Text Formatting
Inside paragraphs you often need to mark individual words: something important, a technical term, a quotation, a keyboard shortcut. HTML has a set of small inline text elements for this. Each has a specific meaning, and choosing the right one helps screen readers, search engines and anyone who later styles your page.
Importance and emphasis
<p><strong>Warning:</strong> never share your M-Pesa PIN.</p> <p>I said the meeting is on <em>Friday</em>, not Thursday.</p>
<strong>means strong importance, seriousness or urgency. Browsers show it in bold.<em>means stress emphasis, the word you would say louder or differently when speaking. It changes the meaning of the sentence. Browsers show it in italics.
You can nest them: <strong><em>…</em></strong> is both important and stressed.
What about b and i?
<b> and <i> also make bold and italic text, and they are valid modern HTML, but with different meanings. <b> draws attention to text without extra importance (for example, keywords in a summary or product names). <i> marks text in a different voice or mood, such as a word from another language, a technical term or a ship's name: <i lang="sw">harambee</i>.
Ask yourself: "Is this word more important?" If yes, use <strong>. "Would I stress it when speaking?" Use <em>. If you only want a visual style with no special meaning, use CSS instead.
Other useful inline elements
| Element | Meaning | Default look |
|---|---|---|
<mark> | Highlighted because it is relevant, like a search match | Yellow background |
<small> | Side comments and fine print, such as copyright | Smaller text |
<del> / <ins> | Text removed from / added to the document | Struck through / underlined |
<s> | No longer accurate or relevant, such as an old price | Struck through |
<sub> / <sup> | Subscript / superscript | Lowered / raised small text |
<abbr> | An abbreviation; add its expansion in title | Sometimes dotted underline |
<time> | A date or time; datetime gives a machine-readable form | Normal text |
<p>Water is H<sub>2</sub>O and the area is 25 m<sup>2</sup>.</p> <p>Price: <s>KES 2,500</s> KES 1,800 this week only.</p> <p>The <abbr title="Kenya Certificate of Secondary Education">KCSE</abbr> results are out.</p> <p>The hackathon starts on <time datetime="2026-12-05">5 December</time>.</p>
The datetime value uses the international format year-month-day, so programs such as calendars and search engines can read the date reliably, while humans read the friendly version.
Quotations
For a short quotation inside a sentence, use <q>. The browser adds the quotation marks itself, so don't type them.
For a longer quotation that stands as its own block, use <blockquote>. Browsers indent it. The optional cite attribute holds the URL of the source (it isn't displayed), and the <cite> element marks the title of a work such as a book, film or song.
<p>Our coach always says <q>practice beats talent</q>.</p> <blockquote cite="https://www.example.com/interview"> <p>Start small, finish what you start, then build something bigger.</p> </blockquote> <p>From the interview series <cite>Young Builders of Kampala</cite>.</p>
Computer text
When you write about technology, these elements make your meaning precise:
<code>: a fragment of computer code, shown in a monospace font.<kbd>: keys the user should press, for example<kbd>Ctrl</kbd> + <kbd>S</kbd>.<samp>: sample output from a program.<var>: a variable in maths or programming.
For a whole block of code, combine <pre> (to keep spacing) with <code> inside it. Remember that any < or & in the code you are displaying must be written as an entity; see Comments, Entities & Symbols.
Try it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Text formatting</title>
</head>
<body>
<h1>Study tips</h1>
<p><strong>Important:</strong> revise a little <em>every</em> day.</p>
<p>Search results for "chemistry": balancing <mark>chemistry</mark> equations.</p>
<p>Carbon dioxide is CO<sub>2</sub>; 2<sup>10</sup> is 1024.</p>
<p>Save your notes with <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>
<p>Revision book: <s>KES 900</s> KES 650.</p>
<p>My teacher says <q>understanding beats memorising</q>.</p>
<p><small>Tips compiled by the Form Four prefects.</small></p>
</body>
</html>
In the preview, "Important:" is bold, "every" is italic, the second "chemistry" has a yellow highlight, the 2 in CO₂ sits low and the 10 sits high, the old price is crossed out, the quotation gets curly quotation marks automatically and the final line is smaller.
Using <u> to underline words for decoration. On the web, underlined text looks like a link, so readers try to click it. Avoid underlining anything that isn't a link.
Key points
<strong>= importance,<em>= stress;<b>and<i>are for styling-type distinctions without extra importance.<mark>,<small>,<s>,<sub>,<sup>,<abbr>and<time>each carry a specific meaning.<q>is for inline quotes (quotation marks added for you);<blockquote>is for long ones.- Use
<code>,<kbd>and<samp>for computer text; use CSS for pure appearance.
Tip: use the ← and → keys to move between pages.
