Web Platform Atlas
EN⚡RUUA⚡DE⚡FR⚡ES⚡PL⚡PT⚡ZH⚡JA⚡
Каталог / HTML / The main element

4.4.14 The main element

Статический предпросмотр (RU): для MDN, WPT, глоссария и BYOK-перевода откройте интерактивный Атлас.
⚡ Открыть главу в Атласе

4.4.14 The main element

Категории:

потоковое содержимое.

Palpable content.

Контексты, в которых может использоваться этот элемент:

Where flow content is expected, but only if it is a hierarchically correct main element.

Контентная модель:

потоковое содержимое.

Опущение тегов в text/html:

Ни один из тегов не может быть опущен.

Атрибуты контента:

глобальные атрибуты

Специфика доступности:

Для авторов.

Для разработчиков.

Санитизация:

Default.

DOM-интерфейс:

Uses HTMLElement.

The main element represents the dominant contents of the document.

A document must not have more than one main element that does not have the hidden attribute specified.

A hierarchically correct main element is one whose ancestor elements are limited to html, body, div, form without an accessible name, and autonomous custom elements. Each main element must be a hierarchically correct main element.

In this example, the author has used a presentation where each component of the page is rendered in a box. To wrap the main content of the page (as opposed to the header, the footer, the navigation bar, and a sidebar), the main element is used.

<!DOCTYPE html> <html lang="en"> <title>RPG System 17</title> <style> header, nav, aside, main, footer { margin: 0.5em; border: thin solid; padding: 0.5em; background: #EFF; color: black; box-shadow: 0 0 0.25em #033; } h1, h2, p { margin: 0; } nav, main { float: left; } aside { float: right; } footer { clear: both; } </style> <header> <h1>System Eighteen</h1> </header> <nav> <a href="../16/">← System 17</a> <a href="../18/">RPXIX →</a> </nav> <aside> <p>This system has no HP mechanic, so there's no healing. </aside> <main> <h2>Character creation</h2> <p>Attributes (magic, strength, agility) are purchased at the cost of one point per level.</p> <h2>Rolls</h2> <p>Each encounter, roll the dice for all your skills. If you roll more than the opponent, you win.</p> </main> <footer> <p>Copyright © 2013 </footer> </html>

In the following example, multiple main elements are used and script is used to make navigation work without a server roundtrip and to set the hidden attribute on those that are not current:

<!doctype html> <html lang=en-CA> <meta charset=utf-8> <title> … </title> <link rel=stylesheet href=spa.css> <script src=spa.js async></script> <nav> <a href=/>Home</a> <a href=/about>About</a> <a href=/contact>Contact</a> </nav> <main> <h1>Home</h1> … </main> <main hidden> <h1>About</h1> … </main> <main hidden> <h1>Contact</h1> … </main> <footer>Made with ❤️ by <a href=https://example.com/>Example 👻</a>.</footer>