Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this warning message mean? 'img elements must have an alt prop, either with meaningful text, or an empty string for decorative images'

People also ask

What is an alt prop?

Definition and UsageThe alt property sets or returns the value of the alt attribute of an image. The required alt attribute specifies an alternate text for an image, if the image for some reason cannot be displayed (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

What is the purpose of the alt attribute in an IMG element?

The src attribute is required, and contains the path to the image you want to embed. The alt attribute holds a text description of the image, which isn't mandatory but is incredibly useful for accessibility — screen readers read this description out to their users so they know what the image means.

When would you see or need the alt text for an IMG element?

Alt text uses: Visually impaired users using screen readers will be read an alt attribute to better understand an on-page image. 2. Alt text will be displayed in place of an image if an image file cannot be loaded.

Why is the alt tag in the image element of HTML is necessary?

Specifies an alternate text for an image. Guidelines for the alt text: The text should describe the image if the image contains information. The text should explain where the link goes if the image is inside an <a> element.


It means when you create an image in your HTML, you should include an alt attribute for the benefit of screen readers and text browsers.

<img src="url" alt="description of image">

Images should have an alt property. The alternate property comes into picture in several cases like the card not getting downloaded, incompatible browsers, or the image getting corrupt. You need to pass in a prop called alt to the image.

Also, Alt tag is used by screen readers for visually impaired. Therefore it is considered as a good practice to always add a ALT tag to the image component. Accessibility


It means that your <img> tag MUST have an alt attribute on it like so:

<img src="pathToYourImage.extension" alt="My Awesome Image">

In case if the image isn't loaded then the text inside the alt attribute will be shown instead.


I had a similar error with this code.

    <img src={props.contacts.imgUrl}/>

Solution: Notice the alt= position on the image anchor outside the curved parenthesis

    <img src={props.contacts.imgUrl} alt=""/>

I had the same error. Basically, you should not include these words in alt attribute. image or picture, or photo

// avoid using image or picture, or photo


// do
<img src="foo" alt="nice"/>.      // good


// don't
<img src="foo" alt="foo is coming "/>.    // bad