Open In App

HTML DOM Image alt Property

Last Updated : 22 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM Image alt Property is used to set or return the value of the alt attribute of the image element. The alt attribute is used to specify the alternate text for an image. It is useful when the image is not displayed. It is used to give alternative information for an image.

Syntax:

It returns the image alt property

ImageObject.alt

It sets the Image alt property.

ImageObject.alt = text

Property Values: It contains a single value that specifies the alternative text for the image. 

Return Value: It returns a string value that represents the alternate text for the image.

Example 1: This example returns the image alt property. 

HTML




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h2>HTML DOM Image alt Property</h2>
  
        <img id="GFG" src=
            alt="GeeksforGeeks logo" />
        <br />
  
        <button onclick="Geeks()">Click me!</button>
          
        <p id="sudo"></p>
    </center>
  
    <script>
        function Geeks() {
            var g = document.getElementById("GFG").alt;
            document.getElementById("sudo").innerHTML = g;
        }
    </script>
</body>
  
</html>


Output:

image alt

Example 2: This example sets the Image alt Property.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h2>HTML DOM Image alt Property</h2>
  
        <img id="GFG" src=
            alt="GeeksforGeeks logo" />
        <br />
  
        <button onclick="Geeks()">
            Click me!
        </button>
          
        <p id="sudo"></p>
    </center>
  
    <script>
        function Geeks() {
            var g = (document.getElementById("GFG").alt
                = "Hello GeeksForGeeks");
  
            document.getElementById("sudo").innerHTML = g;
        }
    </script>
</body>
  
</html>


Output:



Similar Reads

HTML | DOM Input Image alt Property
The HTML DOM Input Image alt Property is used set or return the value of the alt attribute of an Input Image. The 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. Syntax: It returns the alt property.imageObject.alt It is used to Set
2 min read
HTML DOM Area alt Property
The Area alt Property in HTML DOM is used to set or return the value of the alt attribute. It is used to specify the alternate name for the area if the image is not visible. Syntax: It return the Area alt property. areaObject.altIt is used to set the Area alt property.areaObject.alt = text Property Values: It contains a single value which specifies
2 min read
HTML | &lt;img&gt; alt Attribute
The &lt;img&gt; 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. Syntax: &lt;img alt="text"&gt; Attribute Values: It contains single value text which specifies the alternative text for an image. Example: C/C++ Code &amp;lt;!DOCTYPE h
1 min read
How to extract img src and alt from html using PHP?
Extraction of image attributes like 'src', 'alt', 'height', 'width' etc from a HTML page using PHP. This task can be done using the following steps. Loading HTML content in a variable(DOM variable). Selecting each image in that document. Selecting attribute and save it's content to a variable. Output as HTML img object or as plain values as require
2 min read
HTML | &lt;area&gt; alt Attribute
The &lt;area&gt; alt attribute is used to specify the alternative text for an image when the image attribute is not displayed. It gives alternative information for the user when the image is not loaded to display.Syntax: &lt;area alt="text"&gt; Attribute Values: It contains single value text which is used to specify the alternative text for area, i
1 min read
HTML | &lt;input&gt; alt Attribute
The HTML &lt;input&gt; alt Attribute is used to specify the alternative text for an image when the image attribute is not displayed. It gives alternative information for the user when the image is not loaded to display. Syntax: &lt;input alt="text"&gt; Attribute Values: It contains single value text which is used to specify the alternative text for
1 min read
HTML | applet alt Attribute
The HTML applet alt attribute is used to specify the alternate text for an applet element. It is useful when the applet element not displayed. It is used to give alternative information for an applet element. Note: This attribute is not supported by HTML5. Syntax: &lt;applet alt="text"&gt; Attribute Values: It contains single value text which speci
1 min read
Describe the purpose of using alt attribute in &lt;img&gt; tag in HTML
The &lt;img&gt; alt attribute is used to specify the alternate text for an image. It is useful when the image is not displayed. It is used to give alternative information for an image. It is also very much helpful in the Google ranking of your page. In this article, we will discuss the alt attribute in the &lt;img&gt; tag. Syntax: &lt;img alt="text
1 min read
HTML alt attribute
The alt attribute in HTML provides alternative text for images, aiding accessibility and providing context for screen readers. Syntax: &lt;img src=" " alt=" " &gt;Supported tags:  Name Description area &lt;area&gt;'s alt provides alternative text for image map areas. image &lt;img&gt; alt offers alternative text for image accessibility. input speci
2 min read
HTTP headers | Alt-Svc
The HTTP headers Alt-Svc header is a response-type header it has been used to advertise alternative service. Which services can be defined by a protocol/host/port combination. Syntax: Alt-Svc: clear Alt-Svc: &lt;protocol-id&gt;=&lt;alt-authority&gt;; ma=&lt;max-age&gt;; persist=1 Directives: This header accept five directives as mentioned above and
1 min read