Sub topic 6
Inline text elements
This chapter assumes you can write a basic HTML document, and that you know what an element, a tag and an attribute are. It also assumes you have used <h1> and <p> to structure text.
What inline elements do
An inline element marks up part of a line of text. It does not start a new line, and it sits inside a block such as a paragraph. A browser draws most inline elements with a default style, such as bold or italic. Choose an element for its meaning, and use CSS when you only want a look.
Emphasis and importance
Two elements carry meaning:
<em>marks stress emphasis, the word you would stress when speaking. Browsers usually show it in italics.<strong>marks strong importance, seriousness or urgency. Browsers usually show it in bold.
Two older elements have a narrower job:
<b>draws attention to text without adding importance, such as a product name in a review.<i>marks text in an alternate voice, such as a technical term or a foreign phrase.
<p>Do <em>not</em> unplug the device. <strong>Warning:</strong> data may be lost.</p>
<p>The word <i lang="fr">bonjour</i> means hello.</p>Screen readers can announce <em> and <strong>, so the meaning reaches people who cannot see the style.
Other common inline elements
| Element | Use |
|---|---|
| `<code>` | A fragment of computer code |
| `<kbd>` | Keyboard input the user types |
| `<abbr title="...">` | An abbreviation, with its expansion in `title` |
| `<mark>` | Text highlighted for relevance, such as a search hit |
| `<small>` | Side comments and fine print |
| `<sub>`, `<sup>` | Subscript and superscript |
| `<q>` | A short inline quotation |
| `<time datetime="...">` | A date or time in a machine-readable form |
| `<span>` | A generic wrapper with no meaning |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Inline elements</title>
</head>
<body>
<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.</p>
<p>Call <code>console.log()</code> to print a value.</p>
<p>The <abbr title="World Wide Web Consortium">W3C</abbr> publishes the standard.</p>
<p>Water is H<sub>2</sub>O. Area is measured in m<sup>2</sup>.</p>
<p>The meeting is on <time datetime="2026-12-07">7 December</time>.</p>
<p>Roses are red,<br>violets are blue.</p>
</body>
</html>The <br> element is a void element that forces a line break. Use it only where the break is part of the content, as in poems or postal addresses.
Using span
Use <span> when you need a hook for CSS or JavaScript and no element fits the meaning. It adds no meaning and no default style.
<p>Status: <span class="status">Online</span></p>Common errors
- Using
<strong>or<em>only to get bold or italic. Style text with CSS instead. - Using several
<br>elements to create vertical space. Use separate paragraphs, and CSS for spacing. - Overlapping tags, such as
<em><strong>text</em></strong>. Close inner elements first:<em><strong>text</strong></em>. - Marking up whole paragraphs with
<strong>. If everything is important, nothing stands out. - Putting a block element such as
<p>or<h2>inside an inline element like<em>. Block and inline nesting rules come in a later chapter.
Exercise
A paragraph contains the sentence "Never share your password." You want the word "Never" spoken with stress, and you want the label "Security note:" at the start to signal importance. Which two elements do you use, and what is wrong with using <b> for the label?
Show answer
Wrap "Never" in <em> and wrap "Security note:" in <strong>, as in <p><strong>Security note:</strong> <em>Never</em> share your password.</p>. The <b> element only draws attention and does not express importance, so assistive technology gets no signal of urgency.