
- HTML - Home
- HTML - Roadmap
- HTML - Introduction
- HTML - History & Evolution
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <span> Tag
Introduction to <span> Tag
The HTML <span> tag is an inline container for phrasing the text. It can be easily style using CSS and manipulated with JavaScript through class or id attributes.
The <span> tag shpu;d be used only when no other semantic element is suitable. Unlike the <div> tag, which is a block-level element, the <span> tag is an inline-level element. It is used for arguing and applying styles to inline elements.
Syntax
Following is the syntax of <span> tag −
<span>.....</span>
Attributes
The HTML <span> tag supports both Global and Event attributes.
Example: Creating <span> Elements
In the following program, we creating multiple spans using the HTML <span> tag to mark up parts of the text or content in an HTML document. This code creates a webpage with a heading and a paragraph, styling part of the text using the <span> tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML span tag</title> </head> <body> <h3>Tutorialspoint</h3> <!-- Creating span Element --> <p>Easy Simply Learning on <span>Tutorialspoint.</span></p> </body> </html>
Example: Styling <span> Element
Here is another example of the HTML <span> tag. We create multiple input fields for user input and use the <span> tag to mark up parts of the text or content for each input field. This HTML code creates a webpage with a heading and a paragraph, styling the text within the <span> tag in green and 24px font size.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML span tag</title> <style> span { color: green; font-size: 24px; } </style> </head> <body> <h3>Tutorialspoint</h3> <!-- Creating span Element --> <p>Easy Simply Learning on <span>Tutorialspoint.</span></p> </body> </html>
Example: Parsing <span> Elements
Let's consider the following example, where we run a script to parse content within the <span> tag. This HTML code creates a webpage with a paragraph and a button. Clicking the button displays an alert with the span's text.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML span Tag</title> <style> #txt { font-size: 30px; } </style> </head> <body> <!-- Create span Element--> <p>Simply Easy Learning<span id='txt'>Tutorialspoint</span></p> <button onclick="Show()">Show</button> <script> function Show() { let demo = document.getElementById('txt'); alert(demo.innerHTML); } </script> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
span | Yes | Yes | Yes | Yes | Yes |