picture-element
它能做什么
这个技能检查项目中的 picture 元素,并修复缺少 img 备用元素或关键属性的部分。它面向使用现代图片格式的网站构建者。
适用场景
- ✓你请智能体检查项目中的 picture 元素是否缺少备用元素的时候。
- ✓某些浏览器中图片不显示,而 picture 标记可能不完整的时候。
- ✓你在添加现代图片格式,并希望从一开始标记就正确的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/picture-element/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查网站上的 picture 元素,并修复缺少备用图片或 alt 文本的部分吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查每个 picture 元素是否以带有 alt、width 和 height 属性的 img 元素结尾。它还会检查 source 元素是否排在前面、是否有 srcset 或 media 值,以及是否包含用于格式选择的 type。然后它会补上缺失的部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Use <picture> with an <img> fallback
A <picture> without an <img> fallback renders nothing in browsers that don't support <picture> (IE11) or don't support any of the <source> formats. The <img> child is also where alt, width, height, loading, and fetchpriority attributes live—these apply regardless of which source the browser selects.
Quick Reference
- Every
<picture>must end with an<img>element—it is the required fallback and carriesalt <source>elements are evaluated top-to-bottom; the first match wins- Use
type="image/avif"andtype="image/webp"on<source>for format selection - The
<img src>should point to a JPEG or PNG—the universal fallback for all browsers
Check
Scan all <picture> elements in this codebase. Verify: 1) Every <picture> has an <img> as its last child (required fallback). 2) The <img> has an alt attribute. 3) The <img> has width and height attributes. 4) <source> elements appear before the <img> child. 5) Each <source> has either a srcset attribute or a media attribute. 6) format-selecting <source> elements have a type attribute (type="image/avif", type="image/webp"). Flag any <picture> missing an <img> child or with <img> not as the last child.
Fix
For each <picture> element with issues: 1) If missing <img>: add <img src="{fallback-url}" alt="{description}" width="{w}" height="{h}"> as the last child. 2) If <img> is not last: move it to after all <source> elements. 3) If <source> elements lack type attributes for format selection: add type="image/avif" or type="image/webp". 4) Verify the <img src> points to a universally supported format (JPEG or PNG) as the ultimate fallback. Show the corrected <picture> markup.
Explain
Explain how the <picture> element works. Browsers evaluate <source> elements in document order and use the first one whose conditions match (type, media, srcset). The <img> element is the fallback for browsers that don't support <picture> (IE11) or don't support the source format. Without an <img> child, <picture> is invalid HTML and produces no output. The alt attribute must be on the <img>, not the <source> elements—it applies regardless of which source is selected.
Code Review
Review image assets, markup, and delivery configuration related to Use <picture> with an <img> fallback. 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/picture-element
常见问题
为什么需要 img 备用元素?
不支持 picture 或所列格式的浏览器,需要 img 元素才能显示任何内容。
source 元素如何工作?
这个技能说,它们会从上到下依次检查,并使用第一个匹配项。
alt 和尺寸属性应该放在哪里?
这个技能说,它们应放在 img 元素上,无论选中哪个 source,它们都适用。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Use <picture> with an <img> fallback. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.
热度
- GitHub 星标
- 75k
- 排名
- #2979
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。