After learning how to create and run an HTML webpage, the next step is understanding how to display and format text properly.
Text is one of the most important parts of any webpage. HTML provides different tags for:
Headings
Paragraphs
Line breaks
Horizontal lines
Text formatting
In this article, we will learn all these concepts in detail with examples.
HTML Headings
Headings are used to define titles and subtitles on a webpage.
HTML provides six heading tags.
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Output Explanation
| Tag | Size |
|---|---|
<h1> | Largest |
<h2> | Smaller than h1 |
<h3> | Medium |
<h4> | Smaller |
<h5> | Very small |
<h6> | Smallest |
Example Program
<!DOCTYPE html>
<html>
<head>
<title>HTML Headings</title>
</head>
<body>
<h1>Main Heading</h1>
<h2>Sub Heading</h2>
<h3>Section Heading</h3>
<h4>Small Heading</h4>
<h5>Very Small Heading</h5>
<h6>Smallest Heading</h6>
</body>
</html>
Importance of Headings
Headings help:
Organize content
Improve readability
Improve SEO
Help search engines understand webpages
Search engines like Google use headings to analyze webpage structure.
Best Practices for Headings
Use Only One <h1> Per Page
The <h1> tag should represent the main title.
Example:
<h1>Introduction to HTML</h1>
Use Headings in Sequence
Correct:
<h1>Main Title</h1>
<h2>Sub Title</h2>
<h3>Topic</h3>
Wrong:
<h1>Main Title</h1>
<h4>Topic</h4>
HTML Paragraphs
Paragraphs are created using the <p> tag.
Syntax:
<p>This is a paragraph.</p>
Example Program
<!DOCTYPE html>
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<h1>About HTML</h1>
<p>
HTML stands for HyperText Markup Language.
It is used to create webpages.
</p>
</body>
</html>
Important Note About Paragraphs
HTML automatically removes extra spaces and line breaks.
Example:
<p>
Hello
World
</p>
Output:
Hello World
HTML Line Break Tag
To move text to the next line, use <br>.
Example:
<p>
Hello<br>
World
</p>
Output:
Hello
World
HTML Horizontal Rule
The <hr> tag creates a horizontal line.
Example:
<h1>HTML</h1>
<hr>
<p>HTML is used for webpage structure.</p>
Uses of Horizontal Rule
Separate sections
Improve webpage design
Organize content visually
HTML Text Formatting
HTML provides formatting tags for changing text appearance.
Bold Text
<b> Tag
<b>Bold Text</b>
Output:
Bold Text
Strong Text
<strong> Tag
<strong>Important Text</strong>
Difference:
<b>only makes text bold<strong>indicates important content
Italic Text
<i> Tag
<i>Italic Text</i>
Emphasized Text
<em> Tag
<em>Emphasized Text</em>
Difference:
<i>→ Visual italic<em>→ Semantic emphasis
Underlined Text
<u> Tag
<u>Underlined Text</u>
Marked Text
<mark> Tag
Highlights text.
<mark>Highlighted Text</mark>
Small Text
<small> Tag
<small>Small Text</small>
Deleted Text
<del> Tag
<del>Deleted Text</del>
Output shows a strike-through line.
Inserted Text
<ins> Tag
<ins>Inserted Text</ins>
Usually displayed with underline.
Superscript Text
<sup> Tag
Used for powers.
Example:
x<sup>2</sup>
Output:
x²
Subscript Text
<sub> Tag
Used in chemical formulas.
Example:
H<sub>2</sub>O
Output:
H₂O
Complete Text Formatting Program
<!DOCTYPE html>
<html>
<head>
<title>Text Formatting</title>
</head>
<body>
<h1>HTML Formatting Tags</h1>
<b>Bold Text</b>
<br><br>
<strong>Important Text</strong>
<br><br>
<i>Italic Text</i>
<br><br>
<em>Emphasized Text</em>
<br><br>
<u>Underlined Text</u>
<br><br>
<mark>Highlighted Text</mark>
<br><br>
H<sub>2</sub>O
<br><br>
x<sup>2</sup>
</body>
</html>
HTML Preformatted Text
The <pre> tag preserves spaces and line breaks.
Example:
<pre>
Hello
World
</pre>
Output keeps formatting exactly as written.
Why <pre> is Useful
Used for:
Poems
Code snippets
ASCII art
Structured text
Example Using <pre>
<pre>
Twinkle Twinkle Little Star
How I Wonder What You Are
</pre>
HTML Quotations
Short Quotations
Use <q> tag.
<q>Knowledge is power</q>
Block Quotations
Use <blockquote>.
<blockquote>
HTML is the backbone of web development.
</blockquote>
Abbreviation Tag
Use <abbr>.
Example:
<abbr title="HyperText Markup Language">
HTML
</abbr>
When the mouse moves over the text, full form appears.
Address Tag
Used for contact information.
<address>
Kolkata, India
</address>
Nested Formatting Tags
Tags can be combined.
Example:
<b><i>Bold and Italic</i></b>
Real-Life Example Webpage
<!DOCTYPE html>
<html>
<head>
<title>Student Blog</title>
</head>
<body>
<h1>Welcome to My Blog</h1>
<hr>
<p>
HTML is the <strong>foundation</strong>
of web development.
</p>
<p>
Learning <mark>HTML</mark> is very important.
</p>
<p>
Water Formula: H<sub>2</sub>O
</p>
<p>
Equation: x<sup>2</sup> + y<sup>2</sup>
</p>
</body>
</html>
Common Mistakes Beginners Make
1. Forgetting Closing Tags
Wrong:
<b>Bold
Correct:
<b>Bold</b>
2. Using Too Many <br> Tags
Avoid excessive line breaks.
3. Using Headings for Styling Only
Headings should represent structure, not just size.
Advantages of Proper Text Formatting
Better readability
Improved webpage structure
Better SEO
Professional appearance
Improved accessibility
Conclusion
Headings, paragraphs, and formatting tags are the basic building blocks of webpage content. They help organize information clearly and make webpages easier to read.
Comments
Post a Comment