Understanding HTML Tags and Elements: A Beginner's Guide

Search for a command to run...

No comments yet. Be the first to comment.
You open WhatsApp, type a message, and hit send. A single grey tick appears. You're on a train with no signal, but the message went through anyway. Or did it? That single tick is the beginning of a su

You record a Reel, add a song, trim it, and then close the app before posting. When you reopen Instagram, the draft is right there waiting. Nothing was lost. That experience feels simple. The system b

If you have built a React Native app, you have felt the pain of navigation setup. It is easy to get wrong and hard to keep clean as apps grow. This article explains what routing means, why it matters,

Modern apps are not just a pile of screens. They are a living system of features, data flows, offline behavior, and performance constraints. If you have only shipped small apps, the jump to something

Your application has user accounts. Some routes should only be accessible to logged-in users. How do you protect routes and verify that a request actually comes from who they claim to be? JWT (JSON We

Ashish's Blog
57 posts
If you've ever wondered how websites are built, the answer starts with HTML. Think of HTML as the skeleton of every webpage you see on the internet—it provides the structure and framework that holds everything together.
HTML stands for HyperText Markup Language. It's the standard language used to create and structure content on the web. Without HTML, websites would simply not exist.
We use HTML to:
Define the structure of web pages
Organize content like headings, paragraphs, images, and links
Tell browsers how to display information
Create the foundation that CSS and JavaScript build upon
Think of building a house: HTML is the frame and walls, CSS is the paint and decoration, and JavaScript is the electricity that makes things interactive.
An HTML tag is like a label that tells the browser what kind of content it's dealing with. Tags are written inside angle brackets, like this: <tagname>.
Imagine you're writing a sentence and you want to emphasize a word. You might underline it or put it in bold. HTML tags work the same way—they wrap around content to give it meaning and structure.
Or think of tags as boxes with labels. When you're packing for a move, you put items in boxes and label them: "Kitchen," "Bedroom," "Fragile." HTML tags label different pieces of content on your webpage so the browser knows how to handle them.
Most HTML tags come in pairs: an opening tag and a closing tag, with content sandwiched in between.
Structure:
<tagname>Content goes here</tagname>
Opening tag: <tagname> — Marks the beginning
Content: The actual text or information
Closing tag: </tagname> — Marks the end (notice the forward slash /)
Example:
<p>This is a paragraph of text.</p>
Here:
<p> is the opening tag
"This is a paragraph of text." is the content
</p> is the closing tag
Here's where people often get confused: what's the difference between a tag and an element?
Simple answer: An HTML element is the complete package—the opening tag, the content, and the closing tag all together.
<h1>Welcome to My Website</h1>
```
- **Tags**: `<h1>` and `</h1>` are the individual tags
- **Element**: The entire thing—`<h1>Welcome to My Website</h1>`—is the element
### Visual Breakdown: Tag vs Element
```
Element
┌─────────────────┐
│ │
<h1>Welcome to My Website</h1>
↑ ↑ ↑
Opening Content Closing
Tag Tag
Think of it this way: If tags are the slices of bread, the element is the whole sandwich.
Not all HTML elements need a closing tag. Some elements are self-closing because they don't contain any content between tags. These are called void elements.
Common self-closing elements:
<img src="photo.jpg" alt="A beautiful sunset">
<br>
<hr>
<input type="text">
These elements stand alone because they don't wrap around content:
An <img> tag displays an image—there's no text content inside it
A <br> tag creates a line break—it's just an action, not a container
An <hr> tag draws a horizontal line
An <input> tag creates a form field
HTML elements behave in two main ways on a webpage: as block-level elements or inline elements. Understanding this difference is crucial for layout.
Block-level elements take up the full width available and always start on a new line. Think of them as stacking boxes—each one sits on top of the other.
Common block-level elements:
<div>This is a division</div>
<p>This is a paragraph</p>
<h1>This is a heading</h1>
Visual representation:
┌──────────────────────────────────┐
│ <div>First block</div> │
└──────────────────────────────────┘
┌──────────────────────────────────┐
│ <p>Second block</p> │
└──────────────────────────────────┘
┌──────────────────────────────────┐
│ <h1>Third block</h1> │
└──────────────────────────────────┘
Inline elements only take up as much width as needed and don't start on a new line. They flow within the text, like words in a sentence.
Common inline elements:
<span>This is a span</span>
<a href="#">This is a link</a>
<strong>This is bold text</strong>
Visual representation:
This is a <span>span element</span> inside a sentence.
You can also have <a href="#">links</a> and <strong>bold text</strong> inline.
Let's look at some essential HTML tags you'll use all the time:
<h1>Main Heading (Largest)</h1>
<h2>Subheading</h2>
<h3>Smaller Subheading</h3>
<!-- h4, h5, h6 get progressively smaller -->
<p>This is a paragraph. It's used for regular text content.</p>
<div>
A div is a container used to group other elements together.
</div>
<p>This is a paragraph with a <span>highlighted section</span> inside.</p>
<a href="https://example.com">Click here to visit Example</a>
<img src="image.jpg" alt="Description of image">
<!-- Unordered List -->
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
<!-- Ordered List -->
<ol>
<li>First step</li>
<li>Second step</li>
</ol>
<h1>My First Webpage</h1>
<p>Welcome to my website! This is a <strong>paragraph</strong> with some text.</p>
<div>
<h2>About Me</h2>
<p>I'm learning HTML and it's <span>exciting</span>!</p>
</div>
Want to see HTML in action? Here's how to inspect any webpage:
Method 1:
Right-click anywhere on a webpage
Select "Inspect" or "Inspect Element"
The browser's developer tools will open, showing you the HTML
Method 2:
Windows/Linux: Press Ctrl + Shift + I
Mac: Press Cmd + Option + I
Try inspecting this very blog post! You'll see all the HTML tags used to create it. This is one of the best ways to learn—by seeing how real websites structure their content.
Let's recap what we've learned:
HTML is the skeleton of every webpage—it provides structure
Tags are the labels (like <p> and </p>)
Elements are the complete package: opening tag + content + closing tag
Some elements are self-closing (like <img> and <br>)
Block elements stack vertically and take full width
Inline elements flow within text and take minimal width
Common tags include <h1>, <p>, <div>, <span>, <a>, and <img>
The best way to learn HTML is by doing. Open a text editor, create a file called index.html, and start experimenting with these tags:
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>I'm learning HTML!</p>
</body>
</html>
Save this file and open it in your browser. Congratulations—you've just created your first webpage!
Remember, every expert web developer started exactly where you are now. Keep practicing, stay curious, and don't be afraid to inspect other websites to see how they're built. Happy coding!