HTML Tags and Elements
Introduction to HTML Tags and Elements
HTML tags and elements are the building blocks of every web page. They define how content is structured and displayed in a browser. Understanding tags and elements is essential to start creating real web pages.
In this lesson, you will learn what HTML tags and elements are, how they work, and how to use them correctly.
What are HTML Tags?
HTML tags are special keywords enclosed in angle brackets < >. They tell the browser how to display content. Most HTML tags come in pairs: an opening tag and a closing tag.
Example of HTML Tag
In this example:
<p>is the opening tag</p>is the closing tag
What are HTML Elements?
An HTML element consists of an opening tag, content, and a closing tag.
Example of HTML Element
This complete structure is called an HTML element.
Types of HTML Tags
Container Tags
These tags have both opening and closing tags.
Examples:
<h1>This is a heading</h1>
Empty Tags
These tags do not have closing tags.
Examples:
<hr>
<img src=“image.jpg” alt=“image”>
Nested HTML Elements
HTML allows you to place elements inside other elements. This is called nesting.
Example of Nested Elements
<h2>Welcome</h2>
<p>This is a paragraph inside a div.</p>
</div>
Nesting helps in organizing content and creating structured layouts.
Commonly Used HTML Tags
Heading Tags
<h2>Sub Heading</h2>
<h3>Small Heading</h3>
Paragraph and Line Break
<br>
<p>This is another paragraph.</p>
Link Tag
Image Tag
Attributes in HTML
Attributes provide additional information about HTML elements. They are always written inside the opening tag.
Example of Attributes
Common attributes:
- href → specifies link URL
- src → specifies image source
- alt → alternative text for images (important for SEO)
How Browsers Read HTML
Browsers like Google Chrome read HTML tags and render them into a visual format. Proper use of tags ensures that your website displays correctly on all devices.
Best Practices for HTML Tags
- Always close your tags properly
- Use lowercase tag names
- Use proper nesting
- Add alt attributes for images
- Keep code clean and readable
What You Will Learn Next
In the next lesson, you will learn about HTML headings, paragraphs, and formatting tags in detail to create structured content.
Click here for more free courses
FAQs
What is the difference between HTML tag and element?
A tag is a keyword inside angle brackets, while an element includes the tag and the content inside it.
Are all HTML tags paired?
No, some tags like <br> and <img> are empty tags and do not require closing tags.
What are attributes in HTML?
Attributes provide extra information about elements, such as links or image sources.
Why are HTML tags important?
HTML tags define the structure of a webpage and help browsers display content correctly.
Which browser is best for testing HTML?
Browsers like Google Chrome are best for testing HTML due to developer tools.



