HTML <hr> Tag β Horizontal Rule (Separator)
π Introduction
The <hr> tag is used to create a horizontal line in HTML.
It is used to visually separate content sections on a webpage.
Like <br>, it is a self-closing tag (no closing tag needed).
π§± Syntax
<hr />
or:
<hr />
π‘ Example
<!DOCTYPE html>
<html>
<head>
<title>HR Example</title>
</head>
<body>
<h1>Welcome</h1>
<p>This is the first section.</p>
<hr />
<p>This is the second section.</p>
</body>
</html>
π₯οΈ Output Explanation
The page will show:
- First section
- A horizontal line
- Second section
β The <hr> visually separates content
π― When to Use <hr>
Use <hr> to:
- Separate topics or sections
- Divide blog posts
- Break content into logical parts
- Improve readability
Example:
<h2>Introduction</h2>
<p>Welcome to my blog.</p>
<hr />
<h2>Conclusion</h2>
<p>Thanks for reading.</p>
β οΈ Important Note
π <hr> is NOT just a visual line
It actually represents a thematic break in content (semantic meaning).
π¨ Styling <hr> with CSS
You can customize it:
<hr style="border: 1px solid black; width: 50%;" />
β You can change:
- Color
- Thickness
- Width
π« Common Mistakes
- Using
<hr>for decoration only β - Overusing it everywhere β
- Thinking it adds spacing (it doesnβt, itβs a separator) β
π§ͺ Mini Exercise
Create a page with:
- A title section
- A horizontal line
- A content section
- Another horizontal line
- A footer section
π Try to organize it like a real article