HTML `<hr>` Element: Creating Thematic Breaks for Improved Webpage Structure

Learn how to use the HTML `<hr>` (horizontal rule) element to add thematic breaks to your web pages. This tutorial explains its semantic purpose, demonstrates its usage for separating content sections, and shows how to customize its appearance using CSS for improved readability and visual organization.



Using the HTML `<hr>` Element to Create Thematic Breaks

Understanding Thematic Breaks

The HTML `<hr>` (horizontal rule) element is used to create a thematic break in a webpage. It signifies a shift in topic or section. While visually it’s often rendered as a horizontal line, its primary purpose is to add semantic meaning and structure to the webpage, improving readability and user experience. It is not just about visual appearance; it's about logically separating blocks of content.

Using the `<hr>` Element

The `<hr>` element is an empty element (it has no closing tag). It's typically placed between paragraphs or sections to visually separate content. Here’s a simple example:

Basic `<hr>` Example

<p>This is some text.</p>
<hr>
<p>This is a new section.</p>

Browser Support for `<hr>`

The `<hr>` element is supported by all major modern browsers.

Browser Support
Chrome Yes
Edge Yes
Firefox Yes
Opera Yes
Safari Yes

Customizing `<hr>` Appearance with CSS

You can control the `<hr>` element's appearance using CSS. For example, you can adjust its width, color, thickness, and alignment. Here's an example to illustrate this.

Example: Styling `<hr>` with CSS

hr {
  width: 50%;
  border-color: red;
  border-width: 3px;
  margin: 20px auto; /* Centers the rule */
}

Default `<hr>` Styles

Most browsers will render an `<hr>` with default styles. These default styles might change depending on the browser.

Default `<hr>` Styles (CSS)

hr {
  display: block;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  margin-left: auto;
  margin-right: auto;
  border-style: inset;
  border-width: 1px;
}