HTML | Alt Attribute - GeeksforGeeks

Skip to content geeksforgeeks
  • Courses
    • DSA Courses
    • Programming Languages
  • Tutorials
    • Python Tutorial
      • Python Loops and Control Flow
    • Java
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App HTML alt attribute Last Updated : 27 Aug, 2024 Summarize Comments Improve Suggest changes Like Article Like Save Share Report Follow

The alt attribute in HTML provides alternative text for images, aiding accessibility and providing context for screen readers.

Syntax:

<img src=" " alt=" " >

Supported tags:

Name

Description

area

<area>’s alt provides alternative text for image map areas.

image

<img> alt offers alternative text for image accessibility.

input

specify the alternative text for an image when the image attribute is not displayed.

<applet>

used to specify the alternate text for an applet element.

Attribute Values:

value

Description

text

is used to specify the alternative text for the supported element if the image is not displaying.

Example: In This example we includes an image with the alt attribute providing alternative text (“GeeksforGeeks logo”) for accessibility.

HTML <!DOCTYPE html> <html> <head> <title> HTML img alt Attribute </title> </head> <body> <h1>GeeksforGeeks</h1> <h2>HTML img alt Attribute</h2> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" alt="GeeksforGeeks logo"> </body> </html>

Output:

html-image-alt-attribute

HTML image alt attribute

Example 2: In this example we are using an image with an image map created using <area> tags. Each <area> tag includes an alt attribute for accessibility, providing alternative text for the clickable areas.

HTML <!DOCTYPE html> <html> <head> <title> HTML area alt Attribute </title> </head> <body style="text-align:center;"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20190227165729/area11.png" alt="alt_attribute" width="300" height="119" class="aligncenter" usemap="#shapemap" /> <map name="shapemap"> <!-- area tag contained image. --> <area shape="poly" coords="59, 31, 28, 83, 91, 83" href= "https://media.geeksforgeeks.org/wp-content/uploads/20190227165802/area2.png" alt="Triangle"> <area shape="circle" coords="155, 56, 26" href= "https://media.geeksforgeeks.org/wp-content/uploads/20190227165934/area3.png" alt="Circle"> <area shape="rect" coords="224, 30, 276, 82" href= "https://media.geeksforgeeks.org/wp-content/uploads/20190227170021/area4.png" alt="Square"> </map> </body> </html>

Output:

alt2.gif

HTML area alt attribute

Example 3: In this example we are showing an input field of type image with the alt attribute providing alternative text (“Submit”) for accessibility.

HTML <!DOCTYPE html> <html> <head> <title> HTML Input alt Attribute </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>HTML Input alt Attribute</h2> <input id="myImage" type="image" src= "https://media.geeksforgeeks.org/wp-content/uploads/gfg-40.png" alt="Submit" width="48" height="48"> </body> </html>

Output:

HTML-alt-attribute

HTML alt attribute example

Supported Browsers

The browsers supported by HTML | alt attribute are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

HTML alt attribute – FAQs

Is the alt attribute required for images?

Yes, the alt attribute is required for all <img> tags in HTML5. Even if you have a decorative image that does not require descriptive text, it is recommended to use an empty alt=”” attribute.

What should I include in the alt attribute?

The alt attribute should provide a brief and accurate description of the image’s content or purpose. For example, “A person using a laptop” would be appropriate for an image showing that scenario.

What happens if the alt attribute is missing from an image?

If the alt attribute is missing, screen readers will either ignore the image or read the file name, which is usually not helpful. Additionally, if the image fails to load, users won’t see any descriptive text.

Should I use the alt attribute for decorative images?

For purely decorative images that do not add information to the content, it is best to use an empty alt=”” attribute. This signals screen readers to skip the image.

Can I use the alt attribute with other HTML elements besides <img>?

No, the alt attribute is specifically designed for the <img> tag. Other elements, like <input type=”image”>, use the alt attribute differently.

V

Vijay Sirra Follow Improve Previous Article HTML align Attribute Next Article HTML async Attribute

Similar Reads

HTML | <area> alt Attribute The <area> 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: <area alt="text"> Attribute Values: It contains single value text which is used to specify the alternative text for area, i 1 min read HTML | <input> alt Attribute The HTML <input> 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: <input alt="text"> 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: <applet alt="text"> Attribute Values: It contains single value text which speci 1 min read Describe the purpose of using alt attribute in <img> tag in HTML The <img> 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 <img> tag. Syntax: <img alt="text 1 min read HTML img alt Attribute The <img> alt attribute is used to specify alternative text for an image. This attribute is particularly useful when the image cannot be displayed, either due to a broken link or when users rely on screen readers. Syntax<img src="image.jpg" alt="text">Attribute ValuesThe alt attribute contains a single value, which is a text description 1 min read What is the purpose of the alt attribute in the <img> Tag ? The "alt" attribute in the <img> Tag is important for making websites more accessible. It stands for "alternative text" and is used to describe what an image is about. If the image can't load, this text shows up instead. It's also helpful for people who use screen readers because they can hear this description, making the web more inclusive f 1 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 | 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 Image alt Property 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 t 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: <protocol-id>=<alt-authority>; ma=<max-age>; persist=1 Directives: This header accept five directives as mentioned above and 1 min read Vue.js v-on:click.alt Directive The v-on:click.alt directive is a Vue.js directive used to add a click event listener to an element. While click directive triggers the event for all kind of clicks, this directive only triggers the event when alt key is pressed along with the click. First, we will create a div element with id as app and let's apply the v-on:click.alt directive to 1 min read How to detect Alt/Option + another key in textarea ? In this article, we need to Detect Alt/Option + another key in textarea by using HTML and JavaScript. It detects both the keys i.e. Alt + h. The onkeydown Event occurs when someone presses a key (on the keyboard). Syntax: <textarea onkeydown="newScript" > Example: The below code illustrates to detect that when the user pressed the Alt + h key 1 min read How to disable ALT key using jQuery ? jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers What is the use of it ? Disabling ALT keys have a wide range of application when you step into the field of we 2 min read How href attribute is different from src attribute in HTML ? In HTML5, the href and src attributes play distinct roles in defining paths or URLs, each associated with specific HTML elements. The href attribute, commonly found in an anchor (<a>) elements, points to the destination of hyperlinks, facilitating navigation. The src attribute, used with elements like <img> and <script>, specifies 1 min read When to use the class attribute and the id attribute ? The class attribute is used when multiple HTML elements share a common style or behaviour, allowing the application of a shared style to several elements. It promotes code reusability and is suitable for elements with similar characteristics. The id attribute is utilized when a unique identifier is needed for a specific HTML element. This identifie 1 min read How to use the target attribute and the rel attribute in the <a> Tag ? The target and rel attributes in the <a> (anchor) tag is used to control the behaviour of hyperlinks, specifying how the linked content should be opened and establishing relationships between the current and linked documents. Here's how to use these attributes: target Attribute:The target attribute determines where the linked content will be 2 min read HTML | <html> xmlns Attribute The HTML <html> xmlns Attribute is used to specify the xml namespace for a document. Important Note: This attribute is mainly required in XHTML, not valid in HTML 4.01, and optional in HTML 5. Syntax: <html xmlns="http://www.w3.org/1999/xhtml"> Attribute Values: https://www.geeksforgeeks.org/ It defines the namespace to use (for XHTML d 1 min read HTML | scoped Attribute The HTML scoped attribute is a boolean attribute that is used to specify that the styles only apply to this element's parent element and that element's child elements (not the entire document).Note : It is a deprecated attribute and it is not supported by HTML5. Supported tag: style Example: C/C++ Code <!DOCTYPE html> <html> <head 1 min read HTML | <th> valign Attribute The HTML <th> valign Attribute is used to specify the vertical alignment of text content in a header cell. It is not supported by HTML 5. Syntax: <th valign="top | middle | bottom | baseline"> Attribute Value: top: It sets the table header content to top-align. middle: It sets the table header content to middle-align. bottom: It sets th 1 min read HTML | <col> align Attribute The HTML <col> align Attribute is used to set the horizontal alignment of text content inside the col element. It is not supported by HTML 5. Syntax: <col align="left | right | center | justify | char"> Attribute Values: left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align. justif 1 min read HTML | poster Attribute The HTML poster Attribute is used to display the image while video downloading or when the user clicks the play button. If this image not set then it will take the first frame of video as a poster image.Applicable: It is mainly used in <video> element. Syntax: <video poster="URL"> Attribute Values: It contains a single value URL which s 1 min read HTML | <area> target Attribute The HTML <area> target Attribute is used to specify where to open the linked document. It works only when href attribute is present in the area elements. Syntax: <area target="_blank|_self|_parent|_top|framename"> Attribute Values: _blank: It opens the link in a new window._self: It is the default value. It opens the linked document in 1 min read HTML | <select> autocomplete Attribute The HTML <select> autocomplete attribute is used to specify that the form has autocompleted on or off. When the autocomplete attribute is set to on the browser will automatically complete the values based on which the user entered before. Syntax: <select autocomplete="on | off"> Attribute Values: on: It is the default value. When the au 1 min read HTML | <table> bgcolor Attribute The HTML <table> bgcolor Attribute is use to specify the background color of a table.Syntax: <table bgcolor="color_name | hex_number | rgb_number"> Attribute Values: color_name: It sets the text color by using the color name. For example "red".hex_number: It sets the text color by using the color hex code. For example "#0000ff".rgb_numb 1 min read HTML | srcdoc Attribute The HTML srcdoc attribute is used to specify the HTML content of the page to show in the inline frame. This attribute is anticipated to be used beside the sandbox and seamless attributes. If a browser supports the srcdoc attribute, it'll override the content laid out in the src attribute (if present). If a browser doesn't support the srcdoc attribu 1 min read HTML <video> crossorigin Attribute The HTML crossorigin attribute is used in the <video> element that supports a CORS request when we tried to fetch out the video files from the third-party servers or from another domain. Syntax: <video crossorigin="anonymous | use-credentials"> Attribute Values: anonymous: It has a default value. It defines a CORS request that will be s 1 min read HTML | Marquee truespeed attribute If the scrolldelay value less then 60 and truespeed mode is on then the value of scrolldelay is not effecting the scrolling. If the scrolldelay value more then 60 and truespeed mode is on then the truespeed is not effecting the scrolling. So, basically it is used to set scrollDelay attribute should be taken as an exact value or not.Syntax: <marq 1 min read What is the significance of adding autocomplete attribute in HTML Form ? The HTML <form> autocomplete attribute is used to specify that the form has autocompleted on or off value. When the autocomplete attribute is set to "on", the browser will automatically complete the values based on which the user entered before. Syntax: <form autocomplete="on|off"> Attribute values: on: It has a default value. When the 1 min read HTML | <td> abbr Attribute The HTML <td> abbr attribute is used to specify the shorter version of the content. This attribute is not supported by HTML 5. It does not describe any visual effect but it is used by screen readers. Syntax: <td abbr="text"> Attribute Values: text: It contains the short description of cell content. Note : This attribute is not supported 1 min read HTML reversed Attribute It is a Boolean Attribute and is used to order the list in Descending Order(9, 8, 7, 6 .....) instead of ascending order(1, 2, 3 ....). Syntax: <ol reversed> <li> Content... </li> <li> Content... </li> ... <li> Content... </li></ol>Applicable: <ol> Attributes: It includes single attributes rever 1 min read Article Tags :
  • HTML
  • Web Technologies
  • HTML-Attributes
Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Suggest changes Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes min 4 words, max CharLimit:2000

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences

Từ khóa » Html5 Video Alt Attribute