- 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 - <source> tag
Introduction to <source> Tag
The HTML <source> tag is an empty element, meaning it has no closing tag or content. It is used to define various media resources in different formats, such as audio, video, and images, ensuring optimal cross-browser compatibility.
The browser can select a supported format and play music and video files without issues. In a single document, the <source> element can be used multiple times to specify alternative audio, video, and image files in various format.
If the <source> tag is part of the <audio> or <video> tags, it should be placed before the <track> tag and after the media files. If it is within a <picture> tag, it must come before the <img> tag.
Syntax
Following is the syntax of the <source> tag −
<source src=" " type=" ">
Attributes
The HTML <source> tag supports Global and Event attributes, along with some specific attributes listed bellow.
| Attribute | Value | Description |
|---|---|---|
| media | media_query | Specify the type of media resource. |
| sizes | Specifies picture sizes when used in the <picture< element. | |
| src | URL | Specify the URL of the media file. |
| srcset | URL | Specify the URL of the media file when used in the <picture< element. |
| type | MIME-type | Specifies the media type of the resource. |
| height | pixel | Specifies the height of the media when used in the <picture< element. |
| width | pixel | Specifies the width of the media when used in the <picture< element. |
Example: <source> Tag on Video Element
In the following example, we use the <source> tag within the <video> element to play a video. This HTML code creates a video player with specifies dimensions, using a source URL for an MP4 video file.
<!DOCTYPE html>
<html>
<body>
<video width="250" height="150" controls>
<source src=
"https://player.vimeo.com/external/415068616.hd.mp4?s=e6dc106b7cccb956aa1d00d705e440977290df18&profile_id=174&oauth2_token_id=57447761.mp4"
type="video/mp4">
</video>
</body>
</html>
Example: <source> Tag on Audio Element
In another scenario, we use the <source> tag within the <audio> element to play audio. This HTML code creates an audio player with controls, suing a source URL for an MP3 audio file.
<!DOCTYPE html>
<html>
<body style="background-color:#D5F5E3">
<audio controls>
<source src=
"https://samplelib.com/lib/preview/mp3/sample-3s.mp3"
type="audio/mpeg">
</audio>
</body>
</html>
Example: <source> Tag on Picture Element
Lets consider another example where we use the <source> tag within <picture> to load different images based on the viewport width. When the user minimizes the window, the initially displayed image changes to another image.
<!DOCTYPE html>
<html>
<body>
<p>When You minimize the window it loads different image on the webpage.</p>
<picture>
<source media="(min-width:651px)"
srcset="https://www.tutorialspoint.com/sql/images/sql-mini-logo.jpg">
<source media="(min-width:464px)"
srcset="https://www.tutorialspoint.com/html/images/html-mini-logo.jpg">
<img src=
"https://www.tutorialspoint.com/sql/images/sql-mini-logo.jpg"
alt="Flowers" style="width:auto;">
</picture>
</body>
</html>
Supported Browsers
| Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| source | Yes 4.0 | Yes 9.0 | Yes 3.5 | Yes 4.0 | Yes 10.5 |




