Skip to content

alt-text

✅ Recommended ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Enforce the use of alternative text for images.

Rule Details

This rule is triggered when an image is missing alternative text (alt text) information.

Alternative text is important for accessibility and describes the content of an image for people who may not be able to see it.

Guidance for writing alternative text is available from the W3C, Wikipedia, and other locations.

Alternative text is commonly specified inline as:

md
![alternative text](https://example.com/image.jpg)

Or with reference syntax as:

md
![alternative text][ref]

[ref]: https://example.com/image.jpg "Optional title"

Or with HTML as:

html
<img src="https://example.com/image.jpg" alt="alternative text" />

Examples

❌ Incorrect

Examples of incorrect code for this rule:

md
![](https://example.com/image.jpg)

![][image]

[image]: https://example.com/image.jpg

<img src="https://example.com/image.jpg" />

<img src="https://example.com/image.jpg" alt="" />
js
export default [
  // ...
  {
    rules: {
      'mark/alt-text': 'error', 
    },
  },
  // ...
];

✅ Correct

Examples of correct code for this rule:

md
![alternative text](https://example.com/image.jpg)

![alternative text][image]

[image]: https://example.com/image.jpg

<img src="https://example.com/image.jpg" alt="alternative text" />
js
export default [
  // ...
  {
    rules: {
      'mark/alt-text': 'error', 
    },
  },
  // ...
];

Options

No options are available for this rule.

AST

This rule applies to the Image, ImageReference, and Html nodes.

Prior Art