HTML <main> Element

Publish in HTML Tutorial el 24/05/2025 16:49

The HTML <main> Element

The <main> element represents the dominant content of the <body> of a document. It should contain content that is unique to that document and not repeated across multiple pages (like navigation links, headers, or footers).


Key characteristics of <main>:

  • There should be only one <main> element per page
  • It shouldn't be a descendant of <article>, <aside>, <footer>, <header>, or <nav>
  • It helps with accessibility by identifying the primary content
  • It improves SEO by clearly marking your main content

Basic Syntax

Here's how the <main> element is structured in HTML:


Examples of <main> Usage


Example 1: Basic Main Element

A simple page structure with <main> containing the primary content.

Play Code

Example 2: Main with Articles

<main> can contain <article> elements for blog posts or news items.

Play Code

Example 3: Main with JavaScript Content

Using JavaScript to dynamically update content within the <main> element.

Play Code

Example 4: Main with Form

A contact form placed within the <main> element.

Play Code

Example 5: Main with Tabbed Interface

Using JavaScript to create a tabbed interface within the <main> element.

Play Code

Tips and Tricks

  • Accessibility: The <main> element has an implicit ARIA role of "main", which helps screen readers identify the primary content.
  • SEO: Search engines give more weight to content within the <main> element.
  • Styling: You can target the <main> element in CSS with main { /* styles */ }.
  • Progressive Enhancement: Even if JavaScript fails, your main content will still be accessible.
  • Single Page Apps: In SPAs, the <main> element is often the target for dynamic content updates.

Browser Support

The <main> element is supported in all modern browsers, including:

  • Chrome 26+
  • Firefox 21+
  • Safari 7+
  • Edge 12+
  • Opera 15+

For older browsers, you can add the following CSS to ensure proper display:

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