Formatting Text in HTML
HTML provides many elements to format text, add emphasis, and display special types of content. These elements help convey meaning and improve readability.
💻 Basic Text Formatting
<!-- Bold text -->
<strong>Important text (semantic)</strong>
<b>Bold text (visual only)</b>
<!-- Italic text -->
<em>Emphasized text (semantic)</em>
<i>Italic text (visual only)</i>
<!-- Underline -->
<u>Underlined text</u>
<!-- Strikethrough -->
<s>Strikethrough text</s>
<del>Deleted text</del>
<!-- Inserted text -->
<ins>Inserted text</ins>
<!-- Marked/highlighted -->
<mark>Highlighted text</mark>
<!-- Small text -->
<small>Fine print</small>
🔧 Special Text Elements
<!-- Superscript and Subscript -->
<p>E = mc<sup>2</sup></p>
<p>H<sub>2</sub>O</p>
<!-- Abbreviation -->
<abbr title="HyperText Markup Language">HTML</abbr>
<!-- Code -->
<code>let x = 5;</code>
<!-- Preformatted text -->
<pre>
Text with spaces
and line breaks
preserved
</pre>
<!-- Keyboard input -->
<kbd>Ctrl</kbd> + <kbd>C</kbd>
<!-- Sample output -->
<samp>Error: File not found</samp>
<!-- Variable -->
<var>x</var> + <var>y</var> = 10
📝 Quotations
<!-- Blockquote (long quote) -->
<blockquote cite="https://example.com">
This is a long quotation that will be displayed
as a block element with automatic indentation.
</blockquote>
<!-- Inline quote -->
<p>He said, <q>Hello World</q> and left.</p>
<!-- Citation -->
<p><cite>The Great Gatsby</cite> by F. Scott Fitzgerald</p>
🎨 Practical Example
<article>
<h2>Web Development Basics</h2>
<p>
Learning <strong>HTML</strong> is the <em>first step</em>
in web development. HTML stands for
<abbr title="HyperText Markup Language">HTML</abbr>.
</p>
<p>
Important formula: E = mc<sup>2</sup>
</p>
<blockquote>
"The best way to learn is by doing."
</blockquote>
<p>
Use <kbd>Ctrl</kbd> + <kbd>S</kbd> to save your file.
</p>
<p>
Example code: <code>console.log("Hello");</code>
</p>
</article>
🎯 Key Takeaways
- <strong>: Important text (semantic bold)
- <em>: Emphasized text (semantic italic)
- <mark>: Highlighted/marked text
- <code>: Computer code snippets
- <pre>: Preformatted text preserving spaces
- <sup>/<sub>: Superscript and subscript
- <blockquote>: Long quotations