The <br>
tag inserts a single line break within text. Unlike the <p>
tag, it doesn’t add extra spacing.
It’s useful for:
- Writing addresses
- Formatting poems
Example:
This is a line of text.
This is a new line.
The <br>
tag is an empty tag; it doesn’t require a closing tag.
While the <br>
tag serves a specific purpose, it’s important to use it judiciously. Overuse can lead to semantic issues and make your HTML less readable. Consider using CSS for more complex layout and spacing requirements.
Here are some things to keep in mind when using the <br>
tag:
- Avoid using it for creating paragraphs: Use the
<p>
tag for defining paragraphs. - Use CSS for spacing: If you need to add extra space between lines or elements, use CSS properties like
margin
andpadding
. - Consider semantic alternatives: For specific formatting needs, explore other HTML elements that might be more appropriate. For instance, the
<pre>
tag is useful for displaying preformatted text, preserving spaces and line breaks.
In modern web development, CSS offers more flexible and maintainable solutions for controlling the layout and appearance of your content. While the <br>
tag remains a valid HTML element, understanding its limitations and exploring alternative approaches will help you create cleaner, more semantic, and more visually appealing websites.
For example, consider this address:
123 Main StreetAnytown, CA 91234
USA
Here, the <br>
tags are perfectly appropriate for separating the different lines of the address.