Question
I am confused about the correct way to write a line break tag in HTML5.
I understand that in HTML 4.01, void elements such as img and br could be written without a closing tag, like this:
<img>
<br>
Then XHTML introduced self-closing syntax such as:
<img />
<br />
I have also read that the space before /> was sometimes used for compatibility with older browsers.
When writing HTML5, which format should be used for a line break element?
<br>
or
<br/>
or
<br />
Short Answer
By the end of this page, you will understand how HTML5 handles void elements like br, why <br> is the standard HTML form, why <br/> and <br /> may still appear in code, and how this differs from XHTML and XML-style syntax.
Concept
In HTML5, br is a void element. A void element is an element that cannot have any content inside it and does not need a closing tag.
That means this is the normal HTML5 form:
<br>
Why this matters
HTML has rules for different kinds of elements:
- Normal elements have an opening and closing tag:
<p>Hello</p> - Void elements do not wrap content and do not use closing tags:
<br> <img src="photo.jpg" alt="Photo"> <input type="text">
In HTML5, the parser already knows that br is void, so it does not need / to mark it as self-closing.
What about <br/> and ?
Mental Model
Think of HTML elements like containers.
-
A normal element like
<p>is a box with a start and end:- open the box:
<p> - put content inside
- close the box:
</p>
- open the box:
-
A void element like
<br>is more like pressing a button than opening a box.- It performs a specific action
- It does not hold content
- There is nothing to close
So writing <br> in HTML is like pressing a “new line” button.
Adding / in <br /> is like writing extra punctuation the browser does not need when reading normal HTML. It may still accept it, but the simpler native form is just <br>.
Syntax and Examples
Core syntax
In HTML5, a line break is written as:
<br>
Example
<p>Hello<br>World</p>
This displays as:
- Hello
- World
on separate lines within the same paragraph.
Other valid forms you may see
<br/>
<br />
Browsers typically accept these in HTML5 documents, but the standard HTML style is:
<br>
More void element examples
These are also void elements in HTML:
<img src="cat.jpg" alt="Cat">
<input =>
Step by Step Execution
Consider this example:
<p>First line<br>Second line</p>
Step-by-step
- The browser reads
<p>and starts a paragraph. - It reads the text
First line. - It reads
<br>. - Because
bris a void element, the browser inserts a line break immediately. - It reads
Second lineon the next line. - It reads
</p>and ends the paragraph.
Result
The paragraph contains two lines:
First lineSecond line
Compare with a normal element
<p><strong>Hello</strong></p>
Here the browser:
Real World Use Cases
Where br is actually useful
Addresses
<p>
Jane Doe<br>
42 River Road<br>
Austin, TX 78701
</p>
Poems or song lyrics
<p>
Roses are red<br>
Violets are blue<br>
HTML has void tags<br>
And now you do too
</p>
Compact labels in UI text
<p>Order confirmed<br>Expected delivery: Monday</p>
Where it should not be used
- Creating page spacing
- Pushing elements down the page
- Replacing proper paragraph structure
- Replacing CSS margins or layout tools
For example, in real apps developers use CSS for spacing:
Profile
Welcome back.
Real Codebase Usage
In real codebases, developers usually follow a consistent markup style based on the document type and formatter.
Common patterns
1. Use plain HTML syntax in HTML5 files
Most teams writing standard .html files use:
<br>
<hr>
<img src="logo.png" alt="Logo">
2. Let formatters enforce consistency
Tools such as formatters or linters may output either:
<br>
or
<br />
depending on the environment or template system. In many codebases, consistency matters more than personal preference.
3. Framework and template differences
Some templating systems, JSX, or XML-based formats may prefer self-closing syntax:
<br />
<img src="/logo.png" = />
Common Mistakes
1. Adding a closing tag to br
Broken code:
<br></br>
Why it is wrong:
bris a void element- Void elements do not have closing tags
Use this instead:
<br>
2. Thinking / is required in HTML5
Beginners often assume this is more correct:
<br />
It is accepted in many cases, but HTML5 does not require it for HTML documents.
The standard HTML form is:
<br>
3. Using br for layout spacing
Broken approach:
<h1>Welcome
Start here
Comparisons
HTML vs XHTML syntax for empty elements
| Context | Preferred syntax | Notes |
|---|---|---|
HTML5 served as text/html | <br> | Standard HTML syntax |
| XHTML served as XML | <br /> | XML requires self-closing form for empty elements |
| JSX | <br /> | JSX syntax requires self-closing tags |
Comparing the three forms
| Form | Works in HTML5? | Standard HTML5 style? | Common in XHTML/XML? |
|---|---|---|---|
<br> |
Cheat Sheet
Quick answer
In HTML5, use:
<br>
Key rule
br is a void element:
- no closing tag
- no inner content
- no need for
/in HTML
Valid forms you may see
<br>
<br/>
<br />
Best choice by context
- HTML5 document:
<br> - XHTML/XML:
<br /> - JSX:
<br />
Other HTML void elements
<area>
<base>
<br>
<col>
<embed>
FAQ
Is <br> valid in HTML5?
Yes. It is the standard HTML5 form for a line break.
Is <br /> wrong in HTML5?
Not usually. Browsers accept it in HTML documents, but it is XML-style syntax rather than the usual HTML5 style.
Should I use <br> or <br />?
If you are writing normal HTML5, use <br>. If you are writing XHTML or JSX, use <br />.
Is <br/> different from <br />?
In most HTML5 browser parsing, both are treated the same. The space is mainly a style difference.
Can I write </br>?
No. br is a void element and must not have a closing tag.
Why do some tools still generate <br />?
Some tools follow XML-style formatting, support multiple markup targets, or use syntax rules like JSX.
Should I use multiple <br> tags for spacing?
Usually no. Use CSS margins or padding for layout and spacing.
What is a void element in HTML?
Mini Project
Description
Build a small contact card page that displays a person's name, address, and support information. This project demonstrates the correct use of the HTML5 br element for meaningful line breaks inside the same block of text, while using CSS—not repeated <br> tags—for layout and spacing.
Goal
Create a valid HTML5 page that uses <br> correctly for line breaks and CSS for spacing between sections.
Requirements
- Create a valid HTML5 document with a heading and two content sections.
- Use
<br>inside an address or contact block where each line belongs to the same piece of content. - Do not use multiple
<br>tags to create vertical space between sections. - Add simple CSS margins or padding for layout spacing.
- Keep the markup semantic and easy to read.
Keep learning
Related questions
Can You Style Half a Character in CSS? Text Effects with CSS and JavaScript
Learn how to style half of a character using CSS and JavaScript, including overlay techniques for dynamic text effects.
Get Screen, Page, and Browser Window Size in JavaScript
Learn how to get screen size, viewport size, page size, and scroll position in JavaScript across major browsers.
Get the Selected Radio Button Value with jQuery
Learn how to find which radio button is selected in jQuery and get its value with simple examples and common mistakes.