What is the correct way of using <br>, <br/>, or <br /> in HTML?

Front End TechnologyHTMLWeb Development

There are multiple correct ways to use a br tag in the web documents.

In HTML, a line break is made with the <br> tag. We don't need to close <br> because it's an empty tag. To break a line, either <br/> or <br></br> are acceptable.

However, <br /> tags are used in other web documents like XHTML. But the <br /> tag must possess a space before the trailing /> as it helps XHTML to render the existing HTML user agents.

Syntax

Text <br> text

Following are the examples….

Example: (using <br>)

In the following example we are using <br> tag to allow break in the lines.

<!DOCTYPE html> <html> <body> <p>If you want to break a line <br> in a paragraph, <br> use the BR element in <br> your HTML document.</p> </body> </html>

On executing the above script, the text which is after the tag <br> will get automatically terminated and added to the next line.

Example: (using <br/>)

In the following example we are using <br/> tag to allow break in our lines.

<!DOCTYPE html> <html> <body> <p>If you want to break a line <br/> in a paragraph, <br/> use the BR element in <br/> your HTML document.</p> </body> </html>

When the script gets executed, the text that is after the tag <br/> is terminated and added to the next line.

raja
Updated on 02-Sep-2022 11:05:24

Advertisements