HTML text-level semantics
Before HTML5, text-level semantic elements were referred to in the specifications as inline elements. Therefore, if you are familiar with that description, be aware that we are talking about the same thing here.
The section of the HTML specification that details text-level semantics can be found here: http://www.w3.org/TR/html5/text-level-semantics.html#text-level-semantics.
Let's take a look at the most common and useful text-level elements.
The <span> element
The span
element is the text-level equivalent of a div
. It is unopinionated and is the perfect element to reach for when you merely want to wrap text in an element for styling purposes.
The <b> element
Historically, visuals were defined in the markup and the <b>
element meant "make this bold" (http://www.w3.org/TR/html4/present/graphics.html#edef-B). However, the specification now describes the <b>
element like this:
The b element represents a span of text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede.
Although no specific meaning is now attached to it, as it's text level, it's not intended to be used to surround large groups of markup. Use a div
for that.
You should also be aware that because it was historically used to bold text, you'll typically have to reset the font-weight
in CSS if you want content within a <b>
tag to not appear bold.
For example:
b {
font-weight: normal;
}
The <strong> element
If you do want to emphasize something for strength, urgency, or importance, <strong>
is the element for you. Here is how the specification defines these use cases:
Importance: The strong element can be used in a heading, caption, or paragraph to distinguish the part that really matters from other parts that might be more detailed, more jovial, or merely boilerplate.
Seriousness: The strong element can be used to mark up a warning or caution notice.
Urgency: The strong element can be used to denote contents that the user needs to see sooner than other parts of the document."
You can read the full specification for <strong>
here:
https://www.w3.org/TR/html52/textlevel-semantics.html#the-strong-element
The <em> element
I'll admit, in the past, I've often used <em>
merely as a styling hook to provide italic text when I wanted it. I need to mend my ways as the HTML specification tells us:
The em element represents stress emphasis of its contents.
Therefore, unless you actually want the enclosed contents to be emphasized, consider using a <b>
tag or, where relevant, an <i>
or span
tag instead.
The <i> element
The HTML5 specification describes the <i>
as:
A span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text.
Suffice it to say, it's not to be used to merely italicize something. For example, we could use it to mark up the odd name in this line of text:
<p>However, discussion on the hgroup element is now frustraneous as it's now gone the way of the <i>Raphus cucullatus</i>.</p>
Or, perhaps if you were marking up a button in a food ordering web application, you might do this:
<button type="button">
French Fries <i>No Salt Added</i>
</button>
There are plenty of other text-level semantic tags in HTML; for the full rundown, take a look at the relevant section of the specification at the following URL: http://www.w3.org/TR/html5/text-level-semantics.html#text-level-semantics.