If there is one thing I want you to get out of all this, is how to use headings properly.
Headings are the most powerful semantic tag. They allow users to have a very quick map of all they can find on your site. It allows them to navigate quickly and never get lost.
To give you an idea of how powerful they are, let's take a little detour towards screen-reader land.
As this WebAim survey shows, headings are the primary way of navigation for users of screen readers.
Upon entering a website, they will hit keys to reveal a headings map of the website. In this headings map, they can navigate either following the logical order of links or can scope to a specific level and navigate between these.
See how powerful this is?
Headings come in six levels, h1 to h6. As stated on the MDN documentation about headings:
You should not skip heading levels: always start from
<h1>, followed by<h2>and so on.
Most of the time, this is very true and you should follow that rule. That way your users will have a clear outline to help them understand your webpage.
And this is true of more users than just screen readers. Headings on a page are often styled bigger. This makes it so that users can also quickly visually scan the page to have an idea of the content.
But as with any good rule, this one has exceptions.
Let's say you have a webpage with a navigation with a h2 on top and then the h1 title under it. You might be tempted to write your markup so that the title comes first and then use flexbox and order to position everything correctly visually.
But this would mean that screen reader users get the page displayed in a weird order. Their screen reader would read the title and then they would be informed of the nav. Wouldn't it seem weird to you if you came on a website and the nav was positioned after the title?
The better solution is to simply let the navigation with its h2 come first. Screen reader users are used to this pattern, and that way the first thing they have access to when they come on your webpage is the info of where the navigation is.
This example is a great general rule of accessibilty. You should use the tools at your disposition in a way that makes sense rather than follow the semantic rules strictly.
Another thing to watch out for is repetition. When a user arrives on a traditional web page, their screen-reader will first announce the <title> of the page. Then the user can navigate by headings and listens to the h1 text.
This means you should try to make your title content different from the h1 content as to not cause confusion.
This can be as simple as adding the name of your site in the title or you could also have completely different text.
One thing to watch out for is SPA.