An “img” Element Must Have An “alt” Attribute, Except Under Certain ...
Có thể bạn quan tâm
A <source> element inside a <picture> that is followed by another <source> or an <img> with srcset must include a media and/or type attribute.
The <source> element is used inside <picture> for responsive images, allowing different resources to be loaded based on conditions such as viewport width (media) or image format (type). According to the HTML standard, when multiple <source> elements are present (or a following <img> with srcset), each <source> must provide a media and/or type attribute so the browser can choose the appropriate resource based on those hints.
Without media or type, the browser cannot distinguish when to use each source, which can lead to validation errors and unexpected rendering behavior.
Incorrect example (causes the validator error):
<picture><sourcesrcset="image1.webp"><sourcesrcset="image2.jpg"><imgalt=""src="fallback.jpg"srcset="fallback2x.jpg2x"></picture>Correct examples (fixing the error):
<picture><sourcesrcset="image1.webp"type="image/webp"><sourcesrcset="image2.jpg"type="image/jpeg"><imgalt=""src="fallback.jpg"srcset="fallback2x.jpg2x"></picture>or
<picture><sourcesrcset="image-small.jpg"media="(max-width:600px)"><sourcesrcset="image-large.jpg"media="(min-width:601px)"><imgalt=""src="fallback.jpg"srcset="fallback2x.jpg2x"></picture>By specifying the media and/or type attributes for each <source>, you satisfy the HTML standard and resolve the W3C validator issue.
Từ khóa » Html5 Img Alt
-
HTML Img Alt Attribute - W3Schools
-
HTML Alt Attribute - W3Schools
-
: The Image Embed Element - HTML - MDN Web Docs - Mozilla
-
Image ALT Tag Tips For HTML - Accessibility At Penn State
-
HTML Img Alt Tags For SEO Best Practice - Search Engines Love ...
-
HTML Img Alt Attribute - Dofactory
-
HTML |
Alt Attribute - GeeksforGeeks
-
Alt Attribute - Wikipedia
-
HTML Img Alt 属性| 菜鸟教程
-
HTML Element: Img: Alt | Can I Use... Support Tables For HTML5 ...
-
Why An HTML Image Alt Text Doesn't Show On Hover - Computer Hope
-
HTML5
Tag Alternative Image [duplicate] - Stack Overflow
-
HTML Img Alt Attribute - W3Schools