HTML Guide
The <br>
tag inserts a line break, and it’s self-closing so you can use either <br>
or <br/>
but </br>
is invalid.
As the <br>
tag is a void element, it doesn’t need a closing tag, so <br>
is preferred to <br/>
.
First line<br>
Second line is also valid but discouraged.<br/>
Third line is invalid</br>
Learn more:
Related W3C validator issues
A <br> element has been found in an invalid place within a <table> element.
For example, the following table has an invalid <br> between two <tr>, but the <br> that appears inside a <td> is valid.
<table>
<tr>
<th>Item</th>
<th>Description</th>
</tr>
<!-- The following br is invalid -->
<br>
<tr>
<td>Book</td>
<td>
<!-- The br in the following line is valid -->
Title: HTML & CSS<br>
Author: John Duckett
</td>
</tr>
</table>
A <br> tag is used in HTML to insert a line break and must be properly placed within elements that can contain phrasing content, such as inside <p> or <div>, but not directly inside elements like <table>, <ul>, or outside the <body>.
A stray <br> tag appears when it is placed in an invalid location according to HTML content model rules, or if it is used outside of any container element.
Correct placement of the <br> tag:
- Place <br> only within phrasing content, such as inside paragraphs or divs.
- Do not place <br> directly inside table structures (<table>, <tr>, <ul>, etc.) or outside <body>.
Valid example:
<p>
First line.<br>
Second line.
</p>
Invalid example (causes stray tag error):
<ul>
<br>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Corrected version without the stray <br>:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Example of improper use outside <body>:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Stray br Tag Example</title>
</head>
<br>
<body>
Content here.
</body>
</html>
Corrected document:
<!DOCTYPE html>
<html lang="en">
<head>
<title>No Stray br Tag</title>
</head>
<body>
Content here.<br>
New line in body.
</body>
</html>
Always ensure that <br> tags are only used where line breaks are permitted and are never placed in forbidden contexts or outside the document body.