Cover Image for HTML br Tag
98 views

HTML br Tag

The <br> tag in HTML is a self-closing tag used to insert a line break or line break-like spacing within a block of text. It is an empty tag, which means it doesn’t require a closing tag.

Here’s an example of how the <br> tag is used:

HTML<span role="button" tabindex="0" data-code="<p>This is the first line.<br> This is the second line.

<p>This is the first line.<br>
This is the second line.</p>

In the example above, the <br> tag is placed within the <p> (paragraph) tags. It creates a line break, causing the text “This is the second line.” to appear on a new line below “This is the first line.”

The <br> tag is commonly used in scenarios where you need to introduce a line break within a paragraph or within other inline elements like headings, list items, or table cells. It’s useful for situations where you want to create simple line breaks without the need for additional paragraph or block elements.

It’s important to note that excessive use of <br> tags for formatting purposes is generally discouraged. For more complex layout and spacing requirements, it’s recommended to use CSS properties and classes to achieve the desired effects.

Here’s an example of how you can use CSS to create spacing instead of relying on multiple <br> tags:

HTML<span role="button" tabindex="0" data-code="<p>This is the first line.</p> <p class="spaced">This is the second line.

<p>This is the first line.</p>
<p class="spaced">This is the second line.</p>
CSS
p.spaced {
     margin-top: 1em;
}

In the example above, the CSS class .spaced is applied to the second paragraph (<p>) element, which adds a top margin of 1em, creating a vertical spacing effect.

Remember that the <br> tag should be used judiciously and when appropriate to introduce line breaks within text content. For more complex layout and spacing requirements, CSS is the recommended approach.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS