CKTIS / HTML
loading — deferring resource loading
The loading attribute controls whether resource loading can be deferred based on an element's position relative to the viewport. It accepts lazy or eager; omission and invalid values mean eager. The standard defines it for img, iframe, audio, and video.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
loading="eager" | loading="lazy"loading is an enumerated attribute, not a boolean or global attribute. On img, iframe, audio, and video, lazy defers fetching until position-related conditions are met. eager disables this deferral; it does not guarantee completed loading or high priority. Omitting the attribute, using the empty value loading="", or supplying an invalid value such as loading="false" selects the eager state.
With lazy, the browser can begin fetching before the element enters the viewport. The triggering margin is implementation-defined, so do not assume a particular distance or time. When scripting is disabled, this mechanism does not defer loading, as an anti-scroll-tracking measure. However, no JavaScript code is required simply to use the attribute.
For media, lazy takes precedence over preload: it first defers fetching, and the preload rules still apply after loading resumes. It also defers starting playback through autoplay and fetching a video element's poster image. An audio element without controls is not displayed, preventing it from lazy loading. Inclusion of these features in the standard does not establish support in every browser.
The DOM property element.loading reflects the attribute, returning known values; an invalid value yields eager. Changing the state to eager resumes pending loading. The example prints the property values for the valid settings lazy and eager. After setting loading="invalid", it only compares image.loading with the raw attribute value returned by image.getAttribute('loading'). The result false shows that the two values differ; it does not confirm that the property returned eager. The example does not measure when the image is fetched. Supply width and height for images to reserve layout space.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Image loading attribute</title>
</head>
<body>
<img id="sample" loading="lazy" width="80" height="40" alt="Blue rectangle" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40'%3E%3Crect width='80' height='40' fill='blue'/%3E%3C/svg%3E">
<pre id="result"></pre>
<script>
const image = document.getElementById('sample');
const lazy = image.loading;
image.setAttribute('loading', 'eager');
const eager = image.loading;
image.setAttribute('loading', 'invalid');
const preservesInvalidToken = image.loading === image.getAttribute('loading');
document.getElementById('result').textContent = [
`Initial loading property: ${lazy}`,
`After setting loading="eager": ${eager}`,
`Invalid token preserved by the property: ${preservesInvalidToken}`
].join('\n');
</script>
</body>
</html>Result
Initial loading property: lazy After setting loading="eager": eager Invalid token preserved by the property: false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.