Search code examples
reactjscompiler-warnings

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


I typed <img src= {'https://robohash.org/${id}?size=300x300'}alt="photo" /> on my React js file, after I saved the file and I got an error message on GitBash saying ,

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

Then I removed the alt from the code, and I got the error message saying,

img elements must have an alt prop, either with meaningful text, or an empty string for decorative images jsx-a11y/alt-text

How can I fix this problem?


Solution

  • I tried this one and it worked:

    <input type="image" img src = {'https://robohash.org/${id}?size=300x300'} alt="photo" />

    (I have used `` not the single quotation marks for the url)