- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - alt Attribute
HTML alt attribute is used within an img element to provide a textual description of the image, which is displayed if the image fails to load.
When the alt attribute is used correctly, everyone can understand the information and context of images on web sites, including individuals with disabilities or slow internet connections. It's crucial for search engine optimization, inclusive design, and web accessibility.
Syntax
<tag alt = "value"></tag>
Applies On
Below listed elements allow using of the HTML alt attribute.
Element | Description |
---|---|
<img> | HTML <img> tag is used to append images in document |
<area> | HTML <area> element in HTML is used to define a clickable area within an image map. |
<input> | HTML <input> element in HTML is used to input text. |
Examples of HTML alt attribute
The following codes describe various usage ways of alt tag.
Alt attribute with img Element
The below code show how alt attribute can be used with img tag. In first case image is displayed without any error, but in second case alternate text is displayed as image is not found in specified location.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'alt' attribute</title> <style> img { width: 300px; height: 100px; } </style> </head> <body> <!--HTML 'alt' attribute--> <p>Example of the HTML 'alt' attribute</p> <p>Image without any error</p> <img src="https://www.tutorialspoint.com/images/logo.png?v3" alt="Tutorialpoint logo"> <br> <p>Images with error</p> <img src="Asset-2PP_.png" alt="Tutorialpoint logo"> </body> </html>
Alt attribute with input Element
Considering the another scenario, where we are going to use the alt attribute with the input type=image.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'alt' attribute</title> <style> img { width: 300px; height: 50px; } </style> </head> <body> <!--HTML 'alt' attribute--> <p>Example of the HTML 'alt' attribute</p> <p>Image with an error</p> <input type="image" src="download1.png" alt="Tutorialspoint old logo"> <p>Image without any error</p> <input type="image" src="https://www.tutorialspoint.com/images/logo.png?v3" alt="Tutorialspoint logo"> </body> </html>
Alt attribute with area Element
Let's look at the following example, where we are going to use the alt attribute with the area tag. The below code will generate an output consisting of the images displayed on the webpage. When the user clicks on the image it displays its alt text.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'alt' attribute</title> </head> <body> <!--HTML 'alt' attribute--> <p>Example of the HTML 'alt' attribute</p> <!--<img src="images (1).png" usemap="#sep" width = "400" height="379">--> <img src="images (1).png" alt="HTML CSS JS logo" usemap="#sep" width="200" height="200"> <map name="sep"> <area shape="circle" coords="30,44,270,350" alt="HTML logo" href="html logo.html"> </map> </body> </html>
HTML logo.html file Code
<!DOCTYPE html> <html lang="en"> <head> <title>HTML</title> </head> <body> <img src="html log.jpg" alt="HTML logo"> </body> </html>
Supported Browsers
Attribute | |||||
---|---|---|---|---|---|
alt | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google