I’m new to HTML and want to make semantically correct HTML, however I’m finding it hard to work with what seems to be only headings, lists and paragraphs.
Particularly, I can’t find a place that makes sense for subtitles. I’m writing a blog site so lets use that as an example:
A BLOG TITLE
the best blog in the world
post_title1
post_title2
post_title3
Semantically ‘A BLOG TITLE’ is h1. It makes sense to me that the post_titleX are h2, but it doesn’t feel right for the subtitle – ‘the best blog in the world’ to be classed at the same level as them.
The specification has changed quite a bit since the working draft that was up-to-date when this answer was first posted five years ago. As @Andre Figueiredo righly points out in the comments, the published HTML5.2 specification is very clear on this specific use case (emphasis added):
In short, use an appropriately classified
pelement inside aheaderelement:In HTML5, there’s an obvious solution:
When using HTML4 I personally tend to replace the
h2withp class="tagline", or something similar.Edit: To motivate the use of
h2in HTML5, think of the title of Dr. Strangelove:Does a
pelement make sense here? Not really — it’s not a paragraph, it’s a title. Doesh2work as-is? No, we might confuse it with subtitles of the text itself. So what do we do? We useh2and group it withh1using aheaderelement, thereby getting rid of the ambiguity concerning the subtitles in the text.