Understanding HTML Tags and Elements: A Beginner's Guide
MERN Stack Developer
Search for a command to run...
MERN Stack Developer
No comments yet. Be the first to comment.
Introduction: The Problem of Styling Imagine you're designing a website with hundreds of paragraphs, dozens of buttons, and multiple navigation menus. You want to: Make all buttons blue Style the main heading differently from subheadings Change th...
Introduction: The HTML Writing Struggle Picture this: You are building a website, and you need to create a navigation menu with five links. Using traditional HTML, you'd type something like this: <nav> <ul> <li><a href=""></a></li> <li><a h...
When you type git commit, have you ever wondered what actually happens behind the scenes? Most developers use Git daily without understanding its internal machinery. This article pulls back the curtain to reveal how Git works at a fundamental level, ...
The Dark Ages of Software Development Picture this: It's 2005. You're a developer working on a critical project with three teammates. Your code lives on a pendrive that gets passed around like a hot potato. Sound familiar? If you've ever named a file...
HTML stands for HyperText Markup Language. It's not a programming language—it's a markup language used to structure content on the web.
Structures content: It tells browsers how to display text, images, videos, and links
Universal standard: Every website uses HTML as its foundation
Works with CSS and JavaScript: HTML provides structure, CSS adds style, and JavaScript adds interactivity
Semantic meaning: It helps search engines and screen readers understand your content
An HTML tag is like a label or instruction that tells the browser how to display a piece of content.
Tags are written with angle brackets (< >). For example:
html
<p>
This is a paragraph tag. It tells the browser: "Hey, the text that follows is a paragraph!"
Most HTML tags come in pairs:
html
<p>This is a paragraph of text.</p>
Let's break this down:
<p> — Opening tag (starts the paragraph)
This is a paragraph of text. — Content (what you want to display)
</p> — Closing tag (ends the paragraph)
Here's where many beginners get confused: What's the difference between a tag and an element?
An HTML element is the complete package: the opening tag + content + closing tag.
html
<h1>Welcome to My Website</h1>
In this example:
Tags: <h1> and </h1>
Content: "Welcome to My Website"
Element: The entire thing together
Simple rule: Tags are the individual pieces; the element is the whole structure.
Not all HTML elements have content between tags. Some elements are self-closing (also called void elements) because they don't wrap around content.
html
<img src="photo.jpg" alt="A beautiful sunset">
<br>
<hr>
<input type="text" placeholder="Enter your name">
<meta charset="UTF-8">
Why are they self-closing?
These elements don't need content inside them. For example:
An <img> tag displays an image—the image file is referenced through an attribute, not wrapped in tags
A <br> tag creates a line break—there's nothing to wrap
An <hr> tag creates a horizontal line—same idea
HTML elements behave differently based on whether they're block-level or inline.
Block-level elements:
Take up the full width available
Always start on a new line
Stack vertically like boxes
Examples:
html
<div>This is a div</div>
<p>This is a paragraph</p>
<h1>This is a heading</h1>
<section>This is a section</section>
```
**Visual representation:**
```
┌─────────────────────────────┐
│ <div>Content here</div> │
└─────────────────────────────┘
┌─────────────────────────────┐
│ <p>Another block</p> │
└─────────────────────────────┘
Inline elements:
Only take up as much width as needed
Do not start on a new line
Flow within the text like words in a sentence
Examples:
html
<span>This is a span</span>
<a href="#">This is a link</a>
<strong>This is bold text</strong>
<em>This is italic text</em>
```
**Visual representation:**
```
This is normal text <strong>with bold</strong> and <a href="#">a link</a> inline.
| Block-Level | Inline |
<div> | <span> |
<p> | <a> |
<h1> to <h6> | <strong> |
<section> | <em> |
<article> | <img> |
<ul>, <ol> | <input> |
Let's explore the tags you'll use most frequently:
html
<h1>Main Heading (Largest)</h1>
<h2>Subheading</h2>
<h3>Smaller Subheading</h3>
<h4>Even Smaller</h4>
<h5>Smaller Still</h5>
<h6>Smallest Heading</h6>
Use case: Organize content hierarchically. <h1> is typically the page title, and you use smaller headings for sections.
html
<p>This is a paragraph. It's used for regular text content.</p>
html
<a href="https://example.com">Click here to visit Example</a>
Attributes:
href: The URL destination
target="_blank": Opens link in a new tab
html
<img src="image.jpg" alt="Description of image">
Attributes:
src: Path to the image file
alt: Alternative text (for accessibility and SEO)
Unordered list (bullets):
html
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
Ordered list (numbers):
html
<ol>
<li>Step one</li>
<li>Step two</li>
<li>Step three</li>
</ol>
html
<div>
This is a block container for grouping content.
</div>
<p>This is a paragraph with <span style="color: red;">red text</span> inside.</p>
html
<strong>Bold text (important)</strong>
<em>Italic text (emphasis)</em>
<b>Bold text (stylistic)</b>
<i>Italic text (stylistic)</i>
<u>Underlined text</u>
html
<p>This is line one.<br>This is line two.</p>
<hr>
Here's a simple HTML page using the tags we've learned:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Blog</h1>
<p>Hello! I'm learning <strong>HTML</strong> and it's <em>amazing</em>.</p>
<h2>My Favorite Things</h2>
<ul>
<li>Coding</li>
<li>Reading</li>
<li>Coffee</li>
</ul>
<h2>Useful Resources</h2>
<p>Check out <a href="https://developer.mozilla.org">MDN Web Docs</a> for more information.</p>
<img src="coding.jpg" alt="Person coding on a laptop">
<hr>
<p>Thanks for visiting!</p>
</body>
</html>
