CKTIS / HTML
src — resource address
The `src` attribute specifies the URL of a resource used by an HTML element, such as an image, script, or recording. It is not a global attribute: its applicability, requirement, and loading behavior depend on the element.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
src="URL"src supplies a resource address, not its contents or alternative text. A supplied value must be a valid, non-empty URL; surrounding spaces are allowed. A relative address is resolved against the document's base URL. Do not use src="" as a substitute for omitting the attribute.
On img, it identifies an image; at least one of src and srcset is required. Responsive selection through srcset or picture can cause a different image to be used. alt supplies alternative text, not an address. On input, src applies only to type="image" and is required in that state. On iframe, it identifies a page, but a present srcdoc takes priority; on embed, it identifies the embedded resource.
On audio and video, it identifies the recording. Specify alternative resources with source elements, omitting src on the parent. Each such source requires src. In contrast, a source inside picture must use srcset and must not have src. On track, the required src identifies text track data, such as subtitles. Merely changing source.src inside an existing media element does not switch playback; changing src on audio or video invokes the loading algorithm.
On script, src fetches code instead of using the element's child text. It is allowed only for classic scripts and JavaScript modules, not import maps or data blocks. Do not treat text inside a script with src as fallback code. The example uses a self-contained SVG image in a data: URL, so no separate image file is needed.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>src example</title>
</head>
<body>
<img
src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='80'%20height='80'%3E%3Crect%20width='80'%20height='80'%20fill='blue'/%3E%3C/svg%3E"
alt="Blue square"
width="80"
height="80">
</body>
</html>Result
An 80 × 80 CSS-pixel blue square.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.
Sources
- HTML Standard — The img element
- HTML Standard — The source element
- HTML Standard — The embed element
- HTML Standard — The iframe element
- HTML Standard — Image Button state
- HTML Standard — Location of the media resource
- HTML Standard — The track element
- HTML Standard — The audio element
- HTML Standard — The video element
- HTML Standard — The script element