Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic structure in HTML - Subtitles (Pre-HTML5)

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.

like image 852
Jono Avatar asked Oct 11 '10 22:10

Jono


People also ask

What is the semantic of HTML5 structure?

One of the most important features of HTML5 is its semantics. Semantic HTML refers to syntax that makes the HTML more comprehensible by better defining the different sections and layout of web pages. It makes web pages more informative and adaptable, allowing browsers and search engines to better interpret content.

What is semantic structure in HTML?

Semantic HTML elements are those that clearly describe their meaning in a human- and machine-readable way. Elements such as <header> , <footer> and <article> are all considered semantic because they accurately describe the purpose of the element and the type of content that is inside them.

What is the new sematic elements in HTML5?

HTML5 provides new semantic elements that allow authors to specifically define aspects of web documents, including <header> , <footer> , <section> , <article> , <figure> and <figcaption> . More importantly, authors can use these elements in an infinite variety of ways, allowing extensive flexibility.

What is semantic HTML explain with example?

Semantic HTML or semantic markup is HTML that introduces meaning to the web page rather than just presentation. For example, a <p> tag indicates that the enclosed text is a paragraph. This is both semantic and presentational because people know what paragraphs are, and browsers know how to display them.


2 Answers

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):

h1h6 elements must not be used to markup subheadings, subtitles, alternative titles and taglines unless intended to be the heading for a new section or subsection.

In short, use an appropriately classified p element inside a header element:

<header>
    <h1>A BLOG TITLE</h1>
    <p class="tagline">the best blog in the world</p>
</header>

In HTML5, there's an obvious solution:
<header>
    <h1>A BLOG TITLE</h1>
    <h2>the best blog in the world</h2>
</header>

When using HTML4 I personally tend to replace the h2 with p class="tagline", or something similar.

Edit: To motivate the use of h2 in HTML5, think of the title of Dr. Strangelove:

<h1>Dr. Strangelove</h1>
<?>Or: How I Learned to Stop Worrying and Love the Bomb</?>

Does a p element make sense here? Not really — it's not a paragraph, it's a title. Does h2 work as-is? No, we might confuse it with subtitles of the text itself. So what do we do? We use h2 and group it with h1 using a header element, thereby getting rid of the ambiguity concerning the subtitles in the text.

like image 120
You Avatar answered Oct 22 '22 09:10

You


I would just use a paragraph element, it doesn't feel as odd to me as using a heading element:

<p class="subtitle">the best blog in the world</p>

You's answer ("your answer", "his answer"?) would certainly be the way to go if you're marking up using HTML5.

like image 30
BoltClock Avatar answered Oct 22 '22 09:10

BoltClock