Skip to content

Instantly share code, notes, and snippets.

@thomd
Last active March 29, 2024 00:27
Show Gist options
  • Star 96 You must be signed in to star a gist
  • Fork 49 You must be signed in to fork a gist
  • Save thomd/9220049 to your computer and use it in GitHub Desktop.
Save thomd/9220049 to your computer and use it in GitHub Desktop.
Standard HTML5 Semantic Layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
<link href="stylesheets/main.css" rel="stylesheet" />
</head>
<body>
<header>
<hgroup>
<h1>Header</h1>
<h2>Subheader</h2>
</hgroup>
</header>
<nav>
<ul>
<li><a href="#">Menu Option 1</a></li>
<li><a href="#">Menu Option 2</a></li>
</ul>
</nav>
<section>
<article>
<header>
<h1>Article #1</h1>
</header>
<section>
This is the first article.
</section>
</article>
<article>
<header>
<h1>Article #2</h1>
</header>
<section>
This is the second article.
</section>
</article>
</section>
<aside>
<section>
<h1>Links</h1>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
</ul>
</section>
<figure>
<img width="85" height="85"
src="http://domain.tld/path/to/image.jpg"
alt="foobar" />
<figcaption>Foobar</figcaption>
</figure>
</aside>
<footer>Footer</footer>
</body>
</html>

notes

  1. You may omit the <header> and it's decendants if it's only a sole headline and replace it with <h1>.
  2. In this example the navigation <nav> is a page specific navigation, hence after the page header <header>. If the <nav> is a global navigation, it might also be before the first page header <header>.
+-----------------------------------+
| header |
+-----------------------------------+
| nav |
+---------------------+-------------+
| | |
| section | aside |
| | |
| | |
| +-----------------+ | |
| | article | | |
| +-----------------+ | |
| | article | | |
| +-----------------+ | |
+---------------------+-------------+
| footer |
+-----------------------------------+
@ve3
Copy link

ve3 commented Jun 3, 2016

What about <main> element?
http://www.w3schools.com/html/html5_semantic_elements.asp said Specifies the main content of a document
Html5doctor also use <main> element for content area (section in your example).
http://html5doctor.com/the-main-element/

Which one is better for use in main column position?

@yumyo
Copy link

yumyo commented Jul 5, 2016

Sadly, it could not be considered best practice anymore as the HTML 5.1 specification

requires developers to use h1-h6 to convey document structure. The simple reason for this change is that the HTML5 document outline is not implemented and despite efforts to get it implemented, the general response from user agent developers has not been enthusiastic.

References:

Computer says NO to HTML5 document outline
HTML 5.1 specification

@neochrisneo
Copy link

You're going to want to use main for ARIA accessibility reasons

@serdarakkilic
Copy link

BTW
The only section in this example have to have some meaningful content besides the articles inside it. Otherwise articles will not add any value to the web sites content. You have to consider article as an independent content which will never change the meaning of a web page if removed completely.

if your page telling something about an "A subject", having articles about "A Subject" will add a value. However if you remove the articles, your page should still needs to tell about the "A subject". Otherwise the page will not be considered as a page that gives information about "A Subject". It will be considered as a page that lists articles about "A subject".

This is very important that you need to consider articles as independent content.

Also sections inside a page needs to tell about different things. Every section needs to have a heading that defines what it is telling about. do not afraid to use div's for your layouts. all the html5 tags has meanings and you have to use them correctly to receive its rewards.

@zrayev
Copy link

zrayev commented Mar 31, 2018

hgroup - depricated html tag

@TheDefinitionist
Copy link

TheDefinitionist commented Jul 5, 2022

Where is main tag

@alvyynm
Copy link

alvyynm commented Aug 24, 2022

@TheDefinitionist, I was just about to ask the same. According to W3C, "A main landmark identifies the primary content of the page."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment