Semantic vs visual formatting
HTML gives you two ways to format text: semantic and visual. Semantic tags carry meaning (importance, emphasis), while visual tags are purely for appearance.
Why does this matter? Screen readers (used by blind users) read semantic tags differently than visual ones. Search engines also pay attention to semantic tags when ranking content. As a web developer, you should prefer semantic tags whenever possible.
Bold and italic: <b> vs <strong>, <i> vs <em>
These tags look similar but behave differently:
<strong>โ Semantic: marks text as having strong importance. Screen readers emphasize it. Good for warnings or critical info.<b>โ Visual only: renders as bold but carries no semantic weight. Use for keywords, product names, or highlights.<em>โ Semantic: marks text as emphasized. Screen readers pronounce it differently (stressed). Good for emotional emphasis.<i>โ Visual only: renders italic but no emphasis. Use for titles (The Great Gatsby), foreign words (c'est la vie), or citations.
Mark, delete, insert, subscript & superscript
HTML has several other useful formatting tags for highlighting, showing edits, and writing chemistry or math:
<mark>โ Highlights text with a yellow background. Like using a marker pen.<del>โ Shows deleted text with a strikethrough. Good for showing what was removed.<ins>โ Shows inserted text (often underlined). Use with<del>to show edits.<sub>โ Subscript: text that goes below the baseline. Used in formulas (H2O).<sup>โ Superscript: text that goes above the baseline. Used in math (x2) and degrees (25°C).
Try it yourself โ Format a technical article
Edit the code below to practice bold, italic, mark, del, ins, sub, and sup. Click Run to see your changes rendered.
Quotations: <blockquote>, <q>, and <cite>
When you quote someone else's words, use semantic quotation tags. This helps search engines and readers understand that the text isn't your own.
<blockquote>โ A large quote that stands alone. Typically indented by browsers. Include a<cite>tag with the author's name.<q>โ An inline, short quote. Browsers usually add quotation marks automatically (though you can style this with CSS).<cite>โ Marks the source/author. Use inside a<blockquote>or separately to cite a work.
Technical text: <code>, <kbd>, <samp>, and <abbr>
When writing about code, keyboard input, or abbreviations, these tags help convey meaning:
<code>โ Inline code snippets. Styled as monospace with a background.<kbd>โ Keyboard input. Shows what the user should type or press. Often styled to look like a keyboard key.<samp>โ Sample output from a program. Visually distinct from code the user types.<abbr title="...">โ Abbreviations. Thetitleattribute shows the full text on hover. Great for acronyms like SEO or API.
Try it yourself โ Create a quotations showcase
Practice block quotes, inline quotes, citations, and abbreviations. Click Run to see how these elements render.
Common mistakes
- Using
<b>instead of<strong>โ<b>is fine for visual styling, but<strong>is better for important information. Prefer semantic tags. - Using
<i>instead of<em>โ<em>tells screen readers to stress the text. Use<i>only for titles, foreign words, or visual styling. - Forgetting the
titleattribute on<abbr>โ An abbreviation without a title is useless. Always include:<abbr title="Full Text">ABR</abbr>. - Not citing block quotes โ A
<blockquote>without a source looks incomplete. Always add<cite>to show who said it. - Using quotation marks manually โ Use
<q>instead of typing"like this". The browser will add proper quotes and they'll be translatable to different languages.
Task: Create an HTML article about water with proper formatting. Include:
- An
<h1>title: "Water: The Universal Solvent" - A paragraph mentioning H2O using subscript (H
<sub>2</sub>O) - A paragraph with
<mark>around key terms like "polar molecule" or "hydrogen bonds" - Temperatures shown with superscript degrees (25°C using <sup>)
- A
<blockquote>from a famous scientist with<cite> - An abbreviation using
<abbr title="...">for a scientific term like "H2O" or "pH" - An inline quote using
<q>from a real or fictional scientist - Code examples using
<code>if relevant (e.g., chemical formulas)
Hint: Start with your HTML skeleton. Write a paragraph about water's properties. Use subscript for HโO. Mark key terms. Add a famous quote from a scientist (Marie Curie, Einstein, etc.) in a blockquote. Use superscript for temperatures (100°C for boiling point). Add an abbr tag for "H2O" or "dihydrogen oxide".
Key takeaways
- Use semantic tags by default:
<strong>for importance,<em>for emphasis. They're better for accessibility and SEO. <b>and<i>are visual-only. Use them for product names, titles, or foreign words when semantic meaning doesn't apply.<mark>highlights text.<del>shows deletions.<ins>shows insertions.<sub>and<sup>are for chemistry and math.- Always cite quotations with
<blockquote>+<cite>for large quotes, or<q>for inline quotes. <abbr title="...">makes acronyms accessible. Always include a title with the full text.<code>,<kbd>, and<samp>are for technical writing โ they help readers understand what's code vs user input vs output.
Test your knowledge
<b> and <strong>?<abbr> tag do?You just mastered text formatting.
Next: Links and navigation.
Join the Best AI Programs โ three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses โ