/

HTML / CSS / JavaScript Tutorial

HTML Element: <main>

[this page | pdf | back links]

The HTML <main> element indicates the main content of a document. It is new in HTML 5. Content within the element should ideally be unique to the document and hence should not include material such as sidebars, copyright information, logos and search forms.

 

There shouldn’t be more than one <main> element in a document and it shouldn’t be a descendent of an <article>, <aside>, <footer>, <header> or <nav> element.

 

The attributes it can take are HTML global attributes and HTML event attributes.

 

To create or access such an element in JavaScript see here. The corresponding HTML DOM object supports standard DOM properties and methods. The default style applicable to this element is shown here.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML:<br>
<main>Text</main>

<br><br>Created using JavaScript:<br>
<main id="element"></main>

<script>
var x = document.createElement("MAIN");
var txt = document.createTextNode("Text");
x.appendChild(txt);
document.getElementById("element").appendChild(x);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Elements


Desktop view | Switch to Mobile