Explanation
The <span>
tag allows you to group inline-elements and apply styles to them. By using the inline style attribute, you can define CSS properties directly within the tag. In the example above, by using the "color" property, we have made the word "sky" blue.
Use
The <span>
tag is predominantly used when we want to apply specific styles to certain parts of the text, without affecting the structure of the HTML document. It's also useful when we want to associate a specific class or id to an inline element.
Important Points
- The
<span>
tag is an inline element and it does not create any line breaks before or after the content.
- It should only be used to apply styles, not to define structure or meaning.
- The inline style attribute should be avoided and instead, the use of CSS separate to HTML is encouraged for better code organization and maintainability.
Summary
The <span>
tag is used to group inline-elements and apply styles to them. It has no impact on the structure of an HTML document and is often used in combination with CSS for custom formatting and styling of specific text-based content. However, it should be used with care and inline style attributes should be avoided in favour of CSS classes and ids.