English العربية Português Japanese

HTML Text Formatting

Formatting tags make text more than just plain words — bold, italic, strikethrough, superscript, quotations. Each format has a corresponding semantic tag that changes both appearance and conveys meaning.

Bold and Italic

<b> makes text bold, and <i> makes text italic. However, HTML5 recommends using the semantic <strong> (indicating important content) and <em> (indicating emphasis), because browsers and search engines can understand their meaning, not just the visual styling.

HTML
<p><b>This is bold</b>, <i>this is italic</i></p>
<p><strong>This is important content</strong> (semantically important, not just styling)</p>
<p><em>This text needs emphasis</em> (read with stress by screen readers)</p>
▶ Try It Yourself
💡 Best Practice: Unless you only want visual bold or italic (e.g., icon fonts), prefer <strong> and <em>. Screen readers treat them specially, making them more accessibility-friendly.

Delete, Insert, and Highlight

<del> displays strikethrough, indicating content has been deleted; <ins> displays underline, indicating newly inserted content. Note that <u> also produces an underline effect, but <ins> carries the semantic meaning of "new addition", while <u> only changes appearance. Additionally, <mark> highlights text like a highlighter pen; <small> represents small-print additional notes, commonly used for disclaimers or copyright information.

HTML
<p>Original price: <del>$199</del> <ins>$129</ins></p>
<p>Don't forget the meeting <mark>tomorrow at 3 PM</mark>.</p>
<p><small>* The organizer reserves the right of final interpretation for this event.</small></p>
▶ Try It Yourself

Additionally, the <pre> tag (preformatted text) preserves spaces and line breaks from the source code, making it perfect for displaying code snippets or simple ASCII art:

HTML
<pre>
+-------------------------+
|    Web-Tutorial.com     |
|   HTML·CSS·JavaScript  |
+-------------------------+
</pre>
▶ Try It Yourself

Subscript and Superscript

<sub> displays text as subscript (lowered), and <sup> displays text as superscript (raised). They are commonly used in chemical formulas, mathematical equations, and footnotes.

HTML
<p>The chemical formula for water is H<sub>2</sub>O</p>
<p>Einstein's mass-energy equation: E=mc<sup>2</sup></p>
<p>Footnote for this article<sup>[1]</sup> is at the bottom of the page.</p>
▶ Try It Yourself

Quotations and Special Text

These tags are specifically used to represent quotations, abbreviations, contact information, and other special content:

HTML
<!-- Block quotation -->
<blockquote>
  Life is like a box of chocolates, you never know what you're gonna get.
  <cite>— Forrest Gump</cite>
</blockquote>

<!-- Inline quotation -->
<p>Confucius said: <q>Learning without thinking leads to confusion; thinking without learning leads to peril.</q></p>

<!-- Abbreviation -->
<p><abbr title="World Wide Web">WWW</abbr> changed the world.</p>

<!-- Contact information -->
<address>
  Author: John Doe<br>
  Email: johndoe@example.com
</address>

<!-- Text direction -->
<p><bdo dir="rtl">This text displays from right to left</bdo></p>
▶ Try It Yourself
📌 Note: <blockquote> is a block-level element, and the browser adds indentation to it; <q> is an inline element, and the browser automatically adds quotation marks. When used with the title attribute, <abbr> shows the full text on mouse hover. <bdo dir="rtl"> makes text flow from right to left, suitable for Arabic and similar scripts.

📖 Summary

📝 Exercises

  1. Format a piece of text: Write a product promotion message including the original price (strikethrough), sale price (underlined insertion), discount note (small text), and a highlighted "Limited Time Offer" marker.
  2. Chemical formulas and superscripts: Use <sub> and <sup> to write CO₂ and x² + y² = z².
  3. Self-check: Open a news website in your browser, right-click "Inspect", and examine which HTML tags are used for quotes, emphasized text, and footnotes in the article. Can you tell which ones use <strong> and which use <b>?
100%