{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-srcset-5e25d6e7912f","title":"Implement srcset for Responsive Images","summary":"Add `srcset` with width descriptors to images wider than 100px, pair with `sizes` attribute, and use `src` as a fallback for optimal responsive image loading.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-srcset-5e25d6e7912f","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-srcset-5e25d6e7912f","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-srcset-5e25d6e7912f.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-srcset-5e25d6e7912f\/download","category":{"slug":"content-editorial","name":"Content & Editorial"},"editor_note":"Ensure the `sizes` attribute is always included when using width descriptors (`400w`, `800w`). Generate multiple width variants (e.g., 400w, 800w, 1200w) for images wider than 100px and specify the fallback image in `src`.","instructions":"---\nname: srcset\ndescription: \"Use when reviewing image assets, markup, and CDN or build transforms related to Use srcset for responsive images. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.\"\nmetadata:\n  category: images\n  priority: high\n  difficulty: intermediate\n  estimatedTime: \"15\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/images\/srcset\n---\n\n# Use srcset for responsive images\n\nWithout `srcset`, every user\u2014regardless of their device\u2014downloads the same large image. A 1600px hero image served to a 375px mobile display downloads 4x the data needed. The `srcset` attribute lets browsers choose the optimal file automatically, reducing bandwidth by 50-80% for mobile users with no change to visual quality.\n\n## Quick Reference\n\n- Add `srcset` with width descriptors (`400w`, `800w`) to all images wider than ~100px\n- Always pair `srcset` width descriptors with a `sizes` attribute\u2014without `sizes` the browser assumes `100vw`\n- Use density descriptors (`1x`, `2x`) only for fixed-size images like avatars and icons\n- Keep `src` pointing to a fallback size for browsers that don't support `srcset`\n\n## Check\n\nScan all <img> elements in this codebase. Flag: 1) Any <img> wider than 100px (in CSS or layout) that lacks a srcset attribute. 2) Any <img> with srcset but missing a sizes attribute (necessary for width descriptors). 3) Any <img> using only density descriptors (1x, 2x) where width descriptors (400w, 800w) would be more appropriate. 4) Any srcset that provides only one size (no benefit over plain src). Report each finding with file path and line number.\n\n## Fix\n\nFor each <img> missing srcset: 1) Generate multiple width variants: typically 400w, 800w, 1200w (add 1600w for full-bleed images). 2) Add srcset listing each variant with its width descriptor. 3) Add a sizes attribute describing actual CSS layout width at each breakpoint. 4) Keep src pointing to a mid-range size (800w) as the fallback. 5) Add width and height attributes if missing. For each image, show the complete corrected HTML including srcset and sizes.\n\n## Explain\n\nExplain how srcset and the two descriptor types work. Width descriptors (400w, 800w) describe the intrinsic width of each candidate; the browser combines this with the sizes attribute to calculate which candidate provides the best pixel density for the current viewport. Density descriptors (1x, 2x) are simpler but less flexible\u2014use them only for fixed-size images like avatars and icons. The sizes attribute is critical: without it, the browser assumes 100vw and always downloads the largest candidate even on narrow screens.\n\n## Code Review\n\nReview image assets, markup, and delivery configuration related to Use srcset for responsive images. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/images\/srcset\n","use_cases":["Add `srcset` with width descriptors (`400w`, `800w`) to all images wider than 100px.","Ensure `sizes` attribute is included when using width descriptors to avoid incorrect image selection.","Use `src` as a fallback for browsers that do not support `srcset`."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/srcset\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T05:45:09.000000Z","updated_at":"2026-11-24T07:12:32.000000Z","seo_title":"Implement srcset for responsive images optimization","seo_description":"Use srcset to serve optimal image sizes for responsive design, improving performance and user experience.","seo_keywords":["srcset responsive images","optimize image loading","responsive image best practices","image sizes for mobile","srcset and sizes attributes"]}}