Developed By
Gautam Kumar - Full stack developer
DEEP DIVE INTO
The <hr>
element in HTML is used to create a thematic break or horizontal rule, often referred to as a "horizontal line." It is a self-closing element that produces a visible horizontal line or divider on the web page, which is commonly used to separate content or provide visual structure within a document. The <hr>
element does not have any content; it is used solely for creating horizontal lines. Here's how to use the <hr>
element and some examples of its usage:
html<hr>
The <hr>
element does not have specific content attributes. However, you can use some global attributes, such as class and style, to control the styling and appearance of the horizontal line.
html<p>This is some content above the horizontal line.</p>
<hr>
<p>This is some content below the horizontal line.</p>
In this example, the <hr>
element is used to insert a horizontal line between two paragraphs, visually separating the content above and below the line.
Content Separation: The <hr>
element is often used to separate sections of content within a document, creating visual breaks between different topics or sections.
Thematic Breaks: It can be used to indicate a thematic break or transition in content, providing a visual cue to the reader.
Footer Separators: Horizontal lines are commonly used to separate the main content of a web page from the footer, creating a clear distinction between the two.
Email Signatures: In email signatures, a horizontal line is often used to separate contact information from the rest of the email.
Visual Structure: The <hr>
element can be used to provide visual structure to a web page, making it easier to read and navigate.
The appearance of the horizontal line created by the <hr>
element can be customized using CSS. You can control its color, width, height, and other visual properties.
Here's an example of how you might use CSS to style an <hr>
element:
html<hr class="custom-hr">
css.custom-hr {
border: 2px solid #333;
margin: 20px 0;
height: 2px;
background-color: #333;
}
In this example, a class "custom-hr" is added to the <hr>
element, and CSS rules are applied to change its appearance, including border style, margin, height, and background color.
The <hr>
element is a straightforward and effective way to create horizontal lines in HTML, providing visual separation and structure within your web page. It's a useful tool for dividing content into distinct sections and enhancing the readability and organization of your documents.