Home 〉 HTML Tutorials 〉 HTML '<hr>' Tag - Horizontal Rule Tag in HTML with Syntax, Attributes & Examples
HTML '<hr>' Tag - Horizontal Rule Tag in HTML with Syntax, Attributes and Examples !
Looking to learn how to use horizontal lines in HTML effectively?
The '<hr>' tag is your go-to solution for visually separating sections of content. In this post, we explored its syntax, block-level and empty nature, available attributes, styling techniques using inline CSS, and practical examples. We also covered how to enhance your SEO with interlinking and relevant external resources. The complete blog post on HTML horizontal rule '<hr>' tag is as follows.
In HTML, the '<hr>' tag is used to create a horizontal line on a webpage, commonly known as a horizontal rule. It is often used to separate content or sections visually. While it doesn't contain any content or text, it plays a vital role in web page structure and layout. Understanding how to use it properly will help you build cleaner, well-structured web pages.
Syntax ✍
<hr>
The '<hr>' tag is:
Although '<hr>' is a simple tag, HTML5 supports a few global attributes to style and manage it.
id' attributes gives a unique identifier to the '<hr>' tag.
<!DOCTYPE html>
<html>
<head>
<style>
#section-divider {
width: 80%;
background-color: #db0b0b;
margin: 30px auto;
border-radius: 4px;
}
</style>
</head>
<body>
<hr id="section-divider">
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Useful for CSS targeting or linking to a specific horizontal rule using anchor tags or scripts.
Applies a CSS class to style the horizontal rule.
<!DOCTYPE html>
<html>
<head>
<style>
.divider-line {
width: 80%;
border: 1px solid #5e19ad;
margin: 30px auto;
border-radius: 4px;
}
</style>
</head>
<body>
<hr class="divider-line">
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Helps in applying common styles across multiple '<hr>' elements using an external or internal CSS class.
Used to apply inline CSS styles directly.
<!DOCTYPE html>
<html>
<body>
<hr style="border: 1px solid #999; margin: 20px 0;">
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Applies direct styling, here it adds a gray border and vertical spacing.
Provides additional information (tooltip) when the user hovers over the horizontal rule.
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Gives a tooltip text for better accessibility and context.
You can style the '<hr>' tag using inline CSS to match your web page design.
<!DOCTYPE html>
<html>
<body>
<hr style="width: 80%; border: 1px solid #333; margin: 30px auto; border-radius: 4px;">
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The HTML '<hr>' tag is a simple yet powerful tool to separate content on a webpage. While it's visually minimal, using it correctly with appropriate styling and attributes helps improve content readability and structure. Whether you're separating sections, breaking up text, or just adding design elements, understanding how to style and use '<hr>' gives you better control over page layout.
It creates a horizontal line, often used to separate sections of content.
It is a block-level element.
Yes, it does not contain any content and is self-closing.
Yes, using inline styles or CSS classes.
'id', 'class', 'style', and 'title'.