Przejdź do głównej zawartości

useImageSize

Ta treść nie jest jeszcze dostępna w Twoim języku.

biome.json
{
"linter": {
"rules": {
"correctness": {
"useImageSize": "error"
}
}
}
}

Enforces that <img> elements have both width and height attributes.

This rule ensures that <img> elements have width and height attributes.

Images without specified width and height can cause layout shifts as the browser does not know how much space to reserve for them, leading to a poor user experience. It’s recommended to always include these attributes to prevent such issues.

<img src="/image.png"/>
code-block.jsx:1:1 lint/correctness/useImageSize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing width or height attribute on img element.

> 1 │ <img src=“/image.png”/>
^^^^^^^^^^^^^^^^^^^^^^^
2 │

Without explicit dimensions, images cause layout shifts (CLS) when loading, harming user experience and SEO.

Learn why this matters: web.dev: Image Dimensions, MDN: img attributes

<img src="/static/images/portrait-01.webp"/>
code-block.jsx:1:1 lint/correctness/useImageSize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing width or height attribute on img element.

> 1 │ <img src=“/static/images/portrait-01.webp”/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Without explicit dimensions, images cause layout shifts (CLS) when loading, harming user experience and SEO.

Learn why this matters: web.dev: Image Dimensions, MDN: img attributes

<img src="/image.png" width="200"/>
code-block.jsx:1:1 lint/correctness/useImageSize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing width or height attribute on img element.

> 1 │ <img src=“/image.png” width=“200”/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Without explicit dimensions, images cause layout shifts (CLS) when loading, harming user experience and SEO.

Learn why this matters: web.dev: Image Dimensions, MDN: img attributes

<img src="/image.png" height="200"/>
code-block.jsx:1:1 lint/correctness/useImageSize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing width or height attribute on img element.

> 1 │ <img src=“/image.png” height=“200”/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Without explicit dimensions, images cause layout shifts (CLS) when loading, harming user experience and SEO.

Learn why this matters: web.dev: Image Dimensions, MDN: img attributes

<img width="200" height="600" src="/static/images/portrait-01.webp" />
<img width="100" height="100" src="https://example.com/image.png" />