Introduction
Microsoft Power Apps is a low-code platform that enables developers and business users to build custom business applications with minimal coding. Traditionally, developers create screens, add controls, configure properties, and implement business logic using the visual interface of Power Apps Studio.
However, Microsoft Power Apps also provides a Code View feature that allows developers to view, copy, and paste control definitions using a YAML-based format combined with Power Fx expressions.
Using this feature, developers can create new controls by writing or modifying YAML code instead of manually configuring every control through the visual designer.
For example, developers can define buttons, labels, text inputs, containers, and other supported controls using YAML. They can also configure properties such as Text, Width, Height, Fill, Color, Visible, and OnSelect.
In this article, we will explore how to use YAML code directly in Power Apps Studio, create controls using YAML, implement Power Fx formulas, and reuse code across Canvas Apps.

1. What Is YAML Code in Power Apps?
YAML stands for YAML Ain't Markup Language. It is a human-readable format used to represent structured data.
In Power Apps, Code View provides a YAML-based representation of individual controls and their properties.
With this functionality, developers can:
View the underlying code of Canvas App controls.
Copy existing controls as YAML code.
Modify copied code using Visual Studio Code or another text editor.
Paste YAML code back into Power Apps Studio to create new controls.
Reuse customized controls across multiple screens and applications.
For example, the following YAML defines a button:
- btnSubmit:
Control: Button
Properties:
Text: ="Submit"
Width: =150
Height: =45
This example demonstrates how a button and its properties can be represented using YAML.
Note: Always use the YAML structure generated by Power Apps Studio. The control type and properties can differ depending on whether you use modern or classic controls.
2. Prerequisites
Before implementing YAML code in Power Apps, ensure that you have:
A Microsoft Power Apps account.
An existing Canvas App or a newly created Canvas App.
Access to Power Apps Studio.
Visual Studio Code or another text editor (optional).
Basic knowledge of Power Fx formulas.
3. Create a Canvas App
First, create a Canvas App where you want to implement YAML code.
Follow these steps:
Open https://make.powerapps.com/.
Navigate to the Apps section.
Select New app.
Choose Canvas App.
Select Tablet or Phone layout.
Enter an application name.
Create the application.
Once the application is created, open it in Power Apps Studio.
4. Open Code View in Power Apps Studio
Power Apps provides a Code View option for viewing the underlying YAML code of individual controls.
Follow these steps:
Open your Canvas App in Power Apps Studio.
Navigate to the Tree View on the left side.
Select an existing control, such as a Label or Button.
Right-click the selected control.
Select View code.
A Code View window opens and displays the YAML representation of that control.
You can review the control name, control type, and configured properties.
This is especially useful when you want to understand the correct YAML syntax before creating new controls.
5. Create a Button Using YAML Code
Let's create a simple Submit button using YAML.
First, add a button to your Canvas App manually and open its Code View.
Copy the generated YAML structure and use it as a template.
For example:
- btnSubmit:
Control: Button
Properties:
Text: ="Submit"
X: =100
Y: =100
Width: =150
Height: =45
Fill: =RGBA(23, 78, 166, 1)
Color: =RGBA(255, 255, 255, 1)
Implementation steps
Copy the YAML code.
Modify the button name and required properties.
Copy the modified code.
Return to Power Apps Studio.
Select the target screen or control in Tree View.
Use the Paste code option or press Ctrl + V.
Power Apps validates the code and creates the control if it is valid.
You can now see the newly created button on your Canvas App screen.
Important: The example illustrates the YAML structure. The actual control name and property schema should be taken from Code View in your environment.
6. Create Multiple Controls Using YAML
Now let's create a simple Employee Registration form containing multiple controls.
The screen will include:
Employee Registration heading.
Employee Name label.
Employee Name text input.
Employee Email label.
Employee Email text input.
Department label.
Department text input.
Submit button.
Example YAML implementation
You can first create these controls manually and copy their YAML definitions from Code View. Modify their properties and names using the generated structures.
For example, a label definition can look like this:
- lblEmployeeName:
Control: Label
Properties:
Text: ="Employee Name"
X: =40
Y: =100
Width: =200
Height: =30
A text input definition can look like this:
- txtEmployeeName:
Control: TextInput
Properties:
HintText: ="Enter employee name"
X: =40
Y: =140
Width: =350
Height: =45
A button definition can look like this:
- btnSubmit:
Control: Button
Properties:
Text: ="Submit"
X: =40
Y: =220
Width: =350
Height: =45
OnSelect: =Notify(
"Employee submitted successfully",
NotificationType.Success
)
Repeat this process for the remaining controls, using the exact control schemas generated by Power Apps Studio.
7. Implement Power Fx Formulas with YAML
One of the useful features of Power Apps Code View is that control properties can contain Power Fx expressions.
For example, you can implement validation logic for the Employee Name input field.
If(
IsBlank(txtEmployeeName.Text),
Notify(
"Please enter employee name",
NotificationType.Error
),
Notify(
"Employee submitted successfully",
NotificationType.Success
)
)
You can configure this formula in the button's OnSelect property.
When represented in YAML, the formula appears as a property value:
OnSelect: =If(
IsBlank(txtEmployeeName.Text),
Notify("Please enter employee name", NotificationType.Error),
Notify("Employee submitted successfully", NotificationType.Success)
)
This approach allows developers to combine UI configuration and Power Fx business logic within the control definition.
8. Copy and Reuse Existing Controls
Another advantage of YAML Code View is that developers can reuse existing controls.
For example, suppose you have already created a customized Submit button with:
Background color.
Font size.
Font weight.
Border radius.
Button text.
OnSelect formula.
Instead of creating another button and configuring every property manually, you can:
Select the existing button.
Open Code View.
Copy its YAML definition.
Paste the code into Visual Studio Code.
Modify the control name and required properties.
Copy the updated YAML.
Paste it into another screen.
This helps maintain consistent UI designs across applications.
9. Create and Reuse Screen Layouts
Power Apps Code View also supports copying and pasting screens.
This is particularly useful when developing applications that contain similar screen layouts.
For example, consider an application with the following screens:
Employee Dashboard.
Employee Registration.
Employee Details.
Employee Approval.
If multiple screens use similar headers, navigation menus, and layouts, you can reuse existing screen definitions instead of building everything from scratch.
You can also maintain reusable YAML snippets for frequently used screen structures.
10. Common Properties Used in YAML
The following table describes some commonly used Power Apps control properties.
Property | Description |
|---|
Text | Specifies the text displayed in a control |
Fill | Defines the background color |
Color | Defines the text color |
Width | Sets the control width |
Height | Sets the control height |
X | Specifies horizontal position |
Y | Specifies vertical position |
Visible | Controls visibility |
DisplayMode | Controls edit or view mode |
OnSelect | Executes a Power Fx formula when selected |
Items | Defines the records displayed in a gallery or dropdown |
The available properties depend on the selected control type.
11. Important Considerations and Limitations
Before using YAML in Power Apps, consider the following points:
Use the YAML structure generated by Power Apps Studio.
Control types and property names must be valid.
The YAML code is validated before Power Apps creates a control.
Browser clipboard access must be enabled for copy-and-paste functionality.
Code View is not a general-purpose YAML editor.
The current Code View does not support directly editing the displayed code; make changes in an external editor and paste them back.
Not every application object can be copied and pasted using Code View.
For more information, refer to Microsoft's official documentation.
12. Benefits of Using YAML in Power Apps
Using YAML Code View provides several advantages:
1. Faster UI Development
Developers can reuse existing control definitions rather than configuring every property manually.
2. Reusable Code
Customized controls can be copied and reused across different screens and applications.
3. Better Understanding of Controls
Code View helps developers understand the properties and Power Fx formulas associated with each control.
4. Consistent UI Design
Developers can reuse common layouts, button styles, and other control definitions.
5. Improved Developer Collaboration
YAML snippets can be shared with other developers through Teams, email, or documentation.
6. Easier Screen Development
Developers can copy and paste supported screen structures to accelerate the development process.
Conclusion
YAML Code View in Microsoft Power Apps provides a useful approach for developers who want to build and reuse Canvas App controls using code.
Instead of manually configuring every control through the visual designer, developers can view existing YAML definitions, modify the code using an external editor, and paste it directly into Power Apps Studio.
By combining YAML with Power Fx, developers can configure control properties, implement validation logic, reuse customized UI components, and accelerate Canvas App development.
Whether you are developing a simple registration form or a complex business application, understanding YAML Code View can help you adopt a more developer-friendly approach to Power Apps development.
Join the conversation! Your thoughts help the community grow.