What is a Span in HTML
In HTML, a <span>
is an inline element used to group and style text within a larger block of content. It does not add any extra line breaks or spaces between the content it surrounds. The <span>
element is commonly used to apply CSS styles to a specific section of text or to create a hook for JavaScript manipulation.
Syntax
The syntax for the <span>
element is as follows:
Example 1: Basic <span>
Usage
Output:
Example 2: Styling a <span>
Output:
Example 3: Nested <span>
Elements
Output:
Example 4: Inline Styling with <span>
Output:
Example 5: <span>
with JavaScript Manipulation
Output:
Example 6: <span>
for Accessibility
Output:
Example 7: Using <span>
for Highlighting Text
Output:
Example 8: <span>
for Inline Block Styling
Output:
Example 9: Using <span>
for Language Styling
Output:
Example 10: <span>
for Semantic Markup
Output:
In conclusion, the <span>
element in HTML is a versatile and powerful tool for styling and manipulating text within a document. It allows developers to target specific sections of text and apply custom styles or functionality without affecting the overall structure of the content. By understanding how to effectively use <span>
, web designers can create more visually appealing and accessible web pages.