agung laksana
Courses Plus Student 179 Pointswhat is the difference between </br> and \n ?
hi,
what is the difference between </br> and \n ? like this
i get confused with these two, it seems they have similar function. Thanks :)
1 Answer
Steven Parker
243,898 PointsThe tag "<br>" is HTML code that causes a line break on the page. But "\n" is a character escape sequence that represents a newline character.
They would generally be found in different places. In an HTML file, you would see "<br>" but not "\n". But in script code, you would see "\n" used for console messages. You might also see "<br>" but only if the purpose of the script is to create or modify HTML.
agung laksana
Courses Plus Student 179 Pointsagung laksana
Courses Plus Student 179 Pointsthanks Steven, I have edited my question. I am following PHP course and I see </br> and \n like this https://imgur.com/a/Iqg4D
i see both used in the script
Steven Parker
243,898 PointsSteven Parker
243,898 PointsThis script code is generating HTML. The "<br />" code will cause the browser to display the following text on a new line, but the "\n" will actually add a newline into the HTML file. The latter one will not be displayed on the browser page and will only be seen by someone viewing the page source.
Using both keeps the source looking similar to the final page. You'll notice that the
h2element in your example has only the "\n" because header elements take up an entire line by default when the browser displays them.