Error codes · Markup

PW5053

image_without_alt

The program must hold to this: an image says what it shows: an <img> has an alt, empty only where it shows nothing a reader needs, and an image button an alt that says what it does.

A program the compiler refuses with it

Refused: PW5053
module front

page Front() {
    route "/"

    view {
        <title>Blue Bottle</title>
        <main>
            <h1>Blue Bottle</h1>
            <img src="/front.jpg" width="640" height="480">
        </main>
    }
}
pw check
error: [PW5053] `<img>` has no `alt`
  --> front.pw:10:13
   |
 3 | / page Front() {
 4 | |     route "/"
 5 | |
 6 | |     view {
...  |
10 | |             <img src="/front.jpg" width="640" height="480">
   | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `<img>` has no `alt`
...  |
13 | | }
   | |_- `Front` renders this image
   |
   = note: Nothing stands for an image with no `alt`: a screen reader announces it as an image, often by its file name, and where it does not load the page shows no text in its place. HTML requires `alt` of every `<img>`: what the image shows, or `""` for one that shows nothing a reader needs, such as decoration or what the text beside it already says, which a screen reader then passes over. An `aria-label` or a `title` is not shown where the image fails to load.
   = help: write `alt="…"` saying what the image shows
   = help: or `alt=""` if it shows nothing a reader needs

From An image with no alt, in Errors and diagnostics. A test holds the guide's examples to the compiler.

The decisions behind it

0404, 0343, 0405

Reading the diagnostic

pw check prints the code in brackets, [PW5053], with the sentence above and the place in your program. Errors and diagnostics explains how to read one, and every code is listed with its rule.