How to Use Span in HTML
In this article, we will see how to use span in HTML. The span tag is an inline element and it is used to target specific text or sentences. The span tag is often not used alone but used within an element.
Usage of span
If you want to apply different styles to a part of your text content, then you can place it inside the <span> tag Only the text part you want to style and style the text part easily. We can also set the correct width of the span. Now let’s see some example code and learn how to use span tag properly.
Example:
<p> My parents and I went to a movie </p>
- In the above code, we have the sentence “My parents and I went to a movie” in <p> tag.
- If you want to apply a different color to the text “movie” only. So, how can you do that, if you apply color to the paragraph element the color of the whole sentence will be changed.
- So, how can you apply different colors to only the text “movie”? The only solution is can use HTML <span> tag to markup the text “movie” and then apply a style to that span element. So, let’s do that.
<p> My parents and I went to a <span style="color:red" > movie </span></p>
Output: