Lesson 4 +10 XP

Formatting Text

Words can be important, funny, loud, or tiny. HTML has a tag for every mood!

Emphasize: <em> and <strong>

  • <em>: emphasis. Reads like stressed speech: "I really want that."
  • <strong>: strong importance. Reads loudly: "I really want that!"
Code

html
<p>I <em>love</em> this. It is <strong>very</strong> important.</p>

The lookalikes: &lt;b&gt; and &lt;i&gt;

  • &lt;b&gt;: makes text bold (but without extra meaning).
  • &lt;i&gt;: makes text italic (like a foreign word or a thought).
Code

html
<p><b>Bold</b> and <i>italic</i> just for looks.</p>

Struck through and underlined

  • &lt;s&gt;: struck-through text (something that is no longer correct or relevant).
  • &lt;u&gt;: underlined text (like an old-fashioned title).
Code

html
<p><s>Was $10</s> Now $5!</p>
<p><u>Important</u> title.</p>

Small print: &lt;small&gt;

&lt;small&gt; makes text smaller, like &quot;Terms and conditions&quot; fine print.

Highlighted: &lt;mark&gt;

&lt;mark&gt; highlights text with a marker color, like a highlighter pen.

Code

html
<p>Remember to <mark>water the plants</mark>!</p>

Up and down: &lt;sub&gt; and &lt;sup&gt;

  • &lt;sub&gt;: subscript, small text below the line: H2O
  • &lt;sup&gt;: superscript, small text above the line: 23 = 8
Code

html
<p>H<sub>2</sub>O and 2<sup>3</sup></p>

Code: &lt;code&gt;, &lt;kbd&gt;, &lt;samp&gt;, &lt;var&gt;

  • &lt;code&gt;: computer code text.
  • &lt;kbd&gt;: keyboard keys you should press (like &quot;Press &lt;kbd&gt;Ctrl&lt;/kbd&gt;&quot;).
  • &lt;samp&gt;: sample output from a computer.
  • &lt;var&gt;: a variable name, like x.

Quotes: &lt;q&gt; and &lt;blockquote&gt;

  • &lt;q&gt;: a short inline quote, browsers add quote marks automatically.
  • &lt;blockquote&gt;: a long quote on its own block.
Code

html
<p>She said, <q>Let's go!</q></p>

<blockquote>
  This is a longer quote that gets its own block.
</blockquote>

Shortcut for titles: &lt;abbr&gt; and &lt;dfn&gt;

  • &lt;abbr&gt;: an abbreviation. The title attribute shows the full meaning when you hover.
  • &lt;dfn&gt;: marks the place a term is first defined.
Code

html
<p><abbr title="World Wide Web">WWW</abbr></p>
<p><dfn>HTML</dfn> is the language of the web.</p>

Times and dates: &lt;time&gt; and &lt;data&gt;

  • &lt;time&gt;: tells the browser something is a date or time (computers love knowing what a date really is!).
  • &lt;data&gt;: links text to a value.

Edits: &lt;del&gt; and &lt;ins&gt;

  • &lt;del&gt;: deleted text, something that was removed.
  • &lt;ins&gt;: added text, something that was inserted.

Together they can show what changed in a document!


html
<p>I used to eat <del>candy</del> <ins>fruit</ins> every day.</p>

Generic helpers: &lt;span&gt; and &lt;div&gt;

  • &lt;span&gt;: an inline helper with no built-in meaning. Use it to style a bit of text.
  • &lt;div&gt;: a block-level helper that groups stuff. More on this later!
Code

html
<p>Paint this <span style="color:red">word red</span>.</p>

Direction: &lt;bdi&gt; and &lt;bdo&gt;

  • &lt;bdi&gt;: &quot;bi-directional isolation&quot;. Keeps text that reads right-to-left (like Arabic) from messing up the rest.
  • &lt;bdo&gt;: forces text to go a certain direction.

Break opportunities: &lt;wbr&gt;

&lt;wbr&gt; tells the browser &quot;you may break the line here if you need to.&quot; Useful for long URLs or words.

Ruby annotations

&lt;ruby&gt;, &lt;rt&gt;, and &lt;rp&gt; are used for East Asian pronunciation guides (like furigana in Japanese).

TL;DR

  • &lt;em&gt; = stress, &lt;strong&gt; = importance.
  • &lt;b&gt;/&lt;i&gt; = just looks.
  • &lt;mark&gt; = highlighter, &lt;small&gt; = fine print.
  • &lt;sub&gt;/&lt;sup&gt; = below/above the line.
  • &lt;code&gt;/&lt;kbd&gt;/&lt;samp&gt;/&lt;var&gt; = code words.
  • &lt;q&gt;/&lt;blockquote&gt; = quotes.
  • &lt;abbr&gt;/&lt;dfn&gt; = abbreviations/definitions.
  • &lt;time&gt;/&lt;data&gt; = real values for computers.
  • &lt;span&gt;/&lt;div&gt; = helpers.