Prompt to write alt text for images that have none

Short answer

This prompt asks an AI assistant to list every image with a missing or empty alt attribute in your exported site, look at the image and the text around it, and propose alt text in a CSV. Decorative images get an empty alt on purpose. It edits the HTML only after you approve the CSV.

Last reviewed

Key facts

  • A missing alt attribute and an empty alt attribute are different. Empty is correct for a purely decorative image.
  • Good alt text describes what the image is for in the page, in a short phrase, and never repeats nearby text.
  • The assistant must look at the image file, not guess from the file name.
  • Test status: the detection script was run on five pages of webexport.online saved to a folder (home, pricing, tools, blog and guides). It found 21 images, 5 of them with an empty alt, all decorative artwork. Writing and applying alt text with an assistant was not run.

The prompt

Paste this into Claude Code, Cursor, Codex or another AI coding assistant with your project folder open, and replace everything in square brackets first. See how to run it in each tool.

Write alt text
You are fixing image alt text in a static site in [EXPORT_FOLDER].

STEP 1: FIND
List every <img> in every .html file whose alt attribute is missing or empty. For each, record the file, the src, whether width and height are set, and the text of the nearest heading and paragraph. Write the result to alt-report.csv.

STEP 2: LOOK
Open each image file or fetch its src. Decide which kind it is:
- informative: it adds meaning the text does not give
- functional: it is inside a link or button, so the alt describes where the link goes or what the button does
- decorative: it adds nothing, such as a background flourish
- text in an image: the alt repeats the text exactly
- logo: the alt is the company name

STEP 3: PROPOSE
Add two columns to alt-report.csv: kind and proposed_alt. Rules for proposed_alt:
- Describe the image in the context of the page, in one short phrase or sentence.
- Do not begin with "image of" or "picture of".
- Do not repeat the caption or the paragraph next to it.
- Do not read anything into an image you cannot see. If the file will not open, write "NEEDS REVIEW".
- Decorative images get an empty alt, written as alt="".

STEP 4: STOP
Do not edit any HTML. Wait for my approval of the CSV.

STEP 5: APPLY, AFTER I APPROVE
Edit only the alt attribute of the rows I approved. Leave src, class, size and every other attribute as they are.

RULES
- Do not touch images that already have alt text.
- Do not rename, move or recompress any image.
- If scripts/alt-audit.mjs exists, use it for step 1.

How to run it

  1. Run the prompt and open alt-report.csv in a spreadsheet.
  2. Check the kind column first. A decorative image marked informative gets a pointless alt, so correct it.
  3. Edit any proposed_alt you would not write yourself, and mark the rows you approve.
  4. Apply, rebuild if needed, and view three pages with images turned off to see the alt text in place.

Run it without a paid key

The detection step needs no AI at all. This script walks a folder of HTML files and lists images with no alt or an empty one, with the text around them. It reads the alt attribute in either quote style. Run it first to see how big the job is.

scripts/alt-audit.mjs
// Usage: node alt-audit.mjs ./exported-site > alt-report.csv
// Lists every <img> in .html files with a missing or empty alt, plus the text around it.
import fs from 'node:fs';
import path from 'node:path';

const root = process.argv[2];
if (!root) { console.error('Usage: node alt-audit.mjs <folder>'); process.exit(1); }
const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? (e.name === 'node_modules' ? [] : walk(path.join(d, e.name))) : e.name.endsWith('.html') ? [path.join(d, e.name)] : []);
const q = (v) => `"${String(v).replace(/"/g, '""')}"`;
console.log('file,src,problem,has_size,context');
let total = 0, bad = 0;
for (const file of walk(root)) {
  const html = fs.readFileSync(file, 'utf8');
  for (const m of html.matchAll(/<img\b[^>]*>/gi)) {
    total++;
    const tag = m[0];
    const alt = tag.match(/\salt=(?:"([^"]*)"|'([^']*)')/i);
    const problem = !alt ? 'missing' : (alt[1] ?? alt[2]).trim() === '' ? 'empty' : null;
    if (!problem) continue;
    bad++;
    const src = tag.match(/\ssrc=["']([^"']+)/i)?.[1] ?? '';
    const around = html.slice(Math.max(0, m.index - 400), m.index + 400).replace(/<(script|style)[\s\S]*?<\/\1>/gi, ' ').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 140);
    console.log([path.relative(root, file), src, problem, /\swidth=/i.test(tag) && /\sheight=/i.test(tag), around].map(q).join(','));
  }
}
console.error(`${total} images, ${bad} without usable alt text (empty alt can be correct for decorative images)`);

Which kind of image gets which alt

KindAlt textExample of the pattern
InformativeA short description of what the image shows in this pageA chart of monthly visitors with a rising line
FunctionalWhat the link or button doesDownload the export ZIP
DecorativeEmpty, alt=""A background curve
Text in an imageThe same words as the imageThe sign reads Open daily
LogoThe company nameThe company name

The categories follow the W3C alt decision tree. Read it once, because a page's purpose changes what an image needs.

Verify the result

Run the detector again and confirm only the decorative images are left.

terminal
node scripts/alt-audit.mjs exported-site > alt-report-after.csv
grep -c '"missing"' alt-report-after.csv
git diff -U0 | grep '^[+-]' | grep -v '^[+-][+-]' | grep -vi 'alt=' | head
  • No image is reported as missing. Remaining empty alt values are on decorative images only.
  • The last command prints nothing, so no change touched anything but alt attributes.
  • A screen reader or the browser's accessibility panel reads sensible text for three sample images.

What can go wrong

  • The assistant can describe an image wrongly or invent text it cannot read. Spot-check the proposals, especially charts and screenshots.
  • Alt text that repeats a nearby caption is read twice by a screen reader. The prompt blocks it, but check.
  • Marking an informative image decorative hides it from people who cannot see it. When unsure, write the description.

Frequently asked questions

Is an empty alt always wrong?

No. An empty alt tells a screen reader to skip a decorative image, which is the right choice for it. A missing alt attribute is the problem, because a reader may announce the file name.

How long should alt text be?

Short enough to read in a breath. One phrase is usually enough. The W3C decision tree starts from what the image is for, and the right text depends on that.

Can I bulk-write alt text without looking?

You can, and the result will be wrong for some images. The CSV step lets you review proposals before they reach the HTML.

Is there a tool for the audit?

The Image Alt Auditor checks missing and empty alt values and image usage signals from a URL.

Official documentation

Free tools for this job

Start with the files

Prompts work best on a WebExport download of your site. Paste your public URL into the export form and get a ZIP. The Free plan covers 1 site, 5 exports a month, 15 pages and 20 MB per export. Professional is a $9.99 one-time purchase with unlimited pages.