HTML <hgroup> Element

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

The <hgroup> element is used to group a set of heading elements (<h1> to <h6>) when you have multiple levels of headings that belong together semantically. This element is particularly useful for creating subtitle relationships without affecting the document outline.


Key Features:

  • Groups multiple heading elements into a single unit
  • Only affects the document outline with the highest-level heading
  • Useful for creating subtitle relationships
  • Helps maintain proper document structure


Basic Syntax


Rendered Example


Main Title

Subtitle


Usage Examples

Example 1: Basic hgroup with two headings

This shows a simple hgroup containing a main title and subtitle.

Play Code


Example 2: hgroup with three heading levels

Demonstrating how hgroup can contain multiple heading levels.

Play Code


Example 3: hgroup with styling

Showing how to style an hgroup element and its contents.

Play Code


Example 4: hgroup with JavaScript (Dynamic Content)

Using JavaScript to dynamically update hgroup content.

Play Code


Example 5: hgroup with JavaScript (Toggle Visibility)

Using JavaScript to toggle the visibility of an hgroup element.

Play Code


Tips and Best Practices

  • Use hgroup when you have multiple heading levels that belong together semantically
  • Only the highest-level heading in the hgroup will contribute to the document outline
  • Don't use hgroup for unrelated headings - it's meant for heading/subtitle relationships
  • Style hgroup elements consistently throughout your site for better UX
  • Combine with ARIA attributes when needed for better accessibility
  • Remember that screen readers will still read all headings within the hgroup


Browser Support

The <hgroup> element is widely supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. However, some older browsers might not recognize it as a semantic element, though they will still render the content.

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 ...