HTML Line Breaks ( <br> )

In this section of our HTML tutorial, we will focus on the <br> element, which is used to insert line breaks within text content in HTML documents. Understanding how to create line breaks is essential for controlling text formatting and layout.

Understanding Line Breaks

The <br> element is a self-closing tag used to insert line breaks within text content. It is particularly useful when you want to start a new line without creating a new paragraph or a block-level element. Line breaks are commonly used in addresses, poems, or any scenario where manual control over line breaks is necessary.

Classic <br> Syntax

Here is the classic syntax for using line breaks in HTML:

In this example, the <br> element is used to insert a line break, starting the text on a new line.

XHTML-style <br /> Syntax

Alternatively, you can use the XHTML-style syntax:

In later versions of HTML (HTML5 and beyond), both classic and XHTML-style syntaxes for self-closing tags like <br> are accepted. The classic syntax is more commonly used, but the choice between the two is a matter of preference and coding style.

Code Examples

Here are examples of using the <br> element in HTML:

Inserting a Line Break:

Inserting Multiple Line Breaks:

Inserting Line Breaks in Addresses:

Use a line break within a paragraph in HTML:

In this example, a line break <br> is used within a paragraph (<p>) to start a new line while keeping the text within the same paragraph. This is useful when you want to insert a line break without creating a new paragraph or block-level element.

Conclusion

The <br> element is a simple but effective tool for inserting line breaks within text content. It is particularly useful when you need to create manual line breaks in addresses, poems, or other scenarios where precise control over text layout is required. As you continue to work on web pages, you’ll discover how line breaks, along with other HTML and CSS techniques, contribute to the overall design and readability of your content.