Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 <img> tag alternative image [duplicate]

Tags:

html

image

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.

like image 901
Hammad Ahmed Avatar asked Feb 13 '15 16:02

Hammad Ahmed


People also ask

How do I create an alternate image in IMG tag?

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.

How do you duplicate an image in HTML?

CTRL C + CTRL V.

How do I show an alternate image in HTML?

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).

Is IMG tag html5?

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).


1 Answers

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()">
like image 68
j08691 Avatar answered Oct 04 '22 10:10

j08691