I was just wondering that in the html img tag
<img alt = "default image" src = "image">
is it possible to have a alternate image rather than just text. Or if is it possible to nest the img tag in the alt ""s.
The <img> alt attribute is used to specify the alternate text for an image. It is useful when the image not displayed. It is used to give alternative information for an image. Attribute Values: It contains single value text which specifies the alternative text for an image.
CTRL C + CTRL V.
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
HTML 5 <img> Tag. The HTML <img> tag is used for embedding images into an HTML document. The value given by the src attribute is the URL to the embedded image. The srcset attribute can also be used in order to specify different images to use in different situations (e.g. high-resolution displays, small monitors, etc).
No, you can't put another image in the alt attribute of an <img>
. You can however use the onerror event to load another image using JavaScript, so if the original image doesn't load, a backup can be loaded.
function standby() {
document.getElementById('foo').src = 'https://www.google.com/images/srpr/logo11w.png'
}
<img id="foo" src="notfound.gif" onerror="standby()">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With