HTML hr Tag: Horizontal Rules

html hr tag

The <hr> tag in HTML gives you a fast way to split content with a clean horizontal line. You may want to show a shift in topic, break up text, or signal a new section. This tag helps you do that without extra styles or layout work.

Understand the <hr> Tag in HTML

The <hr> tag creates a horizontal rule across the page. It shows a break in the flow of text or content. You do not need to pair it with a close tag.

Here is the syntax:

<hr>

The tag does not need any content. You place it on its own line to create space between parts of your page.

Browsers show the <hr> tag as a thin horizontal line. Most use a solid gray color. It stretches across the page or container. It adds margin before and after the line.

Use <hr> between:

  • Two topics in a long article
  • Main sections in a blog post
  • Quotes and source lines
  • Footer and main content

Do not use it just to decorate or fix spaces. Stick to breaks in meaning.

It signals a shift or break in thought. This helps screen readers and search engines understand the structure of your page. It is more than just a line. It shows intent.

The <hr> vs CSS Borders

You can use both <hr> and CSS to show a horizontal line. But they serve different roles. <hr> adds structure while CSS adds style.

Here is an example:

<section>
  <h2>Chapter 1</h2>
  <p>Intro text.</p>
  <hr>
  <h2>Chapter 2</h2>
  <p>Next topic.</p>
</section>

Here is another example for css border:

<div style="border-top: 1px solid #ccc; margin: 20px 0;"></div>

Key differences:

  • <hr> carries semantic meaning. CSS borders do not.
  • <hr> is easy to write. CSS borders give you more style control.
  • Use <hr> for structure. Use CSS borders for layout or decoration.

HTML5 now marks a shift in topic. This makes it useful for both screen readers and visual layout. It is no longer just a visual break.

How to Style the <hr> Tag with CSS

You can change the look of <hr> with CSS. Some common styles include:

hr {
  border: none;
  border-top: 2px dashed #888;
  margin: 40px 0;
  width: 80%;
  height: 0;
}

This removes the default style and adds a custom dashed line with space around it.

Examples

Dashed Divider Between Topics:

<hr style="border: none; border-top: 2px dashed #999; margin: 30px 0;">

This adds a soft break with a dashed style. Use this between sections of a blog or article to guide the reader’s eye.

Thick Line With Custom Color:

<hr style="border: none; height: 4px; background-color: #0a74da; margin: 20px 0;">

This example uses a bold, colored line. It works well to mark key breaks in content or highlight new parts of a web page.

Centered Line With Limited Width:

<hr style="width: 60%; margin: 40px auto; border: none; border-top: 1px solid #ccc;">

The line stays centered and does not stretch across the whole screen. This creates a subtle divider that keeps the layout neat.

Double Line With Shadow:

<hr style="border: 0; border-top: 3px double #333; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin: 50px 0;">

This advanced style creates depth. It uses double lines and a soft shadow to add visual weight without extra markup.

Wrapping Up

In this article, you learned what the <hr> tag does and how it works in HTML5. You also saw how to style it and when to use or avoid it.

Here is a quick recap:

  • <hr> adds a visual and semantic break
  • It renders as a horizontal rule
  • HTML5 treats it as a topic shift
  • Use CSS to control its style

FAQs

What does the tag do in HTML?

The <hr> tag draws a horizontal line and shows a break in topic or thought. It carries meaning in semantic HTML5.

Can I style with CSS?

Yes. You can style <hr> using CSS with rules like:
hr {  
  border: none;  
  height: 2px;  
  background: #000;  
}

Should I use or a CSS border for layout breaks?

Use <hr> when the break has meaning. Use CSS borders for layout, spacing, or visual decoration only.

How does differ in HTML5?

In HTML5, <hr> is a semantic tag. It marks a shift in content or idea, not just a visual line.

Similar Reads

HTML main Tag: How to Create a Primary Content Area

The <main> tag in HTML marks the central content of a webpage. It tells browsers and assistive technologies where the…

HTML time Tag: Representing Dates and Times

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…

HTML Textarea Tag: How it Works with Examples

The HTML textarea tag gives users space to enter longer messages. This element helps build forms that accept feedback, comments,…

HTML Class Attribute: Use in CSS and JavaScript

The HTML class attribute helps group elements. It helps you update the page style without changing the structure of HTML.…

HTML tabindex Attribute: How it Works with Examples

The HTML tabindex Attribute lets you change the tab order on a web page. It helps control keyboard access. What…

HTML Small Tag: How to Make Text Small

The HTML small tag displays text in a smaller font size than nearby text. It shows less important or side…

HTML address Tag: Contact Information

The address tag in HTML shows contact details. The <address> tag helps show who owns the page or article. Understand…

HTML autocomplete Attribute: How to Use it with form and input

The form autocomplete attribute in HTML helps users fill out forms faster because it shows them saved input for common…

The canvas Tag in HTML: How to Draw Graphics with Examples

The HTML canvas tag draws shapes and images. It also helps you draw text with code. It gives control over…

HTML abbr Tag: How Abbreviations Work with Examples

The abbr tag refers to an abbreviation in HTML. It helps you save space and improve accessibility. The screen readers…

Previous Article

HTML br Tag: Line Breaks

Next Article

HTML audio Tag: How to Embed and Control Sound in Pages

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.