Sub topic 6
Inline text elements
Inline text elements mark up words and phrases inside a block such as a paragraph. They tell the browser, search engines and assistive technology what a piece of text means. This chapter assumes you can already write a document skeleton, headings and paragraphs, and that you know an element has a start tag, content, an end tag and attributes.
What makes an element inline
An inline element sits inside a line of text and does not start a new line. A paragraph is a block, and the elements inside it are inline. Block versus inline layout gets its own chapter later. Here the point is simpler: inline elements wrap a few words and add meaning to them.
Browsers give many inline elements a default look. em is usually italic and strong is usually bold. Treat that look as a side effect. Choose an element for its meaning, and use CSS when you only want a different appearance.
Emphasis and importance
Two elements carry most of the weight in everyday prose.
emmarks stress emphasis, the word you would lean on when speaking. Moving it changes the meaning of the sentence.strongmarks strong importance, seriousness or urgency.
<p>You <em>must</em> save the file before opening it.</p>
<p>You must save the file <em>before</em> opening it.</p>
<p><strong>Warning:</strong> deleting the folder cannot be undone.</p>The first two sentences stress different words, so they say slightly different things. Screen readers may change their voice for these elements. Both elements can be nested to raise the level: <strong>very <strong>important</strong></strong>. Do this rarely.
Bold, italic and other presentational leftovers
Some older elements were kept in HTML but given new meanings.
| Element | Meaning in current HTML | Typical use |
|---|---|---|
| `b` | Text drawn to attention with no added importance | Product names, key words in a summary |
| `i` | Text in an alternate voice or mood | Technical terms, foreign phrases, thoughts |
| `u` | Text with an unarticulated annotation | Marking a misspelling, Chinese proper-name marks |
| `mark` | Text highlighted for reference in another context | A search term inside a result |
| `small` | Side comments and fine print | Copyright lines, legal notes |
b and i are fallbacks. If a more specific element fits, use it. A foreign phrase is better marked with i and a lang attribute than with i alone, and an important warning belongs in strong, not b. Avoid u for decoration. Readers expect underlined text to be a link.
<p>The Latin phrase <i lang="la">carpe diem</i> means "seize the day".</p>
<p>Results for <mark>semantic</mark>: 12 pages found.</p>
<p><small>Prices include tax. Offer ends Friday.</small></p>Note that small is not a way to shrink text. It marks content that is a side comment. Use CSS font-size for size alone.
Choosing between similar elements
When you pick an element, ask what the words are doing in the sentence, not how they should look.
Computer and technical text
A family of elements describes text that is not ordinary prose.
codeis a fragment of computer code.kbdis input the user types or presses.sampis sample output from a program.varis a variable name in a formula or program description.preis a block element that keeps whitespace. It is often combined withcodefor multi-line listings.
<p>Run <code>npm install</code>, then press <kbd>Ctrl</kbd> + <kbd>C</kbd> to stop.</p>
<p>The program prints <samp>Listening on port 3000</samp>.</p>
<p>The area is <var>w</var> × <var>h</var>.</p>
<pre><code>line one
line two, indented</code></pre>The default is a monospace font for all of these, but their meaning is separate from the font. Assistive tools and search indexers can pick out code samples because of the element.
Abbreviations, definitions and quotes
abbr marks an abbreviation. The title attribute can hold the expansion, which browsers show as a tooltip on hover. Touch screens and keyboard users often cannot see tooltips, so write the full form in the text the first time you use the abbreviation.
dfn marks the term being defined at that spot. q is a short inline quotation, and browsers add the quotation marks for you. cite names the title of a creative work, such as a book, article or film. It does not mark a person's name in current HTML.
<p>The <dfn>Document Object Model</dfn> (<abbr title="Document Object Model">DOM</abbr>) is the tree the browser builds from HTML.</p>
<p>As the guide says, <q cite="https://developer.mozilla.org/">HTML is the standard markup language for documents</q>. See <cite>Learning the Web</cite>.</p>The cite attribute on q holds a URL for the source. It is not shown by default. A visible link is the better way to credit a source.
Dates, superscripts and edits
time gives a machine-readable version of a date or time in its datetime attribute. The visible text can be written for people.
<p>The workshop starts on <time datetime="2026-12-04T09:30">4 December at 9:30</time>.</p>
<p>Water is H<sub>2</sub>O. The area is 25 m<sup>2</sup>.</p>
<p>The price is <del>$20</del> <ins>$15</ins> this week.</p>sub and sup set text below and above the baseline. Use them for chemical formulas, footnote marks and exponents, not for layout tricks. del and ins record removed and added content. Both accept datetime and cite attributes.
Line breaks and word breaks
br inserts a line break. It is a void element, so it has no content and no end tag. Use it only where a line break is part of the content, such as in a poem or a postal address. Do not use repeated br elements to create space between paragraphs. Use separate p elements for that, and CSS margins for spacing.
wbr marks a place where the browser may break a long word or URL if it needs to.
<p>
221B Baker Street<br>
London<br>
NW1 6XE
</p>
<p>Visit https://example.com/very<wbr>/long<wbr>/path<wbr>/name</p>The generic inline container: span
span has no meaning of its own. It exists so you can attach a class, id, lang or other attribute to a run of text. Reach for it last, when no element above fits.
<p>The status is <span class="status status-ok">online</span>.</p>
<p>The French word <span lang="fr">bonjour</span> means "hello".</p>Compare span with the block-level div. A span stays in the flow of a line. A div begins on a new line.
Whitespace and nesting rules
HTML collapses runs of spaces, tabs and newlines in text into a single space. Writing five spaces between words, or pressing Enter twice in your editor, does not change what the browser shows. This is why br, p and pre exist.
Inline elements must nest cleanly. The element opened last has to close first.
<!-- Valid -->
<p>This is <strong>very <em>important</em></strong>.</p>
<!-- Invalid: the tags overlap -->
<p>This is <strong>very <em>important</strong></em>.</p>Browsers repair overlapping tags, but the result may differ from what you meant, and a validator will report an error. Inline elements also should not contain block elements. A span containing a p, for example, is invalid. An a element is the exception that allows block content, provided that content is valid where the link sits.
Common errors
- Using
strongoremonly to get bold or italic text. Use CSS for style alone. - Using
boriwhere a more precise element exists. - Stacking
brelements for vertical space. - Using
citefor a person's name, orsmallto shrink text. - Relying on the
titleattribute ofabbras the only place the expansion appears. - Putting
spanaround text whenem,strongorcodewould say what it is. - Overlapping tags such as
<b><i>text</b></i>.
Putting it together
This paragraph uses several elements, each chosen for meaning.
<p>
To restart the <abbr title="Secure Shell">SSH</abbr> service, type
<kbd>sudo systemctl restart ssh</kbd> and wait for
<samp>Done</samp>. <strong>Do not</strong> close the terminal until it
finishes. Updated <time datetime="2026-11-30">30 November 2026</time>.
</p>Exercise
A paragraph reads: "Never share your password. Your password is stored as a hash." You want the first sentence marked as urgent, the word "hash" marked as a term being defined, and "never" visually unaffected beyond that. Which elements would you use, and why is b a poor choice for the first sentence?
Show answer
Wrap the first sentence in strong, because it expresses seriousness and urgency, and wrap "hash" in dfn, because it is the term being defined. b only draws attention without adding importance, so it gives assistive technology no signal that the warning matters. Example: <p><strong>Never share your password.</strong> Your password is stored as a <dfn>hash</dfn>.</p>
Exercise
Find the error and fix it: <p>Press <kbd>Enter<kbd> to send.<br><br><br>Thanks.</p>
Show answer
The first kbd is never closed, because the second tag is <kbd> and should be </kbd>. The three br elements are also being used for spacing, which is a misuse. Fixed: <p>Press <kbd>Enter</kbd> to send.</p><p>Thanks.</p>