YouTip LogoYouTip

Tag Hr

## HTML <hr> Tag Tutorial The HTML `
` (Horizontal Rule) element is a block-level element used to represent a thematic break between paragraph-level elements. While it historically rendered simply as a horizontal line, modern HTML5 defines it with semantic meaning, representing a shift of topic or a transition within a section. --- ## Syntax and Usage In HTML, the `
` tag is an **empty element** (or self-closing tag), meaning it does not have a closing tag. * **HTML:** `
` * **XHTML/XML:** `
` (Self-closing is required in XHTML) ### Semantic Meaning * **In HTML5:** It represents a thematic break (e.g., a change of scene in a story, a transition to another topic within a section). * **In HTML 4.01:** It was used purely as a presentational element to draw a horizontal rule. --- ## Code Examples ### Basic Example Use the `
` tag to separate content when the topic changes: ```html

HTML

HTML is the standard markup language for creating Web pages.


CSS

CSS is the language we use to style an HTML document.

``` ### Styling `
` with CSS Since all presentational attributes of `
` are deprecated in HTML5, you should use CSS to customize its appearance (color, height, width, and borders). ```html Custom Styled HR

Section One

This is the first section of our content.


Section Two

This is the second section, separated by a modern gradient divider.


Section Three

This section is separated by a thick, centered blue divider.

``` --- ## Browser Support The `
` tag is universally supported by all major modern and legacy web browsers: * Google Chrome * Microsoft Edge / Internet Explorer * Mozilla Firefox * Safari * Opera --- ## Attributes ### Deprecated Attributes (Not Supported in HTML5) In HTML 4.01, several attributes were used to control the visual layout of the `
` element. **These are obsolete in HTML5.** You must use CSS instead. | Attribute | Value | Description | Modern CSS Alternative | | :--- | :--- | :--- | :--- | | `align` | `left`
`center`
`right` | **Deprecated.** Specifies the alignment of the horizontal rule. | `margin-left`, `margin-right`, or `margin: auto` | | `noshade` | `noshade` | **Deprecated.** Specifies that the horizontal rule should render in a solid color instead of a 3D shaded line. | `border: none; background-color: color;` | | `size` | *pixels* | **Deprecated.** Specifies the height (thickness) of the horizontal rule. | `height: value;` | | `width` | *pixels*
*%* | **Deprecated.** Specifies the width of the horizontal rule. | `width: value;` | ### Global and Event Attributes * The `
` tag supports all **(https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes)** (e.g., `class`, `id`, `style`, `title`). * The `
` tag supports all **(https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#event_handler_attributes)** (e.g., `onclick`, `mouseover`). --- ## Key Considerations 1. **Semantic Separation:** Do not use `
` merely to create visual spacing or margins between elements. Use CSS margin properties (`margin-top` / `margin-bottom`) on your block elements for layout spacing. Only use `
` when there is an actual thematic shift in the content. 2. **Accessibility (ARIA):** By default, browsers map the `
` element to the `separator` role. If you are styling an `
` to be purely decorative and it does not represent a semantic break, consider adding `aria-hidden="true"` to hide it from screen readers.
← Tag ITag Col β†’