Which HTML tag is used to create a horizontal rule (a thematic break)?

Understanding the HTML <hr> Tag

HTML, or Hypertext Markup Language, is the standard markup language for documents designed to be displayed in a web browser. It uses HTML tags to structure and give meaning to the web content. One such tag is the <hr> tag, which stands for horizontal rule.

The <hr> tag is used to create a thematic break in an HTML document. Typically, it is utilized to set a visible line to divide sections of a web page or to symbolize a contextual transition within the content. A common use case can be between sections of an article or post, where the user wants to clearly distinguish between various topics or subtopics.

When implemented, an <hr> tag typically displays as a horizontal rule or line on the web page. An example of its implementation is as follows:

<p>This is a paragraph before the horizontal line.</p>
<hr>
<p>This is a paragraph after the horizontal line.</p>

Note that the <hr> element is a void element, hence it does not contain any content and does not have a separate closing tag, unlike other HTML elements.

Commonly confused tags with <hr> are <br>, <line>, and <divider>. However, these tags serve different functions. The <br> tag introduces a line break, <line> is not a recognized HTML tag at all, and <divider> is also not part of the official HTML tags. The use of these tags as substitutes for <hr> is incorrect.

As a best practice, while the <hr> tag can be used to visually separate content on a webpage, it should also be used keeping the semantic structure in mind. ‘Thematic break’ suggests a shift in content, much more than just a visible separation, which can help screen readers and other accessibility tools to better understand the flow of the content.

Do you find this helpful?