- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- 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 - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- 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 Code Builder
- HTML References
- 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
The HTML alt attribute is essential for supplying alternative text for images, facilitating accessibility, and improving user experience. When the image cannot be rendered or by screen readers for users who has vision issues, it is used to describe the image's content, function, or purpose.
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
Following is the syntax of alt attribute −
<tag alt = "value"></tag>
Where value can any alternate information about the current image.
Example
In the following example, we are going to use the alt attribute with the imag tag.
<!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>
When we run the above code, it will generate an output consisting of the image along with the alt text displayed on the webpage.
Example
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 wihtout any error</p> <input type="image" src="https://www.tutorialspoint.com/images/logo.png?v3" alt="Tutorialspoint logo"> </body> </html>
On running the above code, the output window will pop up displaying the alte text along with a image on the webpage.
Example
Let's look at the following example, where we are going to use the alt attribute with the area tag.
<!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>
When we run the above code, it will generate an output consisting of the images displayed on the webpage. when the user clicks on the image it displays its alt text.
To Continue Learning Please Login
Login with Google