The HTML br Tag
In HTML, the <br>
tag is used to insert a single line break. It is an empty tag which means that it does not have a closing tag.
Basic Usage
The <br>
tag is most commonly used to insert line breaks in text, such as when creating a new paragraph or separating different elements. Here is an example of how the <br>
tag can be used:
Output:
In the above example, the <br>
tag is used to create a line break between “Hello, how2html.com!” and “Welcome to our website.”
Multiple Line Breaks
You can also use the <br>
tag multiple times to insert more than one line break. For example:
Output:
In this example, there are two <br>
tags used to create two line breaks between “First line” and “Second line.”
Using <br>
with Inline Elements
The <br>
tag can be used with inline elements, such as <span>
, to create line breaks within the inline content. Here is an example:
Output:
In this example, the line break created by the <br>
tag is inserted within the <span>
element.
Positioning <br>
with CSS
You can also control the positioning of line breaks created by the <br>
tag using CSS. For example, you can set the line height of the <br>
tag to create more space between lines. Here is an example:
Output:
In this example, the CSS code sets the line height of the <br>
tag to 3em, creating more space between each line break.
Nesting <br>
in Other Tags
You can also nest the <br>
tag within other tags, such as <div>
or <span>
, to create line breaks within specific elements. Here is an example:
Output:
In this example, the <br>
tag is nested within a <span>
element to create a line break within that specific element.
Using <br>
with <pre>
The <pre>
tag in HTML is used to define preformatted text. When using the <pre>
tag, the <br>
tag can be used to insert line breaks within the preformatted text. Here is an example:
Output:
In this example, the <br>
tag is used within the <pre>
tag to create line breaks within the preformatted text.
Using <br>
in Lists
The <br>
tag can also be used in lists to create line breaks between list items. Here is an example:
Output:
In this example, the <br>
tag is used after each list item to create a line break between items.
Adding Margins with <br>
You can also use the <br>
tag in combination with CSS to add margins between lines of text. Here is an example:
Output:
In this example, the CSS code adds a margin of 10px below each line break created by the <br>
tag.
Using <br>
in Tables
The <br>
tag can be used in table cells to create line breaks within table content. Here is an example:
Output:
In this example, the <br>
tag is used within a table cell to create a line break between “Row 1” and “Row 2.”
Wrapping Text with <br>
You can use the <br>
tag to wrap text within a specific width. For example, if you have a long string, you can insert <br>
tags at specific intervals to break the text into multiple lines. Here is an example:
Output:
In this example, <br>
tags are used to break the long string into multiple lines to fit within a certain width.
Using <br>
with HTML Forms
The <br>
tag can also be used within HTML forms to create line breaks between form elements. Here is an example:
Output:
In this example, <br>
tags are used to create line breaks between form elements, making the form more readable and organized.
Conclusion
In conclusion, the <br>
tag is a simple yet versatile tag that is commonly used to insert line breaks within HTML content. It can be used in a variety of ways to format text, create space between elements, and improve the readability of a webpage. By understanding how to use the <br>
tag effectively, you can enhance the layout and presentation of your HTML documents.