Trusted answers to developer questions

How to use the HTML span tag

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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:

svg viewer

Examples

  1. Let’s take a look at how we can use the <span> tag to highlight a certain part of the text:
  • HTML
  1. 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.

  • HTML

RELATED TAGS

html
span
inline styling
cascading style sheets
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?