- HTML Tutorial
- HTML - Home
- HTML - Introduction
- 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 - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- 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
- HTML - HEX
- HTML - HSL
- 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 - 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 - 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
HTML <span> tag is an inline container for phrasing the text. We can easily style the span tag using CSS and it is easily manipulated with JavaScript using the class or id attributes.
It should be used only when no other semantic element is suitable. The <span> tag is different from the <div> tag, the <div> tag is a block-level element, whereas the <span> is an inline-level element. It is used to grouping and applying styles to inline elements.
Syntax
<span>.....</span>
Attribute
HTML span tag supports Global and Event attributes of HTML.
Examples of HTML span Tag
Bellow examples will illustrate the usage of span tag. Where, when and how to use span tag to mark up a part of the text.
Creating span Element
In the following program, we are creating multiple spans using the HTML <span> tag to mark up the part text or content in an HTML.
<!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>
Styling the span Element
Following is another example of the HTML <span> tag. Here, we are creating multiple input fields to take user input and using the <span> tag to markup a part of text or content for each input field.
<!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>
Parsing span Elements
Let's look at the following example, where we are going to run the script for parsing content used in the <span> tag.
<!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 |
To Continue Learning Please Login
Login with Google