HTML <main> tagS2C Home   « HTML <main> tag

Definition

The <main> tag is used to define the Main Content area within a HTML document.

A HTML document should only have one <main> tag.

The <main> tag should not appear within the <article>, <aside>, <footer>, <header> or <nav> elements.

The <main> tag was introduced in HTML5.

Example


<header style="background-color:cyan">
  <h2>Some heading</h2>
  <p>Header content</p>
</header>
<main style="background-color:yellow">
  <h2>Main content heading</h2>
  <p>Main content</p>
</main>
<footer style="background-color:orange">
  <h2>Footer content heading</h2>
  <p>Footer content such as copyright, sitemaps, contact information</p>
</footer>

Some heading

Header content

Main content heading

Main content

Footer Content heading

Footer Content such as copyright, sitemaps, contact information

Attributes

The following attributes can be used with the <main> tag.


<main> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <main> tag.
<main> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<main class="name">Main Content</main>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<main id="name">Main Content</main>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<main style="color:red;">Main Content</main>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<main title="Content info">Main Content</main>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<main accesskey="a">Main Content</main>
tabindexSpecifies a tab order for the element.

<main tabindex="1">Main Content</main>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<main dir="ltr">Main Content</main>
<!-- The text will flow from right to left -->
<main dir="rtl">Main Content</main>
langSpecifies a language code for the content of the element.

<main lang="en">Main Content</main>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<main spellcheck="true">Main Content</main> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<main translate="no">Main Content</main> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<main contenteditable="true">Main Content</main> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<main draggable="true">Main Content</main>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<main hidden>Main Content</main> 
<main hidden="hidden">Main Content</main> 
<main> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<main oncopy="go()">Main Content</main> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<main oncut="go()">Main Content</main>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<main onpaste="go()">Main Content</main>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<main ondrag="go()">Main Content</main>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<main ondragend="go()">Main Content</main>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<main ondragenter="go()">Main Content</main>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<main ondragleave="go()">Main Content</main>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<main ondragover="go()">Main Content</main>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<main ondragstart="go()">Main Content</main>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<main ondrop="go()">Main Content</main>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<main onblur="go()">Main Content</main>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<main onchange="go()">Main Content</main>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<main oncontextmenu="go()">Main Content</main>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<main onfocus="go()">Main Content</main>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<main oninput="go()">Main Content</main>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<main oninvalid="go()">Main Content</main>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<main onreset="go()">Main Content</main>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<main onselect="go()">Main Content</main>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<main onsubmit="go()">Main Content</main>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<main onkeydown="go()">Main Content</main>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<main onkeypress="go()">Main Content</main>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<main onkeyup="go()">Main Content</main>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<main onabort="go()">Main Content</main>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<main oncanplay="go()">Main Content</main>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<main oncanplaythrough="go()">Main Content</main>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<main oncuechange="go()">Main Content</main>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<main ondurationchange="go()">Main Content</main>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<main onemptied="go()">Main Content</main>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<main onended="go()">Main Content</main>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<main onloadeddata="go()">Main Content</main>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<main onloadedmetadata="go()">Main Content</main>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<main onloadstart="go()">Main Content</main>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<main onpause="go()">Main Content</main>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<main onplay="go()">Main Content</main>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<main onplaying="go()">Main Content</main>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<main onprogress="go()">Main Content</main>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<main onratechange="go()">Main Content</main>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<main onseeked="go()">Main Content</main>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<main onseeking="go()">Main Content</main>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<main onstalled="go()">Main Content</main>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<main onsuspend="go()">Main Content</main>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<main ontimeupdate="go()">Main Content</main>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<main onvolumechange="go()">Main Content</main>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<main onwaiting="go()">Main Content</main>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<main onclick="go()">Main Content</main>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<main ondblclick="go()">Main Content</main>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<main onmousedown="go()">Main Content</main>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<main onmousemove="go()">Main Content</main>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<main onmouseout="go()">Main Content</main>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<main onmouseover="go()">Main Content</main>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<main onmouseup="go()">Main Content</main>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<main onwheel="go()">Main Content</main>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<main onscroll="go()">Main Content</main> 
Window - NONE