Why is “<br />” showing up in my <p> and not making a new line?

59 views Asked by At

When I add <br /> to a <p> in HTML, it doesn’t make a new line but shows “<br />”.

Here’s any example of what it shows:

Hello <br /> World 

BTW I’m using Handlebars. I have my HTML like this:

<p>{{content}}</p>

I’m expecting it to make a new line instead of put “<br />”

I’ve tried to use <br> but same problem.

2

There are 2 answers

1
Sakib Rahman On BEST ANSWER

Handlebars escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{

<p>{{{content}}}</p>

For more details: https://handlebarsjs.com/guide/#html-escaping

0
Scott Leis On

By default, Handlebars escapes any HTML in the content you provide, so <br /> becomes &lt;br /&gt; in the source, which then renders as <br />.

You can disable the escaping by using triple braces instead of the usual double braces.

See the documentation about this at https://handlebarsjs.com/guide/#html-escaping