dimensions
它能做什么
这项技能检查网站中的图片标签是否缺少尺寸设置。适合希望页面在加载时保持稳定的开发者。
适用场景
- ✓当照片加载完成时,页面内容发生跳动时。
- ✓当你向页面或模板中添加新图片时。
- ✓当你的页面在布局稳定性检查中分数较低时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dimensions/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能找出我网站上缺少宽度和高度的图片吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会扫描图片标签,并报告缺少宽度或高度的图片。它会建议添加图片的实际尺寸,使浏览器在图片加载前就预留出空间。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Set explicit width and height on images
Images without explicit dimensions are the most common cause of Cumulative Layout Shift (CLS), a Core Web Vitals metric. When images load and cause layout jumps, users accidentally click the wrong element—a frustrating experience that Google penalises in search rankings. A CLS score above 0.1 is considered 'needs improvement'; above 0.25 is 'poor'.
Quick Reference
- Reserve findings for meaningful content images; decorative micro-SVGs or ornament-only assets are low-priority exceptions when CSS already reserves stable space
- Example low-risk exception:
<img src="/divider.svg" alt="" aria-hidden="true">should not be flagged on its own without evidence of visible layout shift - Always set
widthandheightattributes on<img>matching the image's intrinsic dimensions - Pair with
height: autoin CSS to keep the image fluid while preserving the aspect ratio - Missing dimensions are the leading cause of Cumulative Layout Shift (CLS) from images
- Browsers derive
aspect-ratiofrom these attributes—do not set arbitrary placeholder values
Check
Scan all <img> elements in the codebase. Identify any that are missing either the width or height attribute. Also check <source> elements inside <picture>—dimensions should be on the <img> fallback. Report each image missing dimensions with its file path and line number. Note: SVG icons under 32px, tiny decorative SVG ornaments with stable CSS sizing, and images loaded as CSS backgrounds are exempt.
Fix
For each <img> missing width/height: 1) Add the intrinsic pixel dimensions as attributes (e.g., width="800" height="450"). 2) Use CSS max-width: 100% and height: auto on the element to keep it responsive. 3) The attribute values must match the image's intrinsic aspect ratio—do not set arbitrary numbers. 4) For dynamically sized images, calculate the aspect ratio and use the CSS aspect-ratio property as a fallback. 5) Skip purely decorative micro assets when the snippet already shows stable sizing and there is no evidence of layout shift risk. Show the before and after HTML for each fixed image.
Explain
Explain why width and height attributes on <img> prevent Cumulative Layout Shift (CLS). When a browser parses HTML, it does not yet know an image's dimensions—without explicit attributes, the browser initially renders a 0-height placeholder, then jumps the layout when the image loads. With width and height set, the browser calculates the aspect ratio from the attributes and reserves space immediately, eliminating the shift. This became especially important as modern browsers use the aspect-ratio CSS property derived from these HTML attributes.
Code Review
Review image assets, markup, and delivery configuration related to Set explicit width and height on 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.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/images/dimensions
常见问题
没有尺寸的图片为什么会造成问题?
浏览器不知道应该预留多少空间,因此图片出现时,下方的文字会被推开。
很小的装饰性图标也包括在内吗?
这项技能把很小的装饰性图片视为低优先级,因为它们很少会推动周围的内容。
什么分数算是好?
这项技能说明,布局偏移分数低于 0.1 为良好,高于 0.25 为较差。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Set explicit width and height on images. Check encoded size, rendered size, loading strategy, and above-the-fold impact together. Separate real CLS risks from tiny decorative SVGs or ornament-only assets that are unlikely to move surrounding content.
热度
- GitHub 星标
- 75k
- 排名
- #2815
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。