Skip to content

Text Formatting Tags: Mastering the Art of HTML Text Styling ​

What are Text Formatting Tags? ​

Text formatting tags are tags in HTML used to change the appearance of text and emphasize importance. Just as we use bold and italics in document editors to emphasize content, HTML provides a rich set of tags to achieve these effects.

Why Do We Need Text Formatting? ​

Imagine reading a technical document where all text is the same style, without any emphasis or distinction. It would be hard to quickly find key points or understand what content is more important. The roles of text formatting are:

  • Emphasize Important Content: Draw readers' attention to key information.
  • Convey Semantic Meaning: Not just visual effects, but expressing the meaning of content.
  • Improve Readability: Make content easier to understand through visual hierarchy.
  • Enhance Accessibility: Help screen reader users understand the importance of content.
html
<!-- Unformatted text -->
<p>
  Warning: The server will be down for maintenance from 2 PM to 4 PM. All users
  must save their work before 2 PM. Contact [email protected] for questions.
</p>

<!-- Formatted text -->
<p>
  <strong>Warning:</strong> The server will be down for maintenance from
  <mark>2 PM to 4 PM</mark>.
  <em>All users must save their work before 2 PM.</em> Contact
  <code>[email protected]</code> for questions.
</p>

The second example clearly conveys the importance and hierarchy of information through formatting.

Semantic Formatting Tags ​

strong and em: The Correct Way to Emphasize ​

<strong> and <em> are semantic emphasis tags recommended in HTML5.

strong Tag - Strong Importance

html
<!-- strong indicates content is very important -->
<p>
  <strong>Important:</strong> Please read the entire document before proceeding.
</p>

<p>
  The deadline for submission is <strong>December 31, 2025</strong>. Late
  submissions will not be accepted.
</p>

<p>
  <strong>Security Alert:</strong> Your password will expire in 3 days. Please
  update it immediately.
</p>

Meaning of the <strong> tag:

  • Indicates content has strong importance, seriousness, or urgency.
  • Defaults to bold display, but this is just the browser's default style.
  • Can be nested to indicate stronger importance.

em Tag - Emphatic Stress

html
<!-- em indicates emphatic stress -->
<p>I <em>really</em> need to finish this project today.</p>

<p>You should <em>never</em> share your password with others.</p>

<p>This is <em>not</em> the correct approach.</p>

Meaning of the <em> tag:

  • Indicates emphatic stress, changing the focus of the sentence.
  • Defaults to italic display.
  • Can be nested to indicate stronger emphasis.

Difference between strong and em

html
<!-- Comparing usage scenarios -->
<p><strong>Warning:</strong> System maintenance in progress.</p>
<p>This is <em>extremely</em> important to understand.</p>

<p><strong>Do not</strong> enter the restricted area.</p>
<p>You <em>must</em> complete the training before starting.</p>

<!-- Can be combined -->
<p>
  <strong>Critical Update:</strong> The system will <em>permanently</em> delete
  all data in <strong><em>24 hours</em></strong
  >.
</p>

mark Tag - Highlighting ​

The <mark> tag is used to highlight text, typically indicating content relevant to the user's current activity.

html
<!-- Highlighting keywords in search results -->
<p>We found 3 results for "<mark>JavaScript</mark>":</p>
<ul>
  <li>Introduction to <mark>JavaScript</mark> Programming</li>
  <li>Advanced <mark>JavaScript</mark> Concepts</li>
  <li><mark>JavaScript</mark> Best Practices</li>
</ul>

<!-- Marking key points in documentation -->
<p>
  The function accepts three parameters: <mark>name</mark>, <mark>age</mark>,
  and <mark>email</mark>.
</p>

<!-- Marking key parts in a quote -->
<blockquote>
  <p>
    The future of web development lies in
    <mark>component-based architecture</mark> and
    <mark>progressive web applications</mark>.
  </p>
</blockquote>

These tags are used to mark text content related to computers.

code Tag - Code Snippets

html
<!-- Inline code -->
<p>Use the <code>console.log()</code> function to debug your code.</p>

<p>
  The <code>Array.map()</code> method creates a new array with the results of
  calling a function.
</p>

<p>To install the package, run <code>npm install react</code>.</p>

<!-- Code block (usually combined with pre tag) -->
<pre><code>function greet(name) {
  return `Hello, ${name}!`;
}
console.log(greet("Alice"));</code></pre>

kbd Tag - Keyboard Input

html
<!-- Marking keyboard keys -->
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>

<p>Save your work by pressing <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>

<p>
  To open developer tools, press <kbd>F12</kbd> or <kbd>Ctrl</kbd> +
  <kbd>Shift</kbd> + <kbd>I</kbd>.
</p>

<p>Navigate to the next tab with <kbd>Ctrl</kbd> + <kbd>Tab</kbd>.</p>

samp Tag - Program Output

html
<!-- Marking program output results -->
<p>The command returned: <samp>Error: File not found</samp></p>

<p>Server response: <samp>200 OK</samp></p>

<p>
  After running the script, you should see: <samp>Installation complete!</samp>
</p>

var Tag - Variable Names

html
<!-- Marking variables -->
<p>The value of <var>x</var> is calculated as <var>a</var> + <var>b</var>.</p>

<p>
  In the formula <var>E</var> = <var>mc</var><sup>2</sup>,
  <var>E</var> represents energy.
</p>

Traditional Formatting Tags ​

b and i: Style Tags ​

Although HTML5 recommends using semantic tags, <b> and <i> are still useful in specific scenarios.

b Tag - Visually Attention-Grabbing

html
<!-- Product names -->
<p>The new <b>ProMax 5000</b> features advanced cooling technology.</p>

<!-- Keywords in an article but not emphasizing importance -->
<p>
  The ingredients include <b>flour</b>, <b>sugar</b>, <b>eggs</b>, and
  <b>butter</b>.
</p>

<!-- Contrast: Use b when no semantic importance -->
<p><b>Chapter 1:</b> Introduction to Web Development</p>
<!-- Use strong when there is semantic importance -->
<p><strong>Warning:</strong> Do not proceed without backup.</p>

i Tag - Alternate Voice or Tone

html
<!-- Technical terms -->
<p>The <i>Document Object Model</i> (DOM) is a programming interface.</p>

<!-- Foreign words -->
<p>The restaurant's signature dish is <i>coq au vin</i>.</p>

<!-- Thoughts or internal monologue -->
<p>Sarah thought, <i>This is going to be harder than I expected.</i></p>

<!-- Contrast: Use em for emphatic stress -->
<p>I <em>absolutely</em> need to finish this today.</p>
<!-- Use i for foreign words or terms -->
<p>The term <i>cache</i> comes from the French word for "hiding place".</p>

Special Formatting Tags ​

sub and sup - Subscript and Superscript ​

html
<!-- Subscript: Chemical formulas -->
<p>Water's chemical formula is H<sub>2</sub>O.</p>
<p>Carbon dioxide is represented as CO<sub>2</sub>.</p>
<p>
  The molecular formula for glucose is C<sub>6</sub>H<sub>12</sub>O<sub>6</sub>.
</p>

<!-- Superscript: Mathematical formulas -->
<p>The area of a circle is ΀r<sup>2</sup>.</p>
<p>Einstein's famous equation: E = mc<sup>2</sup></p>
<p>2<sup>10</sup> equals 1024.</p>

<!-- Footnote citations -->
<p>
  According to recent research<sup>1</sup>, web performance significantly
  impacts user engagement<sup>2</sup>.
</p>

small - Fine Print ​

html
<!-- Copyright notice -->
<p>&copy; 2025 TechCorp. <small>All rights reserved.</small></p>

<!-- Disclaimer -->
<p>
  Product availability may vary by region.
  <small>Terms and conditions apply.</small>
</p>

<!-- Additional information -->
<h2>Premium Subscription $99/month</h2>
<p><small>Billed annually at $1,188. Cancel anytime.</small></p>

del and ins - Revision Marking ​

html
<!-- Price change -->
<p>Original price: <del>$199</del> Now: <ins>$149</ins></p>

<!-- Document revision -->
<p>
  The meeting is scheduled for <del>Tuesday</del> <ins>Wednesday</ins> at 3 PM.
</p>

<!-- Revision with timestamp -->
<p>
  Status: <del datetime="2025-11-29">In Progress</del>
  <ins datetime="2025-11-30">Completed</ins>
</p>

<!-- Edit history -->
<p>We offer <del>three</del> <ins>four</ins> different subscription plans.</p>

abbr - Abbreviations and Acronyms ​

html
<!-- Abbreviation with explanation -->
<p>
  The <abbr title="World Wide Web">WWW</abbr> was invented by Tim Berners-Lee.
</p>

<p>
  Use <abbr title="HyperText Markup Language">HTML</abbr> for structure and
  <abbr title="Cascading Style Sheets">CSS</abbr> for styling.
</p>

<p>
  Our <abbr title="Application Programming Interface">API</abbr> supports
  <abbr title="REpresentational State Transfer">REST</abbr> architecture.
</p>

<!-- Technical terms -->
<p>
  <abbr title="Search Engine Optimization">SEO</abbr> is crucial for website
  visibility.
</p>

q and blockquote - Quotations ​

html
<!-- Short quote (inline) -->
<p>
  As Steve Jobs said,
  <q>Design is not just what it looks like, design is how it works.</q>
</p>

<p>
  The documentation states:
  <q>All API calls must include authentication tokens.</q>
</p>

<!-- Block quote -->
<blockquote>
  <p>The best way to predict the future is to invent it.</p>
  <footer>— <cite>Alan Kay</cite></footer>
</blockquote>

<blockquote cite="https://example.com/article">
  <p>
    Modern web development requires understanding of multiple technologies
    including HTML, CSS, JavaScript, and various frameworks.
  </p>
  <p>
    Each technology plays a crucial role in creating robust web applications.
  </p>
</blockquote>

Real-World Application Cases ​

Technical Documentation Example ​

html
<article>
  <h1>Getting Started with React Hooks</h1>

  <section>
    <h2>Introduction</h2>
    <p>
      <strong>React Hooks</strong> are functions that let you use state and
      other React features in <em>functional components</em>.
    </p>

    <p>
      The most commonly used hooks are <code>useState</code> and
      <code>useEffect</code>. Before hooks, you could only use state in
      <i>class components</i>.
    </p>
  </section>

  <section>
    <h2>Basic Usage</h2>
    <p>
      <strong>Important:</strong> Hooks must be called at the
      <mark>top level</mark> of your function component.
    </p>

    <p>To use <code>useState</code>, import it from React:</p>
    <pre><code>import { useState } from 'react';</code></pre>

    <p>
      The syntax is:
      <code
        >const [<var>state</var>, <var>setState</var>] =
        useState(<var>initialValue</var>);</code
      >
    </p>
  </section>

  <section>
    <h2>Common Mistakes</h2>
    <p>
      <strong>Never</strong> call hooks inside loops, conditions, or nested
      functions.
    </p>

    <p><del>Incorrect:</del></p>
    <pre><code>if (condition) {
  useState(0); // ❌ Wrong!
}</code></pre>

    <p><ins>Correct:</ins></p>
    <pre><code>const [count, setCount] = useState(0); // ✅ Right!
if (condition) {
  setCount(1);
}</code></pre>
  </section>
</article>

Product Description Page ​

html
<article>
  <h1>CloudMax Pro Subscription</h1>

  <section>
    <h2>Pricing</h2>
    <p><strong>Special Launch Offer:</strong></p>
    <p><del>$299/month</del> <ins>$199/month</ins></p>
    <p>
      <small>Limited time offer. Price valid until December 31, 2025.</small>
    </p>
  </section>

  <section>
    <h2>Features</h2>
    <ul>
      <li><mark>Unlimited storage</mark> - Store as much as you need</li>
      <li><strong>99.99% uptime</strong> guarantee</li>
      <li><em>Priority</em> customer support</li>
      <li><abbr title="Application Programming Interface">API</abbr> access</li>
    </ul>
  </section>

  <section>
    <h2>System Requirements</h2>
    <p>
      Operating System: Windows<sup>ÂŽ</sup> 10 or later, macOS<sup>ÂŽ</sup> 11+,
      or Linux
    </p>
    <p>Browser: Latest version of Chrome, Firefox, Safari, or Edge</p>
    <p>RAM: <em>Minimum</em> 4GB, <strong>Recommended</strong> 8GB+</p>
  </section>

  <section>
    <h2>Quick Start</h2>
    <ol>
      <li>Install the application: <code>npm install cloudmax-cli</code></li>
      <li>Initialize your project: <code>cloudmax init</code></li>
      <li>Deploy: <code>cloudmax deploy</code></li>
    </ol>
    <p>
      For help, press <kbd>Ctrl</kbd> + <kbd>H</kbd> or type
      <code>cloudmax --help</code>
    </p>
  </section>
</article>

Blog Post Example ​

html
<article>
  <h1>Understanding JavaScript Closures</h1>
  <p><small>Posted on November 30, 2025 by Emily Chen</small></p>

  <section>
    <h2>What Are Closures?</h2>
    <p>
      A <strong>closure</strong> is a function that has access to variables in
      its <em>outer lexical scope</em>, even after the outer function has
      returned.
    </p>

    <p>
      As Douglas Crockford said,
      <q>Closures are one of the most powerful features of JavaScript.</q>
    </p>
  </section>

  <section>
    <h2>Why This Matters</h2>
    <p>Understanding closures is <em>essential</em> for:</p>
    <ul>
      <li><mark>Data privacy</mark> and encapsulation</li>
      <li>Creating <i>factory functions</i></li>
      <li>Event handlers and callbacks</li>
      <li>
        <abbr title="Immediately Invoked Function Expression">IIFE</abbr>
        patterns
      </li>
    </ul>
  </section>

  <section>
    <h2>Example</h2>
    <p>
      Consider this code where <var>counter</var> is preserved through closure:
    </p>
    <pre><code>function createCounter() {
  let count = 0;  // Private variable
  return function() {
    return ++count;
  };
}</code></pre>
    <p>
      The inner function <em>remembers</em> the <var>count</var> variable even
      after <code>createCounter()</code> finishes.
    </p>
  </section>

  <section>
    <h2>Common Pitfall</h2>
    <p><strong>Warning:</strong> Be careful with closures in loops!</p>
    <p><del>This won't work as expected:</del></p>
    <pre><code>for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 100);
}
// Output: 3, 3, 3</code></pre>

    <p><ins>Solution using let:</ins></p>
    <pre><code>for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 100);
}
// Output: 0, 1, 2</code></pre>
  </section>
</article>

Semantic vs. Stylistic: How to Choose? ​

Decision Tree ​

html
<!-- Is the content really important? -->
<strong>Yes → use strong</strong>
<b>No, just visually distinct → use b</b>

<!-- Is it emphatic stress? -->
<em>Yes → use em</em>
<i>No, foreign word/technical term → use i</i>

<!-- Is it code? -->
<code>Yes → use code</code>
<samp>Is it output? → use samp</samp>
<kbd>Is it input? → use kbd</kbd>
<var>Is it a variable? → use var</var>

<!-- Does it need highlighting? -->
<mark>Relevant to current context → use mark</mark>
<span class="highlight">Just decoration → use span with CSS</span>

Best Practices Comparison ​

html
<!-- ❌ Not Recommended: Overusing style tags -->
<p>
  <b
    ><i><u>Important announcement!</u></i></b
  >
</p>

<!-- ✅ Recommended: Using semantic tags -->
<p><strong>Important announcement!</strong></p>

<!-- ❌ Not Recommended: Using formatting tags instead of CSS -->
<p>
  <b><font color="red">Error message</font></b>
</p>

<!-- ✅ Recommended: Using CSS for styling -->
<p class="error-message"><strong>Error message</strong></p>

<!-- ❌ Not Recommended: Confusing semantics -->
<em>Warning:</em> System error

<!-- ✅ Recommended: Correct use of semantics -->
<strong>Warning:</strong> System error

Accessibility Considerations ​

html
<!-- Providing context for screen readers -->
<p>
  Price: <del><span class="sr-only">was </span>$299</del>
  <ins><span class="sr-only">now </span>$199</ins>
</p>

<!-- Abbreviations should provide full explanation -->
<p>
  Contact our <abbr title="Customer Service Team">CST</abbr> for assistance.
</p>

<!-- Quotes should provide source -->
<blockquote cite="https://example.com/source">
  <p>Quote content here.</p>
  <footer>— <cite>Author Name</cite>, <cite>Source Title</cite></footer>
</blockquote>

Common Questions ​

Question 1: What is the difference between strong and b? ​

html
<!-- strong has semantic meaning, indicating importance -->
<p><strong>Critical:</strong> Save your work immediately!</p>

<!-- b is just visual effect, no extra semantics -->
<p><b>Product Name:</b> UltraClean Pro 3000</p>

Question 2: When to use mark? ​

html
<!-- ✅ Search results -->
<p>Found "<mark>React</mark>" in 10 documents</p>

<!-- ✅ Highlighting relevant content -->
<p>The <mark>selected text</mark> will be copied</p>

<!-- ❌ Do not use for general emphasis -->
<p><mark>This is important</mark></p>
<!-- Should use strong -->

Question 3: How to combine multiple tags? ​

html
<!-- ✅ Correct: Consider semantics from inside out -->
<p>
  <strong><em>Extremely important</em></strong> announcement
</p>

<!-- ✅ Correct: Emphasis within code -->
<p>
  Use <code><strong>const</strong></code> instead of <code>var</code>
</p>

<!-- ❌ Excessive nesting -->
<p>
  <strong
    ><em
      ><mark><u>Don't do this</u></mark></em
    ></strong
  >
</p>

Summary of Best Practices ​

  1. Prioritize semantic tags: strong, em instead of b, i.
  2. Choose tags based on content meaning: Use strong for importance, em for emphatic stress.
  3. Use technical tags correctly: code, kbd, samp, var each have their use.
  4. Provide abbreviation explanations: Always add title attribute to abbr.
  5. Consider accessibility: Ensure formatting is meaningful to screen reader users.
  6. Don't over-format: Keep it simple, avoid unnecessary visual clutter.
  7. Use CSS for styling: HTML is for semantics, CSS is for appearance.
  8. Test cross-browser effects: Ensure formatting looks consistent across different browsers.

By correctly using text formatting tags, you can create web content that is both beautiful and semantically sound, improving user experience and accessibility.