Skip to content
HTML·Advanced·Conceptual·1 min read

Can a CSS background-image be lazily loaded the same way as an img?

Short interview answer

Not with the loading attribute, since that only applies to img and iframe. A CSS background image is fetched as soon as the browser determines the rule applies to a rendered element, so deferring it needs a different technique, such as swapping the background via JavaScript once the element nears the viewport.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Images, media, and responsive assets

Related questions