Span and Div Tag in HTML Explained with Example: A Complete Beginner's Guide

In the world of web development, HTML (HyperText Markup Language) is the fundamental building block. Two of the most used tags in HTML are the and

tags. Both are used for containment and styling purposes, but they serve different roles and have distinct characteristics.

div vs span in HTML: Know the Difference
div vs span in HTML: Know the Difference

Let's dive into the and

tags, exploring their uses, differences, and providing examples to help you understand them better.

Span tag and Comment tag in HTML
Span tag and Comment tag in HTML

The Tag

The tag is an inline container used to mark up a part of a text, or a part of another inline element. It's primarily used to apply styles or attributes to part of a text without affecting the whole line or paragraph.

Title: HTML Semantic vs Non-Semantic Tags – Guide by RajNandani
Title: HTML Semantic vs Non-Semantic Tags – Guide by RajNandani

Since is an inline element, it can only contain other inline elements, text, or other tags. It won't cause a line break, and it won't start a new line of text.

Using for Styling

Div tag in html: html div side by side absolute position example
Div tag in html: html div side by side absolute position example

The tag is often used to apply specific styles to a small portion of text. Let's say you want to make a specific word bold and italic within a sentence. You could use like this:

<p>This is a <span style="font-weight: bold; font-style: italic;">very</span> important sentence.</p>

Using with id or class attributes

The tag can also be used to apply id or class attributes, making the span targeted by CSS.

10 Essential HTML Tags Every Developer Should Know"
10 Essential HTML Tags Every Developer Should Know"

<p>This is a <span id="important">very</span> important sentence.</p>

The
Tag

The

tag, on the other hand, is a block-level container that creates a division or a section in an HTML document. It's used to group larger pieces of content, like headlines, paragraphs, images, and other tags.

Being a block-level element,

starts on a new line and takes up the full width available, unless overridden by CSS. It can contain both inline and block-level elements.

an image of a web page with different types of text and symbols on it, including the words div & span
an image of a web page with different types of text and symbols on it, including the words div & span

Using
for Layout

The

tag is often used to structure the layout of a web page. For instance, you might use it to create a header, a footer, or a sidebar.

About HTML tags
About HTML tags
Commonly Used HTML Tags with Examples - DataFlair
Commonly Used HTML Tags with Examples - DataFlair
HTML TAG
HTML TAG
the ultimate guide to creating and formating tags
the ultimate guide to creating and formating tags
π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©
π™ƒπ™π™ˆπ™‡ π™π™–π™œπ™¨ π™˜π™π™šπ™–π™© π™¨π™π™šπ™šπ™©
HTML div tag Example and Tutorial using CSS
HTML div tag Example and Tutorial using CSS
What are HTML Tags? List of common HTML Tags
What are HTML Tags? List of common HTML Tags
Types of tags in HTML
Types of tags in HTML
887 reactions · 135 shares | HTML5 Tags information 2026. #coding #webdevelopment✨ #htmlcssjavascript #programming | Premi Coding | Facebook
887 reactions · 135 shares | HTML5 Tags information 2026. #coding #webdevelopment✨ #htmlcssjavascript #programming | Premi Coding | Facebook
the list of html tags for different types of webpages and pages, with text overlaiding them
the list of html tags for different types of webpages and pages, with text overlaiding them
an image of what are tags in web pages? infographical poster on dark background
an image of what are tags in web pages? infographical poster on dark background
Quick HTML Tags Cheat Sheet
Quick HTML Tags Cheat Sheet
the different types of html tags are shown in this screenshote screen graber
the different types of html tags are shown in this screenshote screen graber
Saidul (@saidul_dev) on X
Saidul (@saidul_dev) on X
the basic html tag list is displayed in this screenshote screen graber, which shows
the basic html tag list is displayed in this screenshote screen graber, which shows
the basic instructions for creating a web page with html and jtmll on it
the basic instructions for creating a web page with html and jtmll on it
HTML Tags β€” List of all HTML Tags with Examples TutorialBrain
HTML Tags β€” List of all HTML Tags with Examples TutorialBrain
Div vs Span: Difference and Comparison
Div vs Span: Difference and Comparison
HTML tags are arranged in the following manner
HTML tags are arranged in the following manner
a close look at tags info sheet
a close look at tags info sheet

<div id="header"><h1>Welcome to My Website</h1></div>
<div id="footer"><p>Β© 2022 My Website. All Rights Reserved.</p></div>

Using
for Styling

Like ,

can also be targeted by CSS using id or class attributes.

<div id="main-content"><p>This is the main content of the page.</p></div>
<style>
#main-content {
  background-color: lightgray;
  padding: 10px;
}
</style>

In conclusion, while both and

tags are used for containment and styling, they serve different purposes. is typically used for small portions of text, while
is used for larger sections of a web page. Both are essential tools in an HTML developer's toolkit.

Now that you understand the basics of and

, why not start practicing by implementing them in a simple HTML file? You can always expand your knowledge and skills from here.

Related Articles

Responsive Web Meaning Html For Absolute Beginners Best Html Tutorial Reddit Html Notes In Code Routing In Html Javascript Angular Html Routing Responsive Html Elements Static Html Routing How To Learn Html For Beginners Free How To Learn Html For Beginners Step By Step