LoginSignup
0
0

Redundant alt attribute. Screen-readers already announce `img` tags as an image.

Last updated at Posted at 2019-12-26

Gatsby.jsでホームページを作ろうとしていた時のこと。なんか警告を出してきた。

warn ESLintError: 
<JavaScriptファイルの絶対パス>.js
  5:5  warning  Redundant alt attribute. Screen-readers already announce `img` tags as an image. You don’t need to use the
words `image`, `photo,` or `picture` (or any specified custom words) in the alt prop  jsx-a11y/img-redundant-alt

この警告は何

gatsby@2.18.8にはeslint-plugin-jsx-a11y@6.2.3が依存パッケージとして入っている。

% npm ls eslint-plugin-jsx-a11y
<プロジェクトのpackage名>@<プロジェクトのバージョン> <プロジェクトのルートディレクトリパス>
└─┬ gatsby@2.18.8
  └── eslint-plugin-jsx-a11y@6.2.3 

これが警告を出してくれている。

「スクリーンリーダーは「img」タグを画像として認識しています。のalt属性に「image」、「photo」または「picture」という単語を使用する必要はありません」らしい。

そもそも タグに入れる alt 属性とは

画像の説明。アクセシビリティとして用意する他に、画像が取得できなかった際、代わりに表示するものでもある。
必須ではない。

<img src="./hogepage.png" alt="ほげぱげ">

装飾の場合は空文字列で良いらしい。

<img src="./hogepage.png" alt="">

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0