简体   繁体   中英

Can I use same values alt=“name” for two or more img html elements in single page?

I am using two logos in one page and my code is

<img src="img/logo/logo-black.png" alt="logo" class="logo-white"/>

and

<img src="img/logo/logo-black.png" alt="logo" class="logo-black"/>

when I validated this code I have receive the following message, I am not sure this is an error or not. Have a look at the screenshot and let me know what is the message about. w3c报告

The validation basically says this:

Your HTML IS validated from a technical point of view, no software will encounter problems when parsing it, but having duplicated ALT s have a very high chance of not accurately representing your pictures and which would then lead to an incorrect information when the image can't be loaded, or incorrect interpretation of your images by screen readers.

But still, if you're 100% sure your images are the exact same, having the same alt text should be nothing but fine.

You can perfectly use the same alternative text as long as the text is meaningful.

For instance:

<img src="jack1.jpg" alt="Portrait of Jack Smith" />
<img src="jack2.jpg" alt="Portrait of Jack Smith" />

BUT an alternative text like logo is not meaningful, you should replace it by logo of some company name or by a blank alternative alt="" if the image is here for decorative purpose

The alt tag is alternate text. That is its displayed when the image doesn't load.

You "can" use same alt but you shouldn't !

alt should always be a meaningful line describing what the image is.

What if the user's page doesn't load fast enough and he gets to see the alt tags? or What if your page is being parsed by a browser for visually-impared?

Always use meaningful alternate text tags for images so that the users who may not see the image at-least get a gist of what should have shown up there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM