<br>
Definition
The HTML br
element is used to insert a line break in a piece of text. It is an empty element, which means that it does not have a closing tag. The br
element is a simple and convenient way to add extra space between lines of text in a webpage, making it easier for users to read the content.
Examples
Here is an example of how the br
element can be used in an HTML document:
<p>This is a paragraph of text.<br>
It contains a line break<br>
inserted using the br element.</p>
In this example, the br
element is used to insert line breaks between the lines of text in the paragraph. This will cause the text to be displayed as follows:
This is a paragraph of text.
It contains a line break
inserted using the br element.
The br
element can also be used to create extra space between elements on a webpage, as shown in this example:
<h1>This is a heading</h1>
<br>
<p>This is a paragraph of text.</p>
This will result with the br
element creating a line break between the heading and the paragraph, giving extra space between the two elements. This will cause the webpage to be displayed as follows:
This is a heading
This is a paragraph of text.
Attributes
Attribute | Description | Deprecated |
---|---|---|
clear | Specifies where the next line should start after the break | Yes |
Best Practices
Here are some best practices for using the HTML br
element:
- Use the
br
element sparingly. Too many line breaks can make your content difficult to read and can also make your webpage look cluttered. - Use the
br
element only to add extra space between lines of text, not to add extra space between words or letters. This is because thebr
element creates a hard line break, which cannot be adjusted using CSS. - Use the
p
element to create paragraphs of text, and use thebr
element only to add line breaks within a paragraph. This is because thep
element automatically adds extra space between paragraphs, so using thebr
element in this context is unnecessary. - Use the
br
element only to create extra space between block-level elements, such as headings and paragraphs. Do not use thebr
element to create extra space between inline elements, such as links or images, as this can cause unexpected behavior and make your content difficult to style. - If you need to add extra space between inline elements, use the
padding
ormargin
CSS properties instead of thebr
element. This allows you to adjust the amount of space and create a more consistent and flexible layout for your content.
Use the br
element only when it is necessary to add extra space between lines of text or other elements on your webpage.
Accessibility Considerations
Screen readers can have difficulty interpretting the space created using the br
element and it is recommended to instead use p
elements with proper CSS margin or padding.
Browser Compatibility
Chrome | Firefox | Safari | Internet Explorer | Microsoft Edge | Opera |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |