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 Header Tag: The Complete Guide with Examples

The header tag defines the top part of a page or a section in HTML. It usually holds a heading…

HTML Blockquote Tag: How to Create Quotes

The HTML blockquote tag defines a long quote from another source. It sets the quoted text apart from other content.…

HTML Boolean Attributes with Examples

HTML Boolean attributes control the behavior of elements and do not need a value. These attributes simplify logic and reduce…

How to Use HTML div Tag – Examples & Group Content

In this article, you will cover how to use div tag in HTML layout. It offers beginner to advanced code…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

HTML wbr Tag: Word Break Opportunities

The <wbr> tag in HTML helps the browser decide where it can break a word. It does not force a…

HTML script Tag: How to Add JavaScript to a Web Page

The script tag adds JavaScript to a web page in HTML. This lets the page run logic or load content.…

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 Global Attributes Overview

HTML global attributes work on most elements. They do not depend on the tag name. You can use them with…

HTML Syntax for Beginners: How it Works with Examples

HTML syntax shows how tags and attributes go together. It gives browsers the rules to read and display a page.…

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.