Text formating and heading in html5
Text formating and heading in html5
1. Headings in HTML
Headings help structure a webpage and range from <h1> (largest) to <h6> (smallest).
Example:
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Section Title</h3>
<h4>Subsection</h4>
<h5>Smaller Subsection</h5>
<h6>Smallest Heading</h6>
Usage Rules:
✔ Use only one <h1> per page (for SEO and accessibility).
✔ Headings should follow a logical hierarchy.
✔ Do not use headings just for styling; use them for content organization.
The <p> tag is used for paragraphs, while <br> is for line breaks.
Example:
🔹 <br> vs. <p>: Use <br> inside paragraphs for single line breaks, but separate
topics with <p>.
4. Lists in HTML
Unordered List (<ul>)
<ul>
<li>Apples</li>
<li>Bananas</li>
<li>Cherries</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Practice Exercise
✅ A title
✅ A main heading (<h1>)
✅ A paragraph (<p>)
✅ A bold and italic word
✅ An ordered list
Code Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Formatting</title>
</head>
<body>
<h1>Welcome to HTML Formatting</h1>
<p>This is a <strong>bold</strong> and <em>italic</em> text example.</p>
<h2>My Favorite Fruits</h2>
<ol>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ol>
</body>
</html>