How to use the HTML span tag
The HTML <span> tag is used to group and style in-line elements.
Syntax
Various attributes can be set in the <span> tag. The general syntax to do so is as follows:
<p <span style="attribute: value.."> </p>
The <span> tag is supported by the following browsers:
Examples
- Let’s take a look at how we can use the
<span>tag to highlight a certain part of the text:
- The
<span>tag can also be used to group elements.
Consider the following example in which we wish to style particular sub-strings throughout the text. This can be achieved by creating a class and styling it as desired. The class name can then be used throughout the code within the <span> tag to assign it the particular properties.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved