HTML <hr> Element

Publish in HTML Tutorial el 24/05/2025 15:21

The <hr> element, which stands for "horizontal rule", is used to create a thematic break or divider between sections of content. Originally designed as a simple horizontal line, modern HTML5 redefines it as a semantic element representing a paragraph-level thematic break.

While visually it typically appears as a horizontal line by default, its primary purpose is semantic - to indicate a change of topic or scene within a document. The appearance can be customized with CSS.


Basic Syntax

Here's how the basic <hr> tag looks in HTML:

And here's how it renders:

Play Code


Examples of <hr> Usage

1. Basic Thematic Break

A simple divider between two sections of an article:

Play Code


2. Styled HR with CSS

Customizing the appearance of the horizontal rule:

Play Code


3. HR with JavaScript Interaction

Making the HR element interactive with JavaScript:

Play Code


4. Vertical Rule Alternative

Using CSS to create a vertical divider (not a true HR element, but a common alternative):

Play Code


5. Animated HR with JavaScript

Creating an animated divider that changes over time:

Play Code


Tips and Tricks

  • Semantic Use: Always use <hr> for thematic breaks, not just for visual separation.
  • Styling: Modern browsers typically display HR as a border rather than using the color property. Use background-color and height for better control.
  • Accessibility: Screen readers often announce HR elements, so use them judiciously to avoid confusing users.
  • Responsive Design: Consider adjusting HR margins and size for different screen sizes.
  • Creative Alternatives: While HR is horizontal by nature, you can create vertical dividers with CSS transforms or border properties.


Browser Support

The <hr> element is supported by all browsers, including legacy ones. However, the default styling may vary slightly between browsers, so for consistent appearance, always specify your own styles.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...