The Span tag in HTML is an inline container used to mark or group a small portion of text or inline content so you can style it with CSS or control it with JavaScript. It doesn’t create a new line or add extra space by itself.
In this article, you will know all about the Span in HTML, its uses, and how to use it in HTML.
What is Span in HTML?
The Span in HTML is an inline element used to group small pieces of text or inline elements so you can style or manipulate them with CSS or JavaScript.
It doesn’t add line breaks or extra space ,it simply acts as an invisible container.
What is the Span Tag in HTML?

The Span tag is a generic container for text or inline elements. By itself, it has no visual effect. Its main role is to help developers target specific parts of a page when they want to apply styles or run scripts.
Basic Syntax
<span>Content goes here</span>
Code language: HTML, XML (xml)
You can add attributes like class
or id
:
<span class="highlight">Highlighted text</span>
Code language: HTML, XML (xml)
What Is the Use of Span in HTML?
The Span tag is manily used for the :
1. Styling Part of Text
Change the color, font, or size of only a few words.
<p>This is <span style="color:blue;">blue text</span>.</p>
Code language: HTML, XML (xml)
2. Adding Classes or IDs
Give it a class or ID to apply custom CSS.
<span class="highlight">Important word</span>
Code language: HTML, XML (xml)
3. JavaScript Actions
Use it to add a click or hover effect.
<span onclick="alert('Hello!')">Click me</span>
Code language: HTML, XML (xml)
Also Read , What is CSS in HTML and its types
How to Use Span Tag in HTML?

Using Span Tag is Simple:
- Write the tag where you want to style or control part of the text.
<span>Your text here</span>
Code language: HTML, XML (xml)
- Add a style or class to make it look different.
<span style="color:green;">Green text</span>
Code language: HTML, XML (xml)
- Use CSS for reusable styles by adding a class or ID.
<style>
.highlight { background: yellow; }
</style>
<p>This is a <span class="highlight">highlighted word</span>.</p>
Code language: HTML, XML (xml)
That’s it; you can now change the appearance or add JavaScript actions to that specific part of text.
Difference Between <div>
and <span>
Feature | <div> | <span> |
Type | Block element | Inline element |
Line break | Starts a new line | Stays in same line |
Best for | Big sections | Small text parts |
Final Thoughts
The <span>
tag in HTML is a handy tool for styling or controlling small parts of text. It is an inline element, which means it stays on the same line as the surrounding words. You can use <span>
to change text color, add a background, make words bold, or even attach simple JavaScript actions like a click event. On my website WebWorksCo, I often use the <span>
tag to highlight important words and create neat visual effects. By adding a class or an id, you can reuse the same style across many places on your site without changing the paragraph layout.
Frequently Asked Questions
Q1. What are spans used for?
Spans are used to style or control small parts of text or inline content with CSS or JavaScript without breaking the line of text.
Q2. Is it I or span in HTML?
It is <span>
in HTML. The <i>
tag is a separate tag used to italicize text, while <span>
is for styling or scripting specific inline content.
Inactive
More than Tech: It's the Care We Put into Every Solution
Flagship Tools
Inactive
We Use IT to Give
Life to Your Vision
Platform partnerships
- Digital Ocean
- AWS
- Backblaze
- Interakt