<main>: The HTML Main Element
1 Description
The HTML <main>
element is used to contain the primary content for a given HTML document.
The <main>
elemnt should contain content which is directly related to the primary topic of the webpage.
There may be only one <main>
element in each HTML document. The <main>
elemnt should
be a child (either directly or indirectly) of the <body>
element.
For example a webpage which displays a news article about a baseball game should put the writing about the baseball
game in the <main>
element or in child elements of the <main>
element (such as <section>
,
or <p>
elements).
2 Examples
<!DOCTYPE html>
<html>
<head>
<title>Main element example</title>
</head>
<body>
<main>
<h1>The Weather in New York City</h1>
<h2>May 22nd, 2025</h2>
<section>
<h3>Morning</h3>
<p>
The weather in the morning is expected to be cold with some fog that will
last until 9:00am.
</p>
</section>
<section>
<h3>Afternoon</h3>
<p>
The weather in the afternoon is expected to be clear with a high around 68 degrees
Fahrenheit. No clouds are expected. Humidity around 65%.
</p>
</section>
<section>
<h3>Evening/Night</h3>
<p>
Temperatures will fall in the evening, the overnight low is expected to be around
45 degrees Fahrenheit.
</p>
</section>
</main>
</body>
</html>
This document was last updated: