Tags, Elements & Attributes
HTML is built with tags, elements and attributes. In this chapter, you will understand how HTML instructions are written, how content is wrapped, and how extra information is added to tags.
<h1>Welcome</h1>
HTML Tag
Tags tell the browser how to treat the content.
<p>This is a paragraph.</p>
HTML Element
Opening tag + content + closing tag create an element.
<a href="about.html">About Us</a>
HTML Attribute
Attributes add extra details to a tag.
After This Chapter, You Will Understand
This chapter helps you read and write HTML code confidently.
Tags
Understand opening tags, closing tags and empty tags.
Elements
Understand how tags and content together form elements.
Attributes
Understand extra information such as href, src, alt, id and class.
Nesting
Understand parent-child structure and proper tag placement.
Tags, Elements and Attributes
These three concepts are the building blocks of HTML coding.
1 What is a Tag?
A tag is a keyword written inside angle brackets. It tells the browser what type of content is being used.
Most tags have an opening tag and a closing tag.
2 What is an Element?
An element includes the opening tag, the content, and the closing tag.
The complete line above is called a paragraph element.
3 What is an Attribute?
An attribute gives extra information about an HTML tag. Attributes are usually written inside the opening tag.
Here, href is an attribute that tells where the link should go.
How HTML Code is Written
HTML follows a simple pattern that every beginner should understand clearly.
<tagname>Content goes here</tagname>
# Element with attribute
<a href="about.html">About Us</a>
# Image tag as empty element
<img src="photo.jpg" alt="Student learning HTML">
Opening Tag
<p>
Starts an element.
Content
Hello Students
The actual text or information.
Closing Tag
</p>
Ends the element.
Common HTML Attributes
Attributes help tags work more powerfully and meaningfully.
| Attribute | Use | Example |
|---|---|---|
| href | Specifies link destination | <a href="about.html">About</a> |
| src | Specifies image or media source | <img src="logo.png"> |
| alt | Gives image description | <img src="logo.png" alt="AICPE Logo"> |
| id | Gives unique identity to an element | <section id="courses"> |
| class | Groups elements for CSS styling | <div class="card"> |
| title | Shows extra tooltip information | <p title="Important point"> |
| lang | Defines language of page or element | <html lang="en"> |
Parent and Child Elements
HTML elements can be placed inside other elements. This is called nesting.
4 Correct Nesting
When one element is written inside another element, the outside element is called the parent and the inside element is called the child.
<h2>About Us</h2>
<p>We provide skill courses.</p>
</section>
5 Wrong Nesting
Tags must be closed in the correct order. Wrong nesting creates messy and confusing code.
<p>This is <strong>important</p></strong>
# Correct example
<p>This is <strong>important</strong></p>
Practice Tags, Elements and Attributes
Edit the code and click Run Code to see the output.
Mistakes Students Should Avoid
Correct tag writing is important for clean and professional HTML.
Wrong Habits
- Forgetting closing tags
- Writing attributes without quotes
- Using the same id multiple times
- Writing wrong image path in src
- Using empty alt text for important images
Correct Habits
- Close tags in proper order
- Write attributes inside opening tag
- Use one unique id per page section
- Use class for repeated design groups
- Write meaningful alt text for images
Test Your Understanding
Select the correct answers and check your score.
1. An HTML tag is written inside:
2. Which is a complete HTML element?
3. Which attribute is used to specify link destination?
4. Which attribute is important for image description?
5. Which attribute is best for repeated CSS styling?
Remember These Points
Revise these before moving to Chapter 5.
Tag
A tag is written inside angle brackets and tells the browser what type of content is used.
Element
An element usually includes opening tag, content and closing tag.
Attribute
An attribute gives extra information to an HTML tag.
Empty Element
Some elements like img and br do not need closing tags.
ID
ID gives a unique identity to one element on the page.
Class
Class is used to group elements for styling and repeated design.