HTML Text Formatting and Headings
1. Introduction
Welcome to Chapter 2 of the HTML for Beginners course! In this chapter, we will explore HTML text formatting and headings. You will learn how to structure your text and apply basic formatting like bolding, italics, and highlighting directly through HTML tags.2. Learning Objectives
By the end of this chapter, you will be able to:- Structure a document using HTML headings correctly.
- Add and format paragraphs.
- Use text formatting tags to emphasize and style text.
- Understand the semantic meaning behind formatting tags.
3. HTML Headings
Headings in HTML are used to define the titles or subtitles of your webpage. HTML provides six levels of headings, from<h1> to <h6>.
-
<h1>is the most important heading (usually the main title).
-
<h6>is the least important.
Best Practice: Use exactly one <h1> per page for SEO purposes, and use <h2> through <h6> in a logical hierarchy without skipping levels.
4. Paragraphs and Line Breaks
The<p> tag defines a paragraph. Browsers automatically add empty space (margin) before and after a paragraph.
To force a line break within a paragraph without starting a new one, use the <br> tag (an empty element with no closing tag).
5. Bold and Strong Text
To make text bold, you can use<b> or <strong>.
-
<b>: Bolds text for visual purposes.
-
<strong>: Bolds text but also adds semantic importance (screen readers will emphasize it).
6. Italic and Emphasized Text
Similarly, you can italicize text using<i> or <em>.
-
<i>: Italicizes text visually.
-
<em>: Emphasizes text semantically.
7. Small, Marked, and Deleted Text
-
<small>: Renders smaller text (often used for copyright).
-
<mark>: Highlights text (usually with a yellow background).
-
<del>: Renders a strikethrough line over the text.
8. Inserted, Subscript, and Superscript Text
-
<ins>: Represents inserted text (usually underlined).
-
<sub>: Subscript text (appears half a character below the normal line, like H₂O).
-
<sup>: Superscript text (appears half a character above, like X²).
9. Quotations and Blockquotes
-
<q>: Used for short, inline quotes. Browsers insert quotation marks around it.
-
<blockquote>: Used for long quotations. Browsers usually indent blockquotes.
10. Horizontal Rules
The<hr> tag creates a thematic break, displayed as a horizontal line.
11. Real-World Typography Example
Combining these tags creates richly formatted articles.12. Best Practices & Common Mistakes
Best Practices:-
Always use semantic tags (
<strong>,<em>) over visual tags (<b>,<i>) when the text has special meaning.
-
Maintain a strict heading hierarchy (
H1 -> H2 -> H3).
Common Mistakes:
-
Using
<br>to create space between elements (use CSS margins instead).
-
Using
<h1>multiple times on a single page.
- Using headings just to make text bold and big.
13. Mini Project: Formatted Article Page
Task: Create a news article using headings, paragraphs, strong text, marked text, and blockquotes.14. MCQ Quiz
- 1. Which tag is used for the most important heading?
-
A)
<heading>
-
B)
<h6>
-
C)
<h1>
-
D)
<head>
- 2. How do you add a line break?
-
A)
<break>
-
B)
<br>
-
C)
<lb>
-
D)
\n
- 3. Which tag defines semantic emphasis?
-
A)
<i>
-
B)
<italic>
-
C)
<em>
-
D)
<strong>
15. Interview Questions
Q: What is the difference between<b> and <strong>?
A: <b> makes text bold purely for visual presentation. <strong> makes it bold AND indicates semantic importance, which is helpful for screen readers and SEO.
Q: Why shouldn't you use <br> to create spacing between paragraphs?
A: <br> is meant for line breaks within a block of text (like a poem or address). For spacing between distinct elements, CSS margin should be used for better structure and control.
16. FAQs
Q: Can I change the size of<h1>?
A: Yes, the default size is controlled by the browser, but you can override it easily using CSS.
17. Summary
You've learned how to structure text using headings and paragraphs, and how to format it using tags like<strong>, <em>, <mark>, and <blockquote>. You now know how to apply semantic meaning to your content.