Skip to contentView the source on GitHub

use-astro-image

Use <Image> from astro:assets instead of raw <img> tags.

Performancewarning by default ESLint rule

astro-doctor/use-astro-image

Why it matters

The built-in <Image> component automatically optimizes images (WebP/AVIF conversion, responsive srcset, lazy loading, explicit width/height to prevent layout shift). Plain <img> tags with static sources skip all of this. Source-less placeholders populated at runtime are ignored because they cannot be optimized at build time.

See the difference

Incorrect

Raw <img> tag

astroIncorrect example
---
---
<img src="/hero.png" alt="Hero image" />

Correct

<Image> from astro:assets

astroCorrect example
---
import { Image } from 'astro:assets'
import hero from '../assets/hero.png'
---
<Image src={hero} alt="Hero image" width={800} height={400} />

Configure this check

Override the default severity in your ESLint config:

javascripteslint.config.js
import astroDoctorPlugin from '@santi020k/eslint-plugin-astro-doctor'

export default [
  astroDoctorPlugin.configs.recommended,
  {
    rules: {
      'astro-doctor/use-astro-image': 'error',
    },
  },
]

Or set the severity for CLI scans in doctor.config.ts:

typescriptdoctor.config.ts
export default {
  rules: {
    'astro-doctor/use-astro-image': 'error',
  },
}

Use 'error', 'warn', or 'off'. The configuration guide covers presets and per-file overrides.

Keep exploring performance

Browse every rule and project audit