How to Replace New Line with <Br> using Power Automate?

Are you trying to replace newlines in a string with <br> tags using Power Automate? Unfortunately, Power Automate does not allow you to process new line characters using the replace function, which is a non-printable character.

When trying to replace the ‘\n’, which represents a new line, the replace function will consider it as a ‘\n’ string, but it won’t process as a new line.

I will help you with this!

In this tutorial, I will explain how to replace line breaks from a string with <br> tags using Power Automate. Here, I will describe two different ways:

  • By storing New Line in a variable
  • By getting a New Line from the expression

Replace New Line with <br> tags in Power Automate using a Variable

To illustrate this example, I will use a text string that contains newlines. Here, I will use the Email body content that needs to be sent in the email, including newlines. You can see the string placed below.

Hi All,
Just a quick reminder that we have a holiday coming up on [15-08-2025] for Independence Day.
Happy holidays!
Warm regards,
Alex Wilber

Now, I wanted to replace the new lines present in the above string with <br> tags, so that the output can be sent in an email.

Let’s see how to do it by using a new line variable in the flow:

  1. Create an Instant cloud flow in Power Automate by selecting ‘Manually trigger a flow’ trigger action. If you’re a beginner, consider checking out Power Automate’s Instant Cloud Flow.
  2. Now, add an ‘Initialize variable‘ action and provide the below-mentioned parameters.
    • Name: Enter a name for a variable.
    • Type: Choose the data type as ‘String’.
    • Value: Provide your string value. I will set the value as below.
Power Automate replace new line with br
  1. Then, add another Initialize variable that will store the new line in a variable. Set the name, type as a string, and Value as a new line (Press enter once inside the value field).
Replace new line with br Power Automate
  1. Then, add a ‘Compose‘ action to provide the replace expression as mentioned below.
@{replace(variables('VarEmailBody'),variables('VarLinebreak'),'<br>')}
Replace new line with br in Power Automate
  1. After that, add ‘ Send an email(V2)‘ action: Configure To, Subject, and Body parameters. In the Body parameter, insert the outputs of the compose action in the code view.

In the email body, HTML format is present, where the Power Automate will consider <br> tags and break the line of the email body.

Replace New Line with Br from a String Power Automate

At this step, save and manually run the flow. After the flow runs successfully, you can see that the new lines were replaced by the <br> tags.

Have a look at the reference image placed below:

Replace new line in a Power Automate
Replace new line using Power Automate

Replace New Line with <br> Tags using Power Automate Flow Expression

Here, I will explain another approach to replace a new line with < br> tags using an expression in Power Automate.

In the previous example, we have stored a new line in a variable. In this example, we will get the new line from the ‘decodeUriComponent(‘Uri value’) expression.

decodeUriComponent('%0A') - Returns new line character

Let’s recreate the previous example by using decodeUriComponent(‘%0A’) in the replace expression.

I will use the exact string:

Hi All,
Just a quick reminder that we have a holiday coming up on [15-08-2025] for Independence Day.
Happy holidays!
Warm regards,
Alex Wilber

Do follow the steps below:

  1. Create a Power Automate Instant cloud flow, triggered by clicking on a button.
  2. Take an ‘Initialized variable‘ action with the string value that is provided in the code above.
Power Automate replace line break
  1. Then, add a ‘Compose’ action that will provide the replace expression. In the Inputs parameter, insert the expression given in the code.
    • decodeUriComponent(‘%0A’)-> Decodes %0A value that will give the new line character.
replace(variables('VarEmailBody'),decodeUriComponent('%0A'),'<br>')
Power Automate replace line break with br
  1. To see the output, you can add a ‘Send an email(V2)’ action and set the parameters such as To, Subject, and specify the Body in code view with outputs of the compose action.
eplace line breaks from Textinput with br in Power Automate

Save and test the flow.

Output: Replaced New lines with <br>

Replace line breaks from string with br in Power Automate
Replace line breaks from string in Power Automate

That’s how you can replace new lines with <br> tags in a string using Power Automate.

You can use any of the methods mentioned above to replace the new line with <br> tags using Power Automate.

If you have any suggestions for me, please leave your comments in the section below.

Read Other Power Automate Tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…