HTML Horizontal Rule
Think about reading a story. Suddenly the writer leaves a small gap, maybe adds a line or a few stars, and starts again in a new place or at a new time. You feel the change right away. Nobody had to explain it.
HTML has a tool for exactly this moment: the horizontal rule, written as <hr />. It draws a line across the page, but its real job is not decoration. It tells the reader, "The topic is changing here."
What You Will Learnβ
- What the
<hr />tag is and what it means - When a horizontal rule is the right choice
- How to style it with CSS, since old HTML attributes are outdated
- How screen readers treat it
- Common mistakes, and better alternatives
The Basicsβ
The <hr /> tag creates a thematic break between two blocks of content. It is a void element, which means it has no content inside and no closing tag. (You met void elements in the Line Breaks lesson.)
- HTML Code
- Browser Output
<h2>Morning Routine</h2>
<p>I start my day with a glass of water and a short walk.</p>
<hr />
<h2>Evening Routine</h2>
<p>I finish my day by reading for twenty minutes.</p>
Morning Routine
I start my day with a glass of water and a short walk.
Evening Routine
I finish my day by reading for twenty minutes.
The browser draws a thin line across the full width of its container, with a little space above and below. It is a block-level element, so it always sits on its own row.
In plain HTML, both <hr> and <hr /> work. In MDX and JSX, use <hr />, because unclosed tags cause errors there.
What Does "Thematic Break" Mean?β
In older HTML, <hr> meant "horizontal rule", so people thought of it only as a line. In modern HTML, the meaning is a shift in theme at the paragraph level.
Here is the difference in simple terms.
| Old idea | Modern idea |
|---|---|
| "Draw a line here." | "The subject changes here." |
| About appearance | About meaning |
| Visual decoration | Content structure |
That is why the line you see is only the default look. The meaning stays even if you restyle it.
When to Use <hr />β
Use it when there is a real change of topic inside a section, but the change is too small for a new heading.
- A scene change in a story
- A shift in subject between two paragraphs
- A separator between a main article and its notes or sign-off
- A pause between a question and its long answer
- HTML Code
- Browser Output
<p>Amara closed her laptop and looked out of the window. The rain had stopped.</p>
<hr />
<p>Three weeks later, her first app was live in more than thirty countries.</p>
Amara closed her laptop and looked out of the window. The rain had stopped.
Three weeks later, her first app was live in more than thirty countries.
A quick test: if you removed the line, would the change of topic still be clear? If yes, you probably do not need <hr />. If a reader might get confused, it helps.
Old Attributes Are Gone: Use CSSβ
Old tutorials show attributes like width, size, align, and noshade on <hr>. These are deprecated. They still work in some browsers, but you should not use them. CSS gives you full control instead.
| Old attribute | Modern CSS |
|---|---|
width="50%" | width: 50%; |
size="5" | border-width or height |
align="center" | margin-inline: auto; |
noshade | border-style and background |
A Clean Custom Lineβ
- HTML + CSS
- Browser Output
<style>
.soft-line {
width: 60%;
margin: 2rem auto;
border: none;
border-top: 3px solid #2563eb;
border-radius: 2px;
}
</style>
<p>First topic.</p>
<hr class="soft-line" />
<p>Second topic.</p>
First topic.
Second topic.
A Few More Stylesβ
- Dashed
- Fading
- Dotted
hr.dashed {
border: none;
border-top: 2px dashed #64748b;
}
hr.fade {
height: 2px;
border: none;
background: linear-gradient(to right, transparent, #2563eb, transparent);
}
hr.dotted {
border: none;
border-top: 4px dotted #94a3b8;
width: 30%;
margin-inline: auto;
}
Browsers add their own border style and margin to <hr>. Setting border: none first, then adding the style you want, gives you a predictable result in every browser.
Accessibility and Global Readersβ
Not everyone sees the page in the same way, so it helps to know what happens behind the scenes.
- Screen readers usually announce
<hr />as a separator. Some readers skip it, and others say the word. This is why you should use it only when the break is meaningful. - Decorative lines made with CSS borders are ignored by assistive tools. That is good when the line is only for looks.
- Contrast matters. A very light gray line on a white background may be invisible for low-vision users. Choose a color that can be seen.
- Right-to-left languages such as Arabic and Hebrew work fine with
<hr />, because it spans the full width of its container. - Do not rely on the line alone. If a new section is important, add a heading, which also helps translation tools and search engines.
Choosing the Right Toolβ
<hr /> is not the only way to separate content. Pick the tool that matches your goal.
| Goal | Best choice |
|---|---|
| Change of topic inside a section | <hr /> |
| A new major section of the page | A heading, like <h2> |
| A purely visual line, such as under a title | CSS border-bottom |
| Space between two blocks | CSS margin or padding |
| Separate items in a list | Use list styling or border on each item |
Common Mistakesβ
Mistake 1: Using <hr /> everywhereβ
<!-- Too many lines -->
<p>Paragraph one.</p>
<hr />
<p>Paragraph two.</p>
<hr />
<p>Paragraph three.</p>
<hr />
When every paragraph gets a line, the break loses its meaning. Save it for real changes of topic.
Mistake 2: Using it only for decorationβ
If you only want a line under a title, a CSS border-bottom is the better tool. It does not say "the topic changed" when nothing changed.
Mistake 3: Using deprecated attributesβ
<!-- Outdated -->
<hr width="50%" size="4" noshade />
<!-- Modern -->
<hr style="width: 50%; border-top: 4px solid #000;" />
Mistake 4: Writing a closing tagβ
</hr> is not valid. Void elements never have a closing tag.
Mistake 5: Using it instead of headingsβ
A line does not tell users what the next section is about. If the next part has its own subject, give it a heading.
Try It Yourselfβ
Here is a small exercise.
- Create a file called
travel-diary.html. - Write two short paragraphs about a place you visited or want to visit.
- Add a third paragraph about a different day or a different place.
- Place an
<hr />between the parts where the story changes. - Add a CSS class that makes your line 40% wide, centered, and dotted.
- Remove the
<hr />and read the text again. Is the change still clear?
Quick Recapβ
Click a question to check your answer.
1. What does <hr /> represent in modern HTML?
A thematic break, meaning a shift in topic between blocks of content.
2. Does <hr /> need a closing tag?
No. It is a void element and has no content to wrap.
3. How should you change the width or color of a horizontal rule today?
Use CSS, such as width, border-top, and margin. The old HTML attributes are deprecated.
4. When is a heading better than <hr />?
When the next part is a new section with its own subject. A heading names that section, and a line does not.
5. Why should you not use <hr /> between every paragraph?
Too many breaks make each one meaningless, and screen readers may announce a separator every time.
Key Takeawaysβ
<hr />marks a change of theme, not just a line on the screen.- It is a void, block-level element with no closing tag.
- Style it with CSS. The old attributes are deprecated.
- Use it sparingly, and prefer headings for new sections and CSS borders for decoration.
- Choose visible colors and think about screen readers so every learner can follow your page.
Next, learn how to show importance and attention in your text with Strong and Bold.