HTML <span> Tag Definition, Usage and Examples

The HTML span> Tag is an internal container that is used to mark up a section of text or a section of a page. Using the class or id property, the <span> HTML Tag may be easily customized with CSS or modified using JavaScript. The <span> HTML tag is similar to the <div> element, however the <div> element is a block-level element, whereas <span> HTML Tag is an inline element. The <span> HTML Tag is part of style and semantics HTML category in HTML Element Reference. The attributes of the <span> HTML Tag are global attributes, and event attributes. 

<span> code block example to learn how it works is given below. 

<span class="myClass">Content here...</span>

The second example usage of the “<span>” code block example is below. 

<blockquote style="font-size:larger;">If someone tells you, <span style="color:green;">"You can't"</span> they really mean, <span style="color:red;">"I can't"</span>.</blockquote>
<cite>Sean Stephenson</cite>

What is <span> HTML Tag?

The <span> HTML tag is a general inline container for expressing text that does not represent anything essentially. It can be used to group items for style purposes (through the class or id properties) or because they have similar attribute values, such as lang. It should only be used when no alternative semantic element is available. The <span> HTML Tag is similar to the div> element, however the <div> is a block-level element, whereas the <span> HTML Tag is an inline element

How to Use <span> HTML Tag?

To use the <span> HTML Tag the web developer should write a <tag? HTML Tag with any children nested between the start and end tags.  Because the <span>HTML Tag does not signify anything on its own, it is usually accompanied by an attribute. The class attribute, which allows the element to be associated with styles from a style sheet, is perhaps the most frequent attribute to utilize with the <span> HTML tag.

Example Usage of <span> HTML Tag?

The following example of usage of <span> HTML tag is given below.

<p>My mother has <span style="color:green">green</span> eyes.</p>

What are the Attributes of <span> HTML Tag?

There are multiple attributes for the <span> HTML Tag. The following attributes are listed below.

  • Global Attributes: The <span> HTML Tag supports Global Attributes. All HTML elements, even those not specified in the standard, can have global attributes. This means that any non-standard elements must nevertheless allow certain characteristics, even if using such elements makes the content non-HTML5 compliant.
  • Event Attributes: The <span> HTML Tag supports Event Attributes. The Event Attributes always have a name that begins with “on” and is followed by the name of the event for which it is intended. They specify a script to run when an event of the defined type is dispatched to the element with the specified attributes.

What are the Default CSS Settings for <span> HTML Tag?

The following is the Default CSS Setting for the <span> HTML Tag.

span.ingredient {
    color: #f00;
}

What are the Related other HTML Tags to <span>?

The other related HTML Tags to the <span> HTML Tag are listed below.

  • <footer> HTML Tag: The <footer> HTML Tag is related to <span> HTML Tag because they are both style and semantic tags. The <footer> HTML Tag specifies a footer for the sectioning content or sectioning root element immediately preceding it.
  • <aside> HTML Tag: The <aside> HTML Tag is related to <span> HTML Tag because they are both style and semantic tags. The <aside> HTML Tag denotes a section of a document whose content is only tangentially related to the page’s primary content.
  • <div> HTML Tag: The <div> HTML Tag is related to <span> HTML Tag because they are both style and semantic tags. The <div> HTML Tag acts as a container for flow content. It has no influence on the text or layout unless and until it is styled with CSS.
  • <summary> HTML Tag: The <summary> HTML Tag is related to <span> HTML Tag because they are both style and semantic tags. The <summary> HTML Tag specifies a summary, caption, or legend for the disclosure box of a <details> HTML Tag.
  • <style> HTML Tag: The <style> HTML Tag is related to <span> HTML Tag because they are both style and semantic tags. The <style> HTML Tag  specifies the style of a document or section of a document. It contains CSS that is applied to the contents of the <style> HTML Tag containing document.
Holistic SEO
Follow SEO

Leave a Comment

HTML <span> Tag Definition, Usage and Examples

by Holistic SEO time to read: 4 min
0