Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2815

dimensions

Skill này làm gì

Skill này kiểm tra các thẻ ảnh trên website để tìm thiếu thiết lập kích thước. Skill dành cho lập trình viên muốn trang giữ ổn định khi đang tải.

Khi nào nên dùng

  • ✓Khi nội dung trên trang nhảy khi ảnh tải xong.
  • ✓Khi bạn thêm ảnh mới vào trang hoặc template.
  • ✓Khi trang của bạn điểm kém trong các bài kiểm tra độ ổn định bố cục.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dimensions/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/dimensions/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể tìm các ảnh trên website của tôi bị thiếu chiều rộng và chiều cao không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent quét các thẻ ảnh và báo những thẻ thiếu width hoặc height. Nó gợi ý thêm kích thước thật của ảnh để trình duyệt dành sẵn chỗ trước khi ảnh tải.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 width and height attributes on <img> matching the image's intrinsic dimensions
  • Pair with height: auto in 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-ratio from 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

Câu hỏi thường gặp

Vì sao ảnh thiếu kích thước gây vấn đề?

Trình duyệt không biết cần chừa bao nhiêu chỗ, nên chữ bên dưới bị đẩy đi khi ảnh xuất hiện.

Các icon trang trí nhỏ có được tính không?

Skill coi ảnh trang trí nhỏ là ưu tiên thấp, vì chúng hiếm khi làm nội dung xung quanh bị xê dịch.

Điểm nào được coi là tốt?

Skill nói điểm dịch chuyển bố cục dưới 0,1 là tốt, còn trên 0,25 là kém.

Chi tiết

Mô tả gốc của tác giả

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.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2815
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự