Kontakt os

Create a responsive form/app in Power Apps

Learn how to create a responsive app/form in Power Apps


What will we build?

In this blog post we will create a responsive app, focusing on the form component

Finished responsive Power Apps form showing a clean input form displayed on a phone screen

The app/form will be build to fit on any screen size or orientation

The same Power Apps form displayed correctly across multiple screen sizes and orientations including phone portrait, phone landscape, and tablet

Solution

Step 1
Go to make.powerapps.com and create a new blank canvas app (select phone size)

Step 2
Go to settings and turn off Scale to fit. Lock aspect ratio should automatically be turned off as well

Power Apps Studio settings panel showing Scale to fit and Lock aspect ratio both turned off to enable responsive layout

Step 3
In App insert following code

MinScreenWidth =
Max(App.Width, If(App.Width < App.Height, App.DesignWidth, App.DesignHeight)) MinScreenHeight =
Max(App.Height, If(App.Width < App.Height, App.DesignHeight, App.DesignWidth))

Power Apps App properties showing MinScreenWidth and MinScreenHeight set to dynamic expressions based on App.Width and App.Height

Rename Screen1 to startScreen and change the following properties for your screen

Width =
Max(App.Width, If(App.Width < App.Height, App.DesignWidth, App.DesignHeight)) Height =
Max(App.Height, If(App.Width < App.Height, App.DesignHeight, App.DesignWidth))
Fill =
RGBA(76, 88, 58, 0.5)


These steps are very important for your app to be responsive, and must be included in all screens


Step 4
In your startScreen insert a vertical container, and change following properties

X = 0
Y = 0
Width = Parent.Width
Height = Parent.Height
LayoutAlignItems = LayoutAlignItems.Stretch
LayoutJustifyContent = LayoutJustifyContent.Center

Step 5
Inside your container insert a new Form, you can use the classic form, or the modern. We will continue with modern

Go to settings -> updates -> new -> modern controls and themes, to turn it on

Power Apps Studio settings panel showing the modern controls and themes toggle enabled under Settings > Updates > New

Use following properties

X = 0
Y = 0
Width = Parent.Width
Height = Parent.Height

Your form should now look something like this

Power Apps canvas showing the modern form placed inside the vertical container filling the full screen width and height

Try to run your app. Not very responsive yet. If you run the form on the mobile, the input fields are also very small.

Select all your datacards (you can select them in the tree view, you just need to hold CTRL and select minimum 3 times with the mouse)

Power Apps tree view showing multiple datacards selected simultaneously by holding CTRL to allow bulk property changes

Change the following property

Width = Parent.Width

Try to run your app again. Now we are getting some better responsiveness

Step 6
Go back to app and select OnStart and insert following code

Set(vSmallDatacardHeight, 150);
Set(vSmallDatacardvalueHeight, vSmallDatacardHeight - 50);
Set(vFontSize, 35);
Set(vTitleHeight, vFontSize * 2);

Right click on App and select Run OnStart (this must be done each time your change any of the properties in OnStart)

Power Apps App OnStart property containing Set variable expressions for vSmallDatacardHeight, vSmallDatacardvalueHeight, vFontSize, and vTitleHeight with the Run OnStart option highlighted

Step 7
Select all your datacards again and change the following property

Height = vSmallDatacardHeight

Step 8
Select your titles and change the following properties (here you can only change one at the time)

Height = vTitleHeight
Size = vFontSize

Step 9
Select your input field and change the following properties (again only one at the time can be changed)

Height = vSmallDatacardvalueHeight
FontSize = vFontSize

Step 10
We need a submit form button

Select your form and click on Field -> Edit fields

Select the 3 dots and click Add a custom card

Power Apps form Fields panel showing the three-dot menu with the Add a custom card option to insert a submit button datacard

Give your new card the following property

Width = Parent.Width
Height = vSmallDatacardHeight + vTitleHeight

Insert a button and give it the following properties (use a classic button)

Fill = RGBA(76, 88, 58, 1)
BorderThickness = 0
Width = Parent.Width - 48
Height = vSmallDatacardvalueHeight
X = 24
Y = DataCardKey1.Y + DataCardKey1.Height + 4 (DataCardKey1 = the name of your DataCardKey)
HoverFill = ColorFade(RGBA(77, 88, 57, 1), -20%)
HoverColor = RGBA(255, 255, 255, 1)
Text = "Submit form"
OnSelect = If(Form1.Valid, Form1.Updates); Notify( "Your form has been submitted", NotificationType.Success, 5000)

Try to run your app in various sizes (and publish it and test it on your phone/tablet)

So far so good, but the width of the inputs are taking the entire screen. It looks OK on a phone, but not so nice on bigger screens. Let’s add some padding

Power Apps form on a wide screen showing input fields stretching the full width without padding, looking unbalanced on larger displays

Step 11
Go back to the OnStart property in App and add the following code

Set(vPaddingSmall, 0);
Set(vPaddingMedium, 0.1);
Set(vPaddingLarge, 0.15);
Set(vPaddingExtraLarge, 0.20);

The numbers represent the percentage of padding we would like (on each site), so you can change them to your liking.

Don’t forget to Run OnStart

Step 12
Select your container and insert following code

PaddingLeft =

Parent.Width *
Switch(
    Parent.Size,
    ScreenSize.Small, vPaddingSmall,
    ScreenSize.Medium, vPaddingMedium,
    ScreenSize.Large, vPaddingLarge,
    ScreenSize.ExtraLarge, vPaddingExtraLarge,
    0
)

PaddingRight =

Self.PaddingLeft

We now have a form that looks good on various screens

Here is the app on an iPhone in portrait mode The responsive Power Apps form running on an iPhone in portrait mode with correctly sized and padded input fields Here is the app on the same phone, but in landscape mode The same responsive Power Apps form on an iPhone in landscape mode adapting its layout and padding to the wider orientation Here is the app on an iPad in portrait mode The responsive Power Apps form running on an iPad in portrait mode with appropriate side padding applied for the larger screen size Here is the app on the same tablet, but in landscape mode The responsive Power Apps form on an iPad in landscape mode demonstrating correct padding and layout adjustment for wide tablet orientation

Download example app
You can download my example app here

You need to add your own data source!

Power Apps canvas showing the example responsive app with sample data fields after importing the downloaded zip file

You can open the app by creating a new blank Canvas App and find the open menu here

Power Apps Studio showing the Open menu location used to import and open a downloaded canvas app zip file

Pinksky bruger cookies for at forbedre funktionaliteten på denne hjemmeside. Du bestemmer selv hvad vi må bruge. Læs mere i vores cookiepolitik.