Skip to main content

HTML Text and Links

HTML Text Formatting

Written by Updated HTML Text Formatting exercises

HTML has a small set of tags for formatting text inside a sentence: bold, italic, highlighted, smaller, crossed out, raised or lowered. Some only change the look; the better ones also say why the text is different.

The most useful thing to learn here is that pairing. <b> and <strong> both look bold, <i> and <em> both look italic, but <strong> and <em> carry meaning that screen readers and search engines can use.

Text Formatting Example

html

<p>This is <b>bold</b> and <i>italic</i> text.</p>

The words appear in bold and in italics inside the sentence.

Commonly Used Text Formatting Tags

TagDescriptionExample
<b>Makes text bold (visual only)Bold text
<strong>Emphasizes important text (semantic)Important!
<i>Italic text (visual only)Italic text
<em>Emphasized text (semantic meaning)Emphasized text
<u>Underlined textUnderlined
<mark>Highlights textHighlighted text
<small>Makes text smallerFine print
<del>Shows deleted textOld price
<ins>Shows inserted text<ins>New price</ins>
<sub>Subscript textH2O
<sup>Superscript textx2

The examples on the right show what each tag looks like by default. Each one has its own lesson with more detail, such as the strong tag and the mark tag.

Combining Multiple Formatting Tags

Multiple Formatting Example

html

<p>This <b><i><mark>text</mark></i></b> is bold, italic, and highlighted.</p>

Tags can be nested inside each other. Close them in the reverse order you opened them.

Preformatted & Code Text

<pre> Tag

Pre Tag Example

html

<pre>
Line 1
  Line 2 (Indented)
    Line 3
</pre>

<code> Tag

Code Tag Example

html

<code>console.log("Hello World");</code>

Combined <pre> and <code> Tag

Combined Example

html

<pre><code>function greet() { console.log("Hello!"); }</code></pre>

Meaning first, looks second

  • Use <strong> for importance and <em> for stress. Use <b> and <i> only when there is a reason for the style but no extra meaning.
  • When you only want a look, such as a colored or bold label, use CSS instead of a formatting tag.

Example

html

<p style="font-weight: bold; color: #29AB87;">Styled with CSS</p>

Practical Example: Product Description

Practical Example

html

<h2>Smart Watch Features</h2>
<p>
  The <strong>new SmartTime X</strong> comes with a 
  <em>heart rate monitor</em> and <mark>GPS tracking</mark>.
  Battery lasts for <b>7 days</b> and is <u>water-resistant</u>.
</p>
<p>
  Old price: <del>$199</del>  
  New price: <ins>$149</ins>
</p>

The product name is important (<strong>), the feature is stressed (<em>), GPS is highlighted, and the old price is crossed out next to the new one.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML Text Formatting exercises

Mark real importance

Write the paragraph Danger: high voltage. and mark the word Danger as important.

Result

Check your answer to see it here.