DEV Community

Cover image for Understanding HTML Tags and Elements
Debashis Das
Debashis Das

Posted on

Understanding HTML Tags and Elements

Understanding HTML Tags and Elements

When you open any website, what you see—text, buttons, images, headings—doesn’t just magically appear. Behind the scenes, HTML is doing most of the structural work.
Think of HTML as the skeleton of a webpage. Just like our body needs bones to hold everything together, a website needs HTML to give it shape.

Let’s break it down step by step, in the simplest way possible.

1. What is HTML and Why Do We Use It?

HTML (HyperText Markup Language) is the standard language used to create webpages.

We use HTML to:

  • Structure content on the web
  • Tell the browser what is a heading, what is a paragraph, what is an image
  • Organize text, links, images, forms, and more

Without HTML, a webpage would just be plain text with no structure or meaning.

2. What Is an HTML Tag?

An HTML tag is like a label that tells the browser how to treat a piece of content.

You can think of a tag like a box label 📦
It says:

“Hey browser, the content inside me is special—handle it this way.”

Example:


<p>This is a paragraph</p>

Enter fullscreen mode Exit fullscreen mode

Here, <p> tells the browser that the text inside is a paragraph.

3. Opening Tag, Closing Tag, and Content

Most HTML tags come in pairs:

<tagname> content </tagname>

Enter fullscreen mode Exit fullscreen mode

Let’s break it down:


<h1>Hello World</h1>

Enter fullscreen mode Exit fullscreen mode
  • <h1> → Opening tag
  • </h1> → Closing tag
  • Hello World → Content

Together, they form a complete structure.

4. What Is an HTML Element?

An HTML element = opening tag + content + closing tag

<p>Hello chai aur code</p>

Enter fullscreen mode Exit fullscreen mode
  • <p> → tag
  • Hello chai aur code → content
  • </p> → tag

All of this combined is called an HTML element.

Simple difference:

  • Tag → Just the markup (<p>)
  • Element → The full thing (<p>content</p>)

5. Self-Closing (Void) Elements

Some elements don’t need closing tags because they don’t wrap content.
They are called self-closing or void elements.

Examples:


<img src="image.jpg">
<br>
<hr>
<input>
Enter fullscreen mode Exit fullscreen mode

They perform a task instead of holding content:

  • <img> displays an image
  • <br> creates a line break

No closing tag needed

6. Block-Level vs Inline Elements

This concept is very important for layout.

Block-Level Elements

  • Take the full width of the page
  • Always start on a new line

Examples:

<h1>Heading</h1>
<p>Paragraph</p>
<div>Container</div>
Enter fullscreen mode Exit fullscreen mode

Inline Elements

They take only the space they need
Stay on the same line

Examples:

<span>Text</span>
<a href="#">Link</a>
<strong>Bold</strong>
Enter fullscreen mode Exit fullscreen mode

Visual idea:

[ Block Element ]
[ Another Block ]

Inline inline inline

Enter fullscreen mode Exit fullscreen mode

7. Commonly Used HTML Tags (Beginner-Friendly)

Here are some tags you’ll use all the time:

  • <h1> to <h6> → Headings
  • <p> → Paragraph
  • <div> → Container (block-level)
  • <span> → Inline container
  • <a> → Link
  • <img> → Image
  • <ul>, <ol>, <li> → Lists

No need to jump into advanced tags yet—master the basics first.

Diagram: HTML Tag vs Element

Top comments (0)