The <source> element lists one alternate media or image resource for <video>, <audio>, or <picture>. The browser walks the list and uses the first option it can play or display.
Inside media elements, put sources before any <track> or fallback text. Inside <picture>, put sources before the required <img> (which also carries alt).
Baseline · Widely available.
Not deprecated. Stable across modern browsers since about July 2015.
Void element.
Do not write a closing </source>. Attributes also differ by parent: src for audio/video; srcset for picture.
Syntax
HTML Syntax
syntax.html
<source src="url" type="mime">
Start tag only. For <picture>, use srcset (not src) on each <source>.
Reference
Attributes
Element-specific attributes (allowed set depends on the parent):
List <source> children with src + type, preferred format first.
Browser skips unsupported types without downloading when type is set.
Add fallback text/links for environments that cannot play video at all.
Example 2 — Multiple Audio Formats
Same pattern for sound: MP3 plus Ogg for broader support.
HTML
<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 element.
<a href="/audio/count.mp3">Download MP3</a>.
</audio>
Put modern formats first with matching type (e.g. image/webp).
Optional width/height on picture sources help reserve layout space.
Keep a widely supported fallback on <img src>.
Write alt once on that <img>, not on <source>.
Edge Cases & Pitfalls
Most bugs mix audio/video attributes with picture rules, or forget fallbacks.
parent
src vs srcset
Audio/video need src. Picture needs srcset. Mixing them is invalid for that parent.
order
Sources before tracks / img
In media elements, place <source> before <track> and fallback text. In picture, sources come before <img>.
type
Always set MIME when you can
Without type, browsers may download a file only to discover they cannot play it.
a11y
alt lives on img
<source> has no alt. For captions on video, use <track>.
void
No closing tag
Writing </source> is incorrect HTML. Treat it like <img> or <br>.
Compatibility
Browser Support
The <source> element is core HTML5 media/image markup in every major browser. Playable formats still vary by codec.
✓ Baseline · Widely available
<source>
Widely available since about July 2015. Nesting source in video, audio, and picture is supported across Chrome, Firefox, Safari, Edge, and Opera. Offer multiple formats for widest playback.
98%Element support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+ (media); picture later
Partial
<source>Widely supported
Bottom line: Safe to use everywhere. Always provide fallbacks (extra formats, nested img, or download links) because codecs differ.
Remember
Key Takeaways
Role:<source> lists alternate resources for video, audio, or picture.
Fallback: first usable source wins; always keep img or text fallbacks.
One line: nest ordered <source> alternatives so browsers can pick a format or image that works.
UA style
Default CSS Settings
source is not rendered on its own. Typical user-agent idea:
default.css
source {
display: none;
}
Visible UI comes from the parent video, audio, or the nested img inside picture.
Frequently Asked Questions
The source element lists alternate media or image resources for video, audio, or picture. The browser picks the first option it can use, then falls back to later sources or nested fallback content.
Yes. source has no content and must not have a closing tag. Write <source …> (or self-close as <source … /> in XHTML-style markup).
Use src (required) and usually type (MIME). Optional media can choose a file by viewport. Do not use srcset or sizes on source inside audio or video.
Use srcset (required). Add media and/or type as needed, and sizes when using width descriptors. Do not put src on source inside picture — the fallback URL belongs on the nested img.
With type, the browser can skip unsupported formats without downloading the file. List preferred formats first (for example WebM then MP4).
For picture, the nested img is used. For audio/video, the browser shows the fallback content between the parent’s tags (or an error state in the controls).