Poradnik: Responsive Images (srcset)

How to serve responsive images z the srcset i sizes atrybuty i the picture element, gdy to używać każdy, i how responsive images fix LCP i CLS bez będąc a bezpośredni ranking signal.

Opublikowano po raz pierwszy: 2 lip 2026 · Ostatnia aktualizacja: 3 sie 2026 · Advanced
Języki

Responsive images let the przeglądarka (via srcset + sizes) lub the author (via <picture>) serve the right-sized image per urządzenie. srcset/sizes jest resolution switching (same image, przeglądarka picks — a suggestion); <picture> jest art direction lub format switching (author-dictated crops/formaty — a command). najbardziej witryny tylko need srcset/sizes. ten jest nie a bezpośredni ranking signal i it doesn't change co Google indexes — Google indexes the src URL — ale it's the concrete fix Lighthouse recommends dla oversized images (jego "Properly size images" audit fails at a 4KiB gap) i, paired z explicit width/height, it's how you zapobiegać CLS. zachować tekst alternatywny identical i image URLs stable w całym breakpoints dla mobilny-pierwszy indeksowanie. I reuse the dokładny srcset + width/height pattern z my Ahrefs CLS artykuł. Nests poniżej the Image SEO hub.

TL;DR — Two jobs, one syntax family. srcset/sizes on <img> = resolution switching (same image, przeglądarka picks best-fit — a suggestion); <picture> = art direction lub format switching (author-dictated crops/formaty — a command). najbardziej witryny tylko need the pierwszy. Responsive images są nie a bezpośredni ranking signal i don’t change co Google indexes — Google indexes the src URL, so zachować alt tekst, filenames, i image URLs stable w całym breakpoints (mobilny-pierwszy indeksowanie). The rzeczywisty payoff jest Core Web Vitals: right-sizing images jest the fix behind Lighthouse’s “Properly size images” audit (fails at a 4KiB gap), i width/height (lub aspect-ratio) — nie srcset — jest co zapobiega CLS. Don’t lazy-load the LCP image. I reuse the dokładny srcset + width/height pattern z my Ahrefs CLS piece.

Evidence for this claim The HTML responsive-image features srcset, sizes, and picture let browsers select an appropriate image candidate. Scope: Current HTML responsive image behavior. Confidence: high · Verified: WHATWG HTML: Responsive images Evidence for this claim Google can process responsive images and recommends src as a fallback while using srcset or picture for responsive delivery. Scope: Current Google Images responsive-image guidance. Confidence: high · Verified: Google Search Central: Responsive images

Two różny jobs, one syntax family

Everything in ten topic collapses do two mechanisms, i half the confusion out there comes z mixing them up:

  1. Resolution switching — the same image at różny sizes lub pixel densities. You give the przeglądarka a menu z srcset i sizes on the <img>, i the przeglądarka decides który file to fetch na podstawie the viewport i screen density. ten jest the common case.
  2. Art direction — a genuinely różny image per condition: a wide crop on komputer stacjonarny, a tight vertical crop on mobilny, lub a różny file format entirely. Here you dictate the choice z the <picture> element.

The web.dev Learn: Responsive images course frames the difference exactly right: z srcset the przeglądarka gets suggestions, whereas “the picture element gives commands.” i the scope-setting wiersz worth tattooing on the wall, również z web.dev: “You probably won’t need to użyj picture element dla najbardziej of twój responsive images — the srcset i sizes atrybuty on the img element cover a lot of używać cases.” Reach dla <picture> tylko gdy you actually need a różny image, nie a różny size of the same one.

srcset i sizes — resolution switching

w-descriptors vs. x-descriptors

srcset takes a comma-separated lista of candidate files, każdy tagged z a descriptor. There są two kinds:

  • Width descriptors (w) — you state każdy file’s intrinsic pixel width (puppy-2000.jpg 2000w). The przeglądarka combines że z twój sizes wartość to działać out który file best fits the space i the urządzenie’s pixel density. ten jest the flexible option i co you’ll używać najbardziej of the time.
  • Pixel-density descriptors (x) — you state który file jest dla który urządzenie pixel ratio (logo.png 1x, logo@2x.png 2x). używać te dla fixed-size images (an avatar, a logo) gdzie the displayed size nigdy changes; you don’t need sizes z x descriptors.

reguła of thumb: fluid, treść-width images → w descriptors + sizes; fixed-size UI images → x descriptors.

Why sizes matters (i co happens if you skip it)

z w descriptors, sizes isn’t optional cosmetics — it’s how the przeglądarka knows how big the image będzie render so it może choose przed layout. Per web.dev, sizes “tells the przeglądarka co size you expect the image to być displayed at poniżej różny conditions,” as a comma-separated lista of media conditions i widths:

sizes="(max-width: 600px) 480px, 1000px"

Read it as: “if the viewport jest 600px lub narrower, the image będzie być o 480px wide; otherwise, o 1000px.” Omit sizes i the przeglądarka assumes the image fills the pełny viewport width (100vw) — so on a wide screen it może pull twój largest file dla an image że’s actually renderowanie at 400px, quietly defeating the whole point. Missing sizes jest the single najbardziej common srcset mistake.

Don’t guess at tamte width wartości z the layout in twój head — sprawdź image’s rzeczywisty wyrenderowany CSS width in the przeglądarka (DevTools → elementy → the computed width of the <img> box) at każdy breakpoint you care o, i ustawić sizes to match. A sizes wartość że doesn’t match the rzeczywisty wyrenderowany width nadal causes the przeglądarka to select the błędny candidate even though the znaczniki jest syntactically poprawny — syntax walidacja alone won’t catch że; see the currentSrc sprawdzenie below to confirm co actually załadowany.

Worked przykład (my reusable pattern)

ten jest the dokładny pattern z my Ahrefs piece, co jest Cumulative Layout Shift (CLS) & How To poprawić It, expanded z sizes:

<img
  src="puppy-1000.jpg"
  srcset="puppy-1000.jpg 1000w,
          puppy-2000.jpg 2000w,
          puppy-3000.jpg 3000w"
  sizes="(max-width: 600px) 480px, 1000px"
  width="1000" height="1000"
  alt="Puppy with balloons" />

każdy piece jest load-bearing: src jest the fallback i the URL Google indexes; srcset listy the candidates z w descriptors; sizes tells the przeglądarka the wyrenderowany width; width/height reserve space (the CLS fix — więcej below); alt stays identical no matter który file loads.

The picture element — art direction i format switching

gdy you actually need it

używać <picture> dla two things srcset może’t robić:

  1. Art direction — a różny crop per breakpoint. web.dev’s przykład: on a narrow phone you może serve a tall, tight crop; on a wide komputer stacjonarny, a short, wide one. Same subject, deliberately różny framing.
  2. format switching — oferta AVIF/WebP z a JPEG fallback via <source type="…">, letting the przeglądarka take the pierwszy format it obsługuje. ten ties straight back to the format guidance on the Image SEO hub.

The syntax (i the fallback reguła)

The <picture> element wraps one lub więcej <source> elementy i zawsze ends z a plain <img>:

<!-- Art direction: different crop per breakpoint -->
<picture>
  <source media="(max-width: 600px)" srcset="hero-crop-mobile.jpg">
  <img src="hero-crop-desktop.jpg" width="1200" height="675"
       alt="Product hero shot">
</picture>

<!-- Format switching: modern format with a fallback -->
<picture>
  <source type="image/avif" srcset="hero.avif">
  <source type="image/webp" srcset="hero.webp">
  <img src="hero.jpg" width="1200" height="675" alt="Product hero shot">
</picture>

że trailing <img src> jest nie optional. Google states it directly: per sekcja 4.8.1 of the HTML standard, “upewnij się że you zapewniać an img element as a fallback z a src atrybut gdy używając the picture element.” It’s the file older przeglądarki i crawlers fall back to — i, again, the one Google indexes.

robi srcset pomagać SEO? bezpośredni vs. indirect

Here’s the framing każdy competing poradnik fumbles, so I’ll być blunt.

Directly: no. Responsive-image znaczniki jest nie a ranking signal the way tekst alternatywny lub filenames są dla image search. Adding srcset doesn’t lift twój positions, i it doesn’t change co appears in Google Images. Google indexes the image referenced in src; the srcset/<picture> warianty są a delivery mechanism, nie osobno indeksowalny assets. zachować twój alt tekst, filename, i dane strukturalne attached to że primary src image.

Indirectly: yes, i it’s one of the biggest levers you mieć. Right-sized images są the najbardziej effective concrete fix dla two Core Web Vitals — LCP i CLS — który feed Google’s strona-experience signals. że’s the whole payoff. It’s the same shape as the WebP/AVIF story on the Image SEO hub: no boost dla the format itself, the win jest speed.

Responsive images i LCP

Oversized images są one of the najbardziej common causes of a slow Largest Contentful Paint, i responsive images są Lighthouse’s recommended fix. The Lighthouse “Properly size images” audit listy “wszystkie images in twój strona że aren’t appropriately sized, along z the potential savings” — anything bigger than it needs to be “just wyniki in wasted bytes i slows down strona load time.” Its fix, verbatim: “z responsive images, you generate multiple versions of każdy image, i then określać który version to używać in twój HTML lub CSS używając media zapytania, viewport dimensions, i so on.”

Two specifics worth knowing:

  • The awaria threshold jest 4KiB. Lighthouse tylko flags an image gdy “the wyrenderowany size jest co najmniej 4KiB smaller than the rzeczywisty size.” mały overshoots don’t count; serving a 3000px file do a 400px slot robi.
  • A tooling shortcut. Google recommends RespImageLint, “a pomocny bookmarklet dla identifying the optimal srcset i sizes wartości dla twój images.” Run it przed you hand-calculate breakpoints.

Don’t lazy-load the LCP image

ten jest the reguła people break najbardziej. srcset on twój hero jest fine — ale nigdy pair it z lazy ładowanie on the LCP element. The largest above-the-fold image powinien load eagerly z fetchpriority="high", exactly as the Image SEO hub covers. i gdy you build a responsive <picture> hero, zachowaj swap logic native: Google warns że it “won’t load content that requires user interactions” like swiping lub clicking, so a JS scheme że tylko loads the rzeczywisty image po interaction hides it z Google.

Responsive images i CLS

Here’s the trap: srcset alone robi nothing dla layout shift. Resolution switching decides który file loads; it doesn’t reserve space dla it. Left bez dimensions, per web.dev’s Optimize CLS poradnik, “as images load, text shifts down the page to make room for them” — ponieważ the space “może’t być allocated dla it until the przeglądarka starts to download it i może determine jego dimensions.”

The fix jest explicit dimensions, i it composes z responsive znaczniki:

  • ustawić width i height atrybuty on the <img>. Modern przeglądarki “ustawić the domyślny aspect ratio of images na podstawie an image’s width i height atrybuty,” so tamte two liczby reserve the right box przed dowolny srcset wariant downloads. (web.dev)
  • Pair them z height: auto in CSS dla fluid containers. ten jest the part że looks contradictory ale isn’t: web.dev’s own guidance jest to “używać CSS to resize the image to the width of the container” and “ustawić height: auto; to avoid używając a fixed wartość dla the image height.” The HTML atrybuty ustawić the intrinsic aspect ratio; the CSS lets the image scale fluidly. Together they zapobiegać CLS i stay responsive.
  • lub używać CSS aspect-ratio to reserve the space gdy you może’t ustawić atrybuty.

który kills a persistent myth: width/height atrybuty don’t break fluid layouts. atrybuty + height: auto jest the poprawny combo, nie a conflict. I walk przez the pełny layout-shift mechanics in my Ahrefs CLS artykuł; the short version jest “reserve the space so that there’s no shift” i let the image fill it.

mobilny-pierwszy indeksowanie implications

Google indexes primarily the mobilny version of twój strony, so two reguły matter więcej than they używany to gdy you’re serving responsive warianty:

Google’s own summary of why to bother jest plain: “designing responsive strony internetowe leads to better doświadczenie użytkownika, since people może access them w całym a plethora of urządzenie types.”

co o Bing?

There’s no Bing-specific guidance on srcset, sizes, lub the <picture> element — Bing’s public documentation doesn’t address responsive-image znaczniki at wszystkie. So don’t justify responsive images z a Bing algorithm hook; the case jest wydajność i UX, który Bing (like Google) treats as strona-experience quality zamiast something you może point at a udokumentowany responsive-images reguła dla.

częste błędy

  • Forgetting sizes z w descriptors — the przeglądarka assumes 100vw i może fetch twój biggest file dla a mały slot.
  • Dropping the fallback src on <picture> — a spec violation Google explicitly flags, i it’s the URL crawlers index.
  • Mismatched width/height ratio vs. the actually-served image — nadal causes shift.
  • Lazy-ładowanie the LCP hero — opóźnienia LCP dla no powód; load it eagerly z fetchpriority="high".
  • Regenerating image URLs per żądanie — breaks Google’s buforowanie i the mobilny-pierwszy “stable URL” reguła.
  • Reaching dla <picture> gdy srcset/sizes by robić — unnecessary complexity; web.dev says najbardziej witryny don’t need it.

gdzie ten sits

ten jest the sizing-i-delivery deep dive poniżej the broader Image SEO hub — the wydajność half of image SEO, parallel to how the tekst alternatywny poradnik handles the image-search half. dla the layout-shift mechanics in pełny, see my Ahrefs CLS artykuł; dla LCP, fetchpriority, i the ładowanie strategy, że’s Core Web Vitals działać wearing an image hat.

Add an expert note

Pin an expert quote

New person? Create their unclaimed profile at /admin/experts/ → Pin a quote first.