HTML <h1> to <h6> Element

Publish in HTML Tutorial el 24/05/2025 14:53

HTML heading elements are used to define headings and subheadings on a webpage. They create a hierarchical structure for your content, with <h1> being the most important and <h6> the least important. Search engines use these headings to index the structure and content of your web pages.

Headings should be used semantically to structure content, not just for styling text. Always maintain proper heading hierarchy (h1 → h2 → h3, etc.) for accessibility and SEO benefits.


Basic Syntax

Here's how heading elements are written in HTML:


Examples

Example 1: Basic Heading Structure

A simple document outline with proper heading hierarchy:

Play Code


Example 2: Styled Headings

Headings with inline CSS styling:

Play Code


Example 3: Headings with Anchors

Creating linkable section headings:

Play Code


Example 4: Dynamic Heading with JavaScript

Changing heading content with JavaScript:

Play Code


Example 5: Responsive Headings with JavaScript

Adjusting heading levels based on screen size:

Play Code


Tips and Best Practices

  • Use only one <h1> per page for the main title
  • Maintain proper heading hierarchy (don't skip levels)
  • Headings should be concise and descriptive
  • Use headings to create a document outline, not for styling
  • Consider using ARIA landmarks with headings for better accessibility
  • For SEO, include important keywords in your headings
  • Use CSS for visual styling rather than choosing headings based on appearance

Accessibility Considerations

Screen readers use headings to navigate content. Proper heading structure helps users with disabilities understand your content's organization:

  • Never use headings just for visual effect (use CSS instead)
  • Ensure headings accurately describe the content that follows
  • Don't use empty headings
  • Test your heading structure with accessibility tools

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