Author: Vincent Ortiz
Published: 01/31/2026
HTML <span> Tag 101: A Beginner’s Guide to Using Classes and Spans
What is a span tag in HTML?
In HTML, the <span> tag is primarily used to style specific strings of text within a parent element. For example, you can wrap a few words inside a <p> tag with a <span> to apply unique formatting without breaking the flow of the paragraph.
By pairing <span> tags with CSS classes, you achieve two major advantages:
Consistency: You can maintain a uniform look across your entire website.
Reusability: You can easily apply the same styling to multiple elements throughout your site by simply reusing the class name, making your code cleaner and much easier to manage.
How can you use a <span> tag?
The <span> tag is a versatile tool that can be used in two primary ways: quick inline adjustments and structured, reusable styling.
1. Quick Wins with Inline Styling
Inline styling is the simplest way to use a <span>. It is perfect for one-off scenarios where you need to change the look of a specific word without affecting anything else on your site.
For instance, if you want to turn a single word red within a paragraph, you can use the style attribute directly:
<p>I want to make the last word <span style="color: red;">red</span>.</p>
Beyond color, the <span> tag allows you to modify almost any CSS property, including:
Font-weight: Making text bolder.
Font-size: Increasing or decreasing text scale.
Background-color: Creating a "highlight" effect.
2. Scalable Design with CSS Classes
While inline styles are fast, using a class is the professional approach for consistent design. This method allows you to define your style once in a CSS file and reuse it across multiple pages. This is especially useful for branding elements, such as highlighting keywords in your headlines.
The CSS:
How can you use a <span> tag?
The <span> tag is a versatile tool that can be used in two primary ways: quick inline adjustments and structured, reusable styling.
1. Quick Wins with Inline Styling
Inline styling is the simplest way to use a <span>. It is perfect for one-off scenarios where you need to change the look of a specific word without affecting anything else on your site.
For instance, if you want to turn a single word red within a paragraph, you can use the style attribute directly:
<p>I want to make the last word <span style="color: red;">red</span>.</p>
Beyond color, the <span> tag allows you to modify almost any CSS property, including:
Font-weight: Making text bolder.
Font-size: Increasing or decreasing text scale.
Background-color: Creating a "highlight" effect.
2. Scalable Design with CSS Classes
While inline styles are fast, using a class is the professional approach for consistent design. This method allows you to define your style once in a CSS file and reuse it across multiple pages. This is especially useful for branding elements, such as highlighting keywords in your headlines.
The CSS:
.keyword-highlight {
font-weight: 800;
color: green;
}The HTML:
By applying the same class to your <span> tags, you ensure your site stays visually consistent:
<h2>Shop our <span class="keyword-highlight">latest</span> clothes now</h2>
<h2>Buy <span class="keyword-highlight">new</span> items now</h2>
<h2>We have <span class="keyword-highlight">sold out</span> of all items</h2
Using this method, if you ever decide that your "green" keywords should actually be "blue," you only have to update one line in your CSS file instead of editing every single page.
Can You Use a <div> Instead of a <span> Inside a Text Tag?
The short answer is no.
The reason comes down to how these elements behave on the page. A <div> is a block-level element, meaning it automatically starts on a new line and pushes any following content to a new line as well. If you drop a <div> into the middle of a sentence, it will "break" the paragraph.
A <span>, on the other hand, is an inline element. It lives inside the flow of your text without forcing any line breaks. This is exactly what makes the <span> tag so valuable: it allows you to apply unique styles to specific words while keeping the layout perfectly intact.
Why Nesting Rules Matter
In HTML, there are strict "parent-child" rules. Just as you can't put a <div> inside a <p> tag, you also cannot:
Nest a <p> tag inside another <p> tag.
Nest an <h1> tag inside another <h1>.
Attempting to do this will confuse the browser, often leading to broken layouts and poor SEO.
The Verdict
The <span> tag is the ultimate "surgical tool" for web design. It is the only way to isolate a piece of text for styling—like changing a color or font—without disrupting the natural flow of your content.
FAQ
What is the span tag in HTML used for?
The span tag in HTML is used for changing the look of a specific word or phrase inside a sentence. Unlike other tags that start a new line, the <span> tag stays right where it is, allowing you to change things like text color or font weight without moving the text around. It is the most common way to "highlight" a single part of a paragraph.
How do I use a span HTML class?
A span HTML class is like a label you put on your tag so you can style it later with CSS. Instead of writing the style over and over, you give your span a name like <span class="blue-text">. This lets you apply the same design to many different spans across your website at once, keeping your code clean and easy to read.
Can I change the font size using a span style?
Yes, you can use html span style font size to make specific words bigger or smaller than the rest of the sentence. While you can do this directly in the HTML tag, it is a "best practice" to use a class so that all your important words look exactly the same throughout your site.
What is the "full form" of span in HTML?
In web development, the span full form in html doesn't actually stand for a long technical phrase; it simply refers to a "span" or "extent" of text. Think of it as a way to mark a specific span of characters that you want to treat differently from the text around them.
How do I use a span tag on multiple lines?
Even though it is an inline tag, you can use html span multiple lines to wrap a long phrase that stretches across several lines of a paragraph. The <span> tag will simply follow the text as it wraps, applying your chosen color or style to the entire block of words without forcing them to break into a new section.