HTML Elements Explained with Examples
Learn HTML Elements with simple Code Examples. Understand Start Tags, End Tags, Nested Elements, Void Elements, and correct HTML Structure.
This content is not yet available in pa. Showing English version.
View in English →In the previous chapter, you explored basic HTML Examples and created a simple Web Page using Headings, Paragraphs, Links, Images, and Buttons.
Now it is time to understand how HTML Elements actually work.
HTML Elements are the building blocks of a Web Page. They define the structure and meaning of different parts of your Content.
In this chapter, you will learn about Start Tags, End Tags, Element Content, Nested Elements, Void Elements, and common mistakes beginners should avoid.
What is an HTML Element?
An HTML Element is defined by a Start Tag, its Content (when applicable), and an End Tag.
Basic Syntax:
<tagname>Content goes here...</tagname>Example:
<h1>Welcome to HTML</h1>This Example contains three parts:
| Part | Description |
|---|---|
| \<h1> | Start Tag - marks the beginning of the Element. |
| Welcome to HTML | Element Content - the text inside the Element. |
| \</h1> | End Tag - marks the end of the Element. |
Together, these parts form an HTML Element.
Remember: An HTML Element is not exactly the same as an HTML Tag. Tags are part of the syntax used to define an Element.
Start Tags and End Tags
Most HTML Elements have both a Start Tag and an End Tag.
The End Tag includes a forward slash / before the Tag Name.
Example:
<p>This is a paragraph.</p>Here:
<p>is the Start Tag.This is a paragraph.is the Element Content.</p>is the End Tag.
Another Example:
<h2>About Me</h2>
<p>I am learning HTML.</p>Important: Not every HTML Element has an End Tag. Some Elements are Void Elements, which you will learn about later in this chapter.
Nested HTML Elements
HTML Elements can contain other HTML Elements.
When one Element appears inside another Element, it is called a Nested Element.
Example:
<p>
I am learning <strong>HTML</strong> today.
</p>In this Example:
<p>is the Parent Element.<strong>is a Child Element nested inside<p>.<strong>gives its Content strong importance. Browsers commonly display it in bold.
Another Example
<div>
<h2>My Profile</h2>
<p>Welcome to my website.</p>
</div>Here, <h2> and <p> are nested inside <div>.
The <div> Element acts as a generic Container for the Content.
The HTML Document Contains Nested Elements
A complete HTML Document contains multiple levels of Nested Elements.
Example:
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>Understanding the Structure
<html>is the Root Element of the HTML Document.<head>and<body>are Child Elements of<html>.<title>is nested inside<head>.<h1>and<p>are nested inside<body>.
Important: <!DOCTYPE html> is a Declaration, not an HTML Element.
Never Forget the End Tag
Some HTML End Tags may be omitted under specific rules, but beginners should write them whenever required or appropriate.
Example — Recommended:
<p>This is my first paragraph.</p>
<p>This is my second paragraph.</p>Example — End Tags Omitted:
<p>This is my first paragraph.
<p>This is my second paragraph.HTML permits omission of the </p> End Tag in certain situations, and Browsers can often interpret the Code correctly.
However, writing explicit End Tags makes your Code easier to read, maintain, and debug.
Important: Do not assume that all End Tags are optional.
Empty HTML Elements and Void Elements
Some HTML Elements cannot contain Child Content and do not have End Tags.
These are called Void Elements.
Common Examples include:
| Element | Purpose |
|---|---|
| \<br> | Inserts a Line Break. |
| \<hr> | Represents a Thematic Break. |
| \<img> | Embeds an Image. |
| \<input> | Creates an Input Control. |
| \<meta> | Provides Document Metadata. |
| \<link> | Links an external Resource, commonly a Stylesheet. |
Example:
<p>Hello<br>World!</p>Another Example:
<img src="photo.jpg" alt="A landscape photograph">The <img> Element does not have a Closing Tag such as </img>.
Note: In HTML Syntax, a trailing slash such as <br /> is permitted on Void Elements, but it is not required and does not create a Closing Tag.
HTML is Not Case-Sensitive for Tag Names
In standard HTML Syntax, Tag Names are case-insensitive.
For example, Browsers recognize the following:
<P>This is a paragraph.</P>And:
<p>This is a paragraph.</p>Both represent a Paragraph Element in an HTML Document.
Recommended Practice: Always write HTML Tag Names in lowercase.
<h1>My Website</h1>
<p>Welcome to my website.</p>Lowercase Tag Names improve consistency and readability.
Note: This rule applies to HTML Tag Names in HTML Syntax. Other syntaxes, such as XML, have different rules.
Correctly Nesting HTML Elements
Nested Elements should be closed in the correct order.
Incorrect:
<p>This is <strong>important.</p></strong>The <strong> Element starts inside <p>, but its End Tag appears after </p>.
Correct:
<p>This is <strong>important.</strong></p>Think of Nested Elements as boxes: close the inner box before closing the outer box.
Block-Level and Inline Elements: A First Look
HTML Elements have different default display behaviors in Browsers.
For example:
<h2>My Heading</h2>
<p>My paragraph.</p>Headings and Paragraphs are normally displayed as separate Blocks.
Now consider:
<p>
Learn <strong>HTML</strong> with W3PrimeCode.
</p>The <strong> Element normally appears within the same line of text.
This is a basic introduction to Block and Inline display behavior. You will study it in greater detail in a later chapter.
Remember: CSS can change how Elements are displayed.
Complete Practical Example
Let's combine different types of HTML Elements.
<!DOCTYPE html>
<html>
<head>
<title>Understanding HTML Elements</title>
</head>
<body>
<div>
<h1>Welcome to My Website</h1>
<p>
I am learning <strong>HTML</strong>
with W3PrimeCode.
</p>
<hr>
<h2>My Introduction</h2>
<p>
My name is Alex.<br>
I want to become a Web Developer.
</p>
<img
src="https://www.w3.org/Icons/w3c_home"
alt="W3C Logo"
width="100"
>
</div>
</body>
</html>Expected Output
The Browser displays:
- A main Heading.
- A Paragraph containing an important word.
- A Thematic Break.
- A second Heading.
- A Paragraph containing a Line Break.
- An Image, if the Resource is available.
What Did You Learn?
This Example includes:
- Elements with Start Tags and End Tags.
- Nested Elements.
- A generic Container Element.
- Void Elements such as
<hr>,<br>, and<img>.
Common Beginner Mistakes
Mistake 1: Forgetting the End Tag
Incorrect:
<h1>Welcome to HTMLCorrect:
<h1>Welcome to HTML</h1>Mistake 2: Incorrect Nesting
Incorrect:
<p>Hello <strong>World</p></strong>Correct:
<p>Hello <strong>World</strong></p>Mistake 3: Adding an End Tag to a Void Element
Incorrect:
<br></br>Correct:
<br>Mistake 4: Confusing Tags with Elements
A Tag is part of the HTML Syntax. An Element is the complete structure represented by that Syntax.
Try It Yourself
Create a File named html-elements.html.
Starter Code:
<!DOCTYPE html>
<html>
<head>
<title>HTML Elements Practice</title>
</head>
<body>
<h1>My Profile</h1>
<p>
My name is <strong>Your Name</strong>.
</p>
<hr>
<p>
I am learning HTML.<br>
This is my practice page.
</p>
</body>
</html>Your Tasks:
- Replace
Your Namewith your name. - Add another Heading using
<h2>. - Add a new Paragraph inside
<body>. - Add a
<div>Container around a Heading and Paragraph. - Add an Image using
<img>and meaningfulaltText. - Check that all Nested Elements are closed correctly.
- Save the File and view it in your Browser.