π Chapter 3: Understanding HTML Tags
π What Are HTML Tags?
In HTML, the core building blocks are called tags. Tags tell the browser how to display and structure content on a web page.
HTML tags are enclosed within angle brackets:
<tagname> Content </tagname>
π Example:
<title>My Web Page</title>
<title>
is the opening tag</title>
is the closing tagMy Web Page
is the content
π§© Types of HTML Tags
There are mainly two types of HTML tags:
π °οΈ 1. Paired Tags (Container Tags)
These tags come in pairs β an opening tag and a closing tag.
- The opening tag starts with
<tagname>
- The closing tag starts with
</tagname>
π Examples:
<html>
<!-- Web content goes here -->
</html>
<body>
<!-- Body content goes here -->
</body>
In the above examples:
<html>
and</html>
form a pair<body>
and</body>
form another pair
These are called Paired Tags because they “contain” content between them.
π ±οΈ 2. Non-Paired Tags (Empty Tags)
These tags do not have a closing tag. They are self-contained and are used to insert elements like line breaks, images, etc.
π Examples:
<br> <!-- Line break -->
<img src="logo.png" alt="Logo"> <!-- Image -->
<hr> <!-- Horizontal line -->
These are known as Non-Paired or Empty Tags because they do not wrap any content and do not need a closing tag.
π In HTML5, itβs optional to use the trailing slash (/
), so <br>
and <br />
both work.
π Summary
Tag Type | Description | Example |
---|---|---|
Paired Tags | Have both opening and closing tags | <body> ... </body> |
Non-Paired Tags | Have only an opening tag | <br> , <img> , <hr> |