Image Performance & Inline SVG

Three HTML attributes control how the browser fetches and decodes images. Inline SVG gives you a shape that CSS can style; an `<img>` pointing at an SVG gives you a picture you cannot touch.

HTML6 min readConcept 20 of 42

What it is

HTML provides three attributes that tune image loading without any JavaScript. loading="lazy" defers the fetch until the image is close to the viewport. decoding="async" lets the browser decode the image off the main thread. fetchpriority="high" tells the browser to promote this image in the fetch queue, useful for the largest image on the page.

SVG is a special case: an SVG file brought in as inline markup becomes part of the DOM, so CSS can color its paths and JavaScript can animate them. The same SVG loaded via <img src="logo.svg"> is opaque, isolated from the page's styles, and treated just like a JPEG. Same file, two completely different capabilities.

Why it matters

The single biggest image performance mistake is putting loading="lazy" on the hero image. The browser discovers lazy images only when they are about to enter the viewport, which delays the fetch by the time it takes to parse and render everything above the fold. For the above-fold image, that delay hurts Largest Contentful Paint directly. Lazy loading is a win for images below the fold and a penalty for the one the user sees first.

Format choice quietly affects every page load. WebP images are typically 25-35% smaller than JPEG at equivalent quality. AVIF goes further but has older browser gaps. The <picture> element lets you offer the modern format to browsers that support it and fall back to JPEG for those that do not, without any JavaScript.

How it works

For the primary above-fold image, add fetchpriority="high" and omit loading. For every image below the fold, add loading="lazy". decoding="async" is safe to add to any image; it is a hint that lets the browser handle decode scheduling more flexibly. None of these attributes change what the image looks like, only when and how the browser fetches and processes it.

For format switching, use <picture> with <source> elements. List AVIF first, then WebP, then JPEG as the <img> fallback. The browser picks the first source whose type it supports: <source srcset="photo.avif" type="image/avif"> then <source srcset="photo.webp" type="image/webp"> then <img src="photo.jpg" alt="...">. You still need width, height, and alt on the <img> regardless of which format is served.

For inline SVG, paste the SVG markup directly into the HTML. Target shapes with CSS using class names or the SVG element selectors (circle, path, rect). If you only need the SVG as a static image and do not need to style it, <img src="icon.svg" alt="..."> is simpler and avoids bloating the HTML. The rule: use inline SVG when you need CSS or JS control, and <img> when you do not.

Try it

See a lazy image fade in as it enters the viewport, compare inline SVG vs <img> CSS control, and watch the <picture> source selection.

<!-- hero: prioritize -->
<img fetchpriority="high"
src="hero.jpg" alt="...">
<!-- below fold: lazy -->
<img loading="lazy"
src="card.jpg" alt="...">
<!-- inline SVG: styleable -->
<svg><circle class=
"icon-fill"/></svg>
<!-- picture: format fallback -->
<picture>
<source type="image/avif"
srcset="p.avif">
<img src="p.jpg" alt="...">
</picture>

loading attribute

high

Hero (above fold)

fetchpriority="high", no loading attr

LCP boost
lazy

Cards (below fold)

loading="lazy"

deferred
lazy

Hero (above fold)

loading="lazy" -- wrong!

LCP hurt

inline SVG vs img

inline SVG

CSS styleable

<img src=".svg">

CSS opaque

Hover the inline circle to recolor it. The `img` version is locked to grey.

<picture> source ladder

AVIFif supported
WebPelse if supported
JPEGalways (fallback)

Prioritize the hero, lazy-load the rest, inline SVG for style control.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1The hero image at the top of a landing page is the largest element on screen. Which attributes should it have?
  2. 2You need to change an icon's color on hover using CSS. Should you use inline SVG or <img src="icon.svg">?
  3. 3You have photo.avif, photo.webp, and photo.jpg. How do you offer all three with automatic fallback?

Remember this

  • Never use loading="lazy" on the above-fold hero; use fetchpriority="high" instead.
  • loading="lazy" defers below-fold image fetches; decoding="async" frees the main thread during decode.
  • Inline SVG is part of the DOM and styleable with CSS; <img src=".svg"> is opaque to stylesheets.
  • Use <picture> with ordered <source type="..."> elements to serve AVIF or WebP with a JPEG fallback.

Done with this concept?

Mark it complete to track your progress. No login needed.