Open In App

How to specify an alternate text for an image in HTML ?

Last Updated : 09 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

The alternative text for an image is useful when the image not displayed/loaded. If the image is not loaded the its alternative text is displayed on the web page. Alternative text is the alternative information for an image.

Example 1: In this example, the image path contains the image so it will display the image.

HTML
<!DOCTYPE html> 
<html> 

<head> 
    <title> 
        How to specify an alternate 
        text for an image? 
    </title> 
</head> 

<body> 
    <h1 style="color:green;">GeeksforGeeks</h1> 

    <h2>
        How to specify an alternate 
        text for an image?
    </h2> 

    <img src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"
        alt="GeeksforGeeks logo"> 
</body> 

</html>

Output:

Example 2: In this example, the image path is not correct so it will display alternative text information.

HTML
<!DOCTYPE html> 
<html> 

<head> 
    <title> 
        How to specify an alternate 
        text for an image? 
    </title> 
</head> 

<body> 
    <h1 style="color:green;">GeeksforGeeks</h1> 

    <h2>
        How to specify an alternate 
        text for an image?
    </h2> 

    <img src= "geeks.png"
        alt="GeeksforGeeks logo"> 
</body> 

</html>

Output:


Next Article

Similar Reads