The HTML <hr> element represents a thematic break between paragraph-level sections of content, such as a change of topic or scene. Browsers normally render it as a horizontal line, but that visual line is only the default presentation.
<hr>
Rendered output:
Use CSS when you want to change the rule's width, thickness, color, spacing, or border style.
Demo of HR Tag Show Table of ContentsIn modern HTML, <hr> is not simply a command to draw a line. Use it when the content itself has a thematic transition.
<section>
<h2>Preparing the Data</h2>
<p>Clean and validate the input before processing it.</p>
</section>
<hr>
<section>
<h2>Processing the Data</h2>
<p>Now apply the required transformation.</p>
</section>
If the page merely needs a decorative border or separator with no thematic meaning, CSS on an existing element or a decorative pseudo-element is often more appropriate.
Presentational attributes previously used on <hr> are obsolete. Modern pages should control appearance with CSS.
<style>
hr.custom-rule {
border: 0;
height: 3px;
background-color: #555;
margin: 2rem 0;
}
</style>
<hr class="custom-rule">
Set the width with CSS. Auto margins can center a rule; setting one horizontal margin to 0 can align it to one side.
<style>
hr.short-rule {
width: 50%;
margin-left: auto;
margin-right: auto;
}
</style>
<hr class="short-rule">
A border is a simple way to create dashed or dotted horizontal rules.
<style>
hr.dashed {
border: 0;
border-top: 2px dashed #777;
}
hr.dotted {
border: 0;
border-top: 2px dotted #777;
}
</style>
<hr class="dashed">
<hr class="dotted">
Older HTML pages often used attributes such as width, size, color, align, and noshade directly on <hr>. You may still encounter code such as this while maintaining legacy pages:
<!-- Legacy HTML: do not use for new pages -->
<hr width="50%" size="4" color="red" align="right">
<hr> for the thematic break and use CSS for its presentation. Do not add obsolete presentational attributes to new HTML.Use <hr> when the thematic break is meaningful in the document. Do not rely on the line alone to replace headings or other structure users need for navigation.
<hr> only when a thematic transition also exists.<hr> elements simply to add visual decoration or spacing.<hr>.Attributes such as color, size, width, align, and noshade belong to legacy HTML. Use CSS instead.
If you need vertical space, use CSS margin or padding. The <hr> element has semantic meaning.
A horizontal rule can mark a thematic break, but it does not label the new section. Use proper headings when users need to understand the section hierarchy.
For purely visual vertical separators, CSS borders or pseudo-elements are clearer and avoid adding unnecessary semantic breaks.
It represents a thematic break between sections of paragraph-level content. Browsers commonly display that break as a horizontal line.
No. The hr element is a void element, so it does not have an end tag in HTML.
Use CSS properties such as border, height, background-color, and margin rather than old HTML attributes.
They are obsolete presentational attributes. Use CSS for modern pages.
Use hr when the line represents a thematic break. For decoration without semantic meaning, a CSS border or pseudo-element is usually more appropriate.
Although CSS can change its appearance, a purely decorative vertical divider is usually better created with a CSS border or pseudo-element.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
15-01-2020 | |
| This saved my life! I had to remove a boring footer and used this to bring the page to life. Thanks plus2net! | |