The src attribute specifies the URL of an external resource an element should load. You will see it most often on <img>, <script>, <iframe>, <audio>, and <video>.
The value is a valid URL string — absolute (https://…) or relative (/images/photo.jpg). Not the same as srcset (responsive candidates) or srcdoc (inline iframe HTML).
Baseline · Widely available.
Not deprecated. Core HTML attribute on media and embedding elements across all browsers.
Empty or broken URLs fail silently for users.
Always verify the path. For images, pair src with meaningful alt text.
Syntax
HTML Syntax
syntax.html
<element src="url">
For <img>, MDN: at least one of src or srcset is required. When both exist with width descriptors, supporting browsers use srcset/sizes and keep src as a fallback.
defer (when used) runs after HTML is parsed, in order.
Empty body — when src is set, do not put code inside the same classic script tag.
Study tip — the try-it demo uses a data URL so it works without a separate .js file.
Example 3 — Audio and Video
Point media elements at a file with src (or nest <source> children).
HTML
<audio src="/audio/count.mp3" controls>
Your browser does not support audio.
</audio>
<video src="/video/count.mp4" controls width="320">
Your browser does not support video.
</video>
Fallback text inside the tags helps when media is unsupported.
Multiple formats? Prefer nested <source> elements instead of one src.
Edge Cases & Pitfalls
Most src bugs are wrong paths or mixing it up with similar attributes.
path
Relative paths depend on the page URL
photo.jpg resolves from the current document folder. Prefer clear root-relative paths when unsure.
vs
src ≠ srcset ≠ srcdoc
srcset = candidates; srcdoc = iframe HTML string; src = one resource URL.
script
Do not mix src and inline classic code
If a classic <script> has src, put the code in that file — not inside the tag.
img
Always provide alt for images
Broken src still needs accessible alt. Decorative images can use empty alt="".
cors
Cross-origin rules still apply
Scripts, modules, and some media from other origins may need CORS headers to work fully.
Compatibility
Browser Support
src is a core HTML attribute for loading external resources on media and embedding elements.
✓ Baseline · Widely available
src
Supported everywhere for img, script, iframe, audio, video, and related elements.
100%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Full support
srcUniversal
Bottom line: Universal. Focus on correct URLs, accessibility (alt), and the right sibling attributes (srcset, srcdoc) for each use case.
Remember
Key Takeaways
Role: URL of the resource to load.
Elements: img, script, iframe, audio, video, and more.
Paths: absolute or relative — check resolution carefully.
Siblings: use srcset / srcdoc when those jobs fit better.
One line:src is “where is the file?” for images, scripts, and media.
Frequently Asked Questions
src sets the URL of the external resource an element should load — for example an image file, a JavaScript file, a media file, or a framed page.
Commonly img, script, iframe, audio, video, embed, and track. source and input type=image can also use src. Always check the element’s MDN page for exact rules.
No. src is a single URL (or fallback). srcset lists multiple image candidates with width or density descriptors for responsive selection.
No. srcdoc embeds HTML content directly inside an iframe. src loads a document from a URL.
Yes. Relative URLs resolve against the document (or base) URL. Absolute URLs include a scheme such as https:.
The resource fails to load. For img, provide meaningful alt text. Empty or broken src URLs are a common cause of missing media.