👀 Live Preview
Audio player with multiple source formats:

The <source> tag provides multiple media resources inside audio, video, and picture elements. This guide covers syntax, attributes, fallback content, and best practices for beginners.
src attribute.
type hint.
Nested use.
MP3, WebM.
Backup text.
Responsive.
<source> Tag?The <source> tag specifies different media resources for browsers to choose from, ensuring compatibility and an optimal user experience. It is commonly nested within <audio> and <video> to offer alternative formats, and inside <picture> for responsive images.
source has no closing content and no visible output on its own. It only works as a child of audio, video, or picture.
The browser tries each source in order until it finds a format it can play or display.
Place source inside audio or video, with src and type attributes:
<video controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.webm" type="video/webm">
Your browser does not support the video tag.
</video>source is a void element — use <source ...> without inner content.type so browsers skip unsupported MIME types quickly.source elements inside the parent.| Topic | Code Snippet | Notes |
|---|---|---|
| Video source | src="file.mp4" type="video/mp4" | Inside video |
| Audio source | src="file.mp3" type="audio/mpeg" | Inside audio |
| Picture source | srcset="img.webp" type="image/webp" | Inside picture |
| Media query | media="(min-width: 800px)" | On picture source |
| Parent elements | audio, video, picture | Required |
| Browser support | Modern + IE 9+ | Wide support |
<source> vs src on Parent| Approach | When to use | Example |
|---|---|---|
src on audio/video | Single file only | <audio src="song.mp3"> |
Multiple source | Cross-browser format fallback | MP3 + Ogg + WebM |
| Rule of thumb | Use source when you need more than one format | |
The <source> tag supports attributes such as src and type that help browsers select a compatible media resource.
src Required*URL of the media file for audio and video sources.
src="/audio/count.mp3"type RecommendedMIME type (e.g. video/mp4, audio/mpeg) so browsers skip unsupported formats.
type="audio/mpeg"srcset pictureImage URL(s) when source is inside a picture element.
srcset="hero.webp"media pictureMedia query condition for responsive image sources.
media="(min-width: 768px)"* Use srcset instead of src for picture sources.
Offer multiple formats and fallback messages with source inside media elements.
Audio player with multiple source formats:
Use <source> to list alternative media files and provide fallback text when nothing can play.
By including multiple source elements within audio or video, you accommodate various formats for playback across different browsers:
<audio controls>
<source src="/audio/count.mp3" type="audio/mpeg">
<source src="/audio/count.ogg" type="audio/ogg">
Your browser does not support the audio tag.
</audio>The content within video or audio after all source elements serves as fallback when none of the specified sources are supported:
<video controls>
<source src="/video/count.mp4" type="video/mp4">
<source src="/video/count.webm" type="video/webm">
Fallback content if the browser does not support any of the sources.
</video>track elements for subtitles (see the video tag).controls.Multiple source elements are nested inside audio or video.
Each type and file is checked until one is playable.
If no source works, inner fallback text is displayed instead.
Users get the best format their browser supports without extra JavaScript.
The <source> tag is supported in all modern browsers. Internet Explorer 9+ supports source inside audio and video with format limitations.
All modern browsers support <source> for audio, video, and picture elements.
Bottom line: Use multiple <source> elements for reliable cross-browser media playback.
Mastering the <source> tag is key to delivering high-quality multimedia content on the web. By providing multiple sources and understanding browser compatibility, you ensure a seamless experience for users across various platforms.
source elements for broader compatibilitytype MIME typesaudio or videosource outside audio, video, or picturetype attribute on large media files<source>Bookmark these before you embed media.
src attribute.
Coretype hint.
AttributesParent tags.
UsageMP3 + WebM.
PatternBackup text.
ResilienceWide support.
Compatibilityaudio, video, or picture so browsers pick a supported format.audio, video, or picture. It cannot be used alone.audio or video after all source elements, shown when no source works.source with some codec limitations.Practice <source> with audio and video formats in the Try It editor.
6 people found this page helpful