Creative agency glossaryWeb, UX/UI, and Design

Srcset

Srcset is an HTML attribute that lists several versions of an image at different sizes or resolutions, so the browser can download the one best suited to the visitor's screen.

What is srcset?

Without srcset, an image tag points to one file, and every visitor downloads it, whether they are on a large high-resolution monitor or a small phone. With srcset, the tag offers a menu: the same image at, say, 480, 960, 1600 and 2400 pixels wide. A companion attribute, sizes, tells the browser how wide the image will be displayed at different screen widths. The browser combines that with the screen's size and pixel density and picks the smallest file that will still look sharp.

There are two ways to write it. Width descriptors, the w values, describe how wide each file is and suit images that change size with the layout. Density descriptors, 1x, 2x and 3x, suit images shown at a fixed size, such as a logo, and supply sharper versions for high-resolution screens. When the image itself needs to change, a different crop for phones for example, the picture element does that job, with srcset inside it.

Why it matters

Why srcset matters

Images are usually the heaviest part of a web page, and the main image is often the element that decides how fast a page feels. Serving a desktop-sized hero to a phone wastes data, slows loading and drags down Largest Contentful Paint, one of the Core Web Vitals that Google uses. Serving a small image to a large high-resolution screen makes the brand look blurry. Srcset fixes both at once, and it is one of the few performance improvements that also improves how a site looks.

In practice

How srcset works in practice

  1. 01

    Most of the work is automated. WordPress has generated srcset and sizes for uploaded images since 2015, creating several sizes on upload, and image CDNs and modern frameworks resize images on the fly. The decisions left to the team are which widths to generate, which formats to offer (WebP or AVIF alongside JPEG) and, most importantly, an accurate sizes attribute that matches how the layout actually displays each image.

  2. 02

    That last part is where sites go wrong, so it is checked. We look at the network panel on a phone and on a desktop to see which file each one actually downloaded, and fix the sizes value whenever the browser is fetching a bigger file than the layout needs. The main image near the top of the page is marked so the browser fetches it early, while images further down are lazy-loaded.

Watch out

What people get wrong about srcset

Leaving sizes off, or setting it to the full screen width, so the browser assumes every image fills the viewport and downloads files far larger than needed. Second, uploading a single small image and expecting srcset to create sharp large versions; it can only choose between files that exist. Third, confusing srcset with art direction. Srcset picks the same image at different sizes; if phones need a different crop, that is the picture element's job. And checking it once, at launch, when every new template and every new image size can quietly undo it.

Questions

People also ask

What is the difference between srcset and the picture element?

Srcset offers the same image at different sizes or resolutions and lets the browser choose. The picture element lets the designer specify different images for different conditions, such as a vertical crop on phones or a newer file format. They are often used together.

Does srcset help SEO?

Indirectly. It makes pages lighter and faster, especially on phones, which improves Core Web Vitals and the experience search engines measure. Google's own image guidelines recommend it, with a plain src kept as a fallback.

Does WordPress add srcset automatically?

Yes. Since version 4.4, WordPress creates several sizes of each uploaded image and adds srcset and sizes to images in content. The default sizes value is generic, so themes with unusual layouts should set their own.

Next to it in the glossary

  1. Secure Sockets Layer (SSL)Secure Sockets Layer (SSL) is the original encryption protocol for securing traffic between a browser and a website, since replaced by TLS, although its name lives on in SSL certificates.
  2. Shopify DevelopmentShopify development is the design, building and customization of online stores on the Shopify e-commerce platform, from theme design and custom features to integrations and performance work.
  3. Site MigrationA site migration is any major change to a website's address, platform, structure or hosting that can affect how search engines find and rank it, such as a new domain, a new CMS or a redesign.
  4. SubdomainA subdomain is a prefix added in front of a domain name, such as shop or blog in shop.example.com, that creates a separate section or site under the same domain.
  5. Top-Level DomainA top-level domain is the last part of a domain name, after the final dot, such as .com, .org, .uk or .nyc.
  6. Transport Layer Security (TLS)Transport Layer Security (TLS) is the encryption protocol that secures traffic between browsers and websites, the technology that puts the S in HTTPS.

Every Web, UX/UI, and Design term →

In the work

Where it shows up

All our creations →

From the journal

Read around it

The journal →

Talking the talk is one thing

We make the work.

RIOT is a creative agency and production studio in New York. Strategy, brand, film, photography, design and the campaigns that carry them, made by one team. A few lines is enough to start: we read every brief the same day.

    Footage