๐จ HTML Text Formatting ๐
Master text appearance and structure in HTML using these tags and best practices.
๐๏ธ Core Formatting Tagsโ
Bold: <b>
& <strong>
๐ชโ
-
<b>
: Bold, style only
<b>Attention!</b>
โ Attention! -
<strong>
: Important, for meaning & accessibility
<strong>Warning!</strong>
โ Warning!
Italics: <i>
& <em>
โ๏ธโ
<i>
: Italicizes (terms, names)
<i>Book Title</i>
โ Book Title<em>
: Emphasizes (adds vocal stress)
<em>Really important!</em>
โ Really important!
Underline: <u>
โ ๏ธโ
- Use sparingly โ often confused with links
<u>Caution</u>
โ Caution
โจ Enhanced Formattingโ
Highlight: <mark>
๐๏ธโ
- Highlights text
<mark>Found match</mark>
โ Found match
Small Text: <small>
๐โ
- Deemphasized, fine print
<small>Terms apply</small>
โ Terms apply
Strikethrough & Deleted: <s>
, <del>
๐๏ธโ
<del>
: Show deleted from document
<del>Outdated info</del>
โOutdated info<s>
: Show no longer correct
<s>Incorrect price</s>
โIncorrect price
Inserted: <ins>
โโ
- Underlined, show additions
<ins>Updated info</ins>
โ Updated info
Subscript & Superscript: <sub>
, <sup>
๐งชโ
<sub>
: Lowered text
H<sub>2</sub>O
โ HโO<sup>
: Raised text
x<sup>2</sup>
,July 26<sup>th</sup>
โ xยฒ , July 26แตสฐ
Quotation & Citation: <blockquote>
, <q>
, <cite>
๐โ
<blockquote>
: For long quotations (adds indentation)<blockquote>
"HTML formatting powers web content."
</blockquote><q>
: For short, inline quotes
<q>Best practices matter.</q>
โ "Best practices matter."<cite>
: Reference sources
<cite>MDN Web Docs</cite>
โ MDN Web Docs
Abbreviation & Definition: <abbr>
, <dfn>
๐ง โ
<abbr>
: Show abbreviations with tooltip<abbr title="HyperText Markup Language">HTML</abbr>
โ HTML (with tooltip)<dfn>
: Define a term
<dfn>HTML</dfn> means Hypertext Markup Language
Code & Preformatted: <code>
, <pre>
, <kbd>
, <samp>
, <var>
๐ปโ
-
<code>
: Code snippet
<code>console.log('Hi!')</code>
โconsole.log('Hi!')
-
<pre>
: Preformatted (respects whitespace/line breaks)<pre>
This is
preformatted text
</pre> -
<kbd>
: Keyboard input
<kbd>Ctrl + S</kbd>
โ Ctrl + S -
<samp>
: Sample output
<samp>Success!</samp>
โSuccess!
-
<var>
: Variables in code/math
<var>username</var>
โ username
๐ Additional Semantic Elementsโ
Address & Contact: <address>
๐โ
- Contact information for article/page author
<address>
Written by <a href="mailto:john@example.com">John Doe</a><br>
Visit us at: 123 Main St, City
</address>
Time & Dates: <time>
โฐโ
- Machine-readable dates and times
<time datetime="2024-01-15">January 15, 2024</time>
<time datetime="2024-01-15T14:30">2:30 PM today</time>
Ruby Annotations: <ruby>
, <rt>
, <rp>
๐ณโ
- For East Asian typography (pronunciation guides)
<ruby>
ๆผขๅญ <rp>(</rp><rt>Kanji</rt><rp>)</rp>
</ruby>
Bidirectional Text: <bdi>
, <bdo>
๐โ
<bdi>
: Isolate text with different direction<bdo>
: Override text direction<bdo dir="rtl">This text goes right to left</bdo>
Generic Containers: <span>
, <div>
๐ฆโ
<span>
: Inline generic container<div>
: Block-level generic container<p>This is <span class="highlight">highlighted text</span> in a paragraph.</p>
๐ Best Practicesโ
HTML = Structure & Meaning
CSS = Style & Appearance
<strong class="highlight">Alert: Action required now!</strong>
.highlight { background: yellow; color: black; font-style: italic; }
๐ฏ Key Guidelinesโ
- Use semantic tags for accessibility & SEO
- Separate content from presentation - keep styling with CSS
- Choose tags by meaning, not appearance
- Test with screen readers for accessibility
- Validate your HTML for browser compatibility
๐ Complete Reference Tableโ
Tag | Purpose | Example | Output |
---|---|---|---|
<b> | Bold (style) | <b>Bold</b> | Bold |
<strong> | Bold (importance) | <strong>Important</strong> | Important |
<i> | Italic (style) | <i>Italic</i> | Italic |
<em> | Italic (emphasis) | <em>Emphasis</em> | Emphasis |
<u> | Underline | <u>Underline</u> | Underline |
<mark> | Highlight | <mark>Highlight</mark> | Highlight |
<small> | Small text | <small>Footnote</small> | Footnote |
<del> | Deleted (strike) | <del>Deleted</del> | |
<s> | Strikethrough | <s>Wrong</s> | |
<ins> | Inserted | <ins>Added</ins> | Added |
<sub> | Subscript | H<sub>2</sub>O | HโO |
<sup> | Superscript | x<sup>2</sup> | xยฒ |
<blockquote> | Long quote | <blockquote>Quote</blockquote> | Indented quote |
<q> | Short quote (inline) | <q>Short quote</q> | "Short quote" |
<cite> | Citation | <cite>Source</cite> | Source |
<abbr> | Abbreviation | <abbr title="World Wide Web">WWW</abbr> | WWW (tooltip) |
<dfn> | Definition | <dfn>Word</dfn> | Word |
<code> | Code | <code>alert()</code> | alert() |
<pre> | Preformat | <pre>text</pre> | Preformatted |
<kbd> | Keyboard input | <kbd>Ctrl+C</kbd> | Ctrl+C |
<samp> | Sample output | <samp>Output</samp> | Output |
<var> | Variable | <var>variable</var> | variable |
<time> | Date/time | <time>2024-01-15</time> | 2024-01-15 |
<address> | Contact info | <address>Contact</address> | Contact info |
Let's Have a quick recapโ
1. What does HTML stand for?
2. Which tag is used to define the main visible content of an HTML document?
3. What does the `alt` attribute in the <img> tag do?
4. Which of the following elements is a block-level element?
5. Which of these tags is used to create a hyperlink in HTML?
6. What will happen if you place a <div> tag inside a <strong> tag?
7. Which tag is used to insert a line break in HTML?
8. Which HTML attribute opens a link in a new browser tab?
9. What is the purpose of semantic tags like <header>, <article>, and <footer>?
10. Which display behavior is true for inline elements?