htmlcssalt

Can there be more than one alt attribute on an image?


This is kind of a simple question but is there a way I can have more than on alt on an img. If there is it would look like this maybe:

<img src="happy.jpeg" alt="happy face" alt="Smiley Face">

or

<img src="happy.jpeg" alt="'happy face', 'Smiley Face'">


Solution

  • Here in HTML Specs says that:

    There must never be two or more attributes on the same start tag whose names are an ASCII case-insensitive match for each other.

    It actually ignores the second attribute with the same name and only uses the first one.

    Also when you specify an attribute using double-quoted attribute value syntax like this,

    <img src="happy.jpeg" alt="'happy face', 'Smiley Face'">
    

    you only pass this single string, not multiple keywords:

    'happy face', 'Smiley Face'