HTML img tag contains alt attribute. This attribute specifies the information about the image like image name, image link, image author, image specification, etc. The main purpose of this attribute is when the internet connection is slow, the image may not load but is loaded without any problem. So instead of the user go back from them, if the user moved his cursor from the page, it would display some text regarding the image; therefore, he can understand that there is some content on this page and wait for some time until the page is loaded.
Real-Time Scenario: While we are displaying any image on the web, it is not fair to the end-user without knowing what the image is about. So we have to specify some content to the image by using the alt attribute.
How does Alt Attribute work in HTML?
Alt Attribute provides alternative information for the image to recognize what the image is meant for. This attribute allows only text. This attribute available in tags:
This 3 tags alt attribute is only for showing text on top of the image.
Syntax #1 – tag
<img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="text">
Syntax #2 – tag
<img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="text" usemap="#name"> //usemap name and map name attribute name must be same <map name="name"> <area coords="specify 4 coordinates" href="file.htm" alt="text"> </map> <input> tag
Syntax #3 – tag
<input type="image" alt="text">
Examples to Implement Alt Tag in HTML
below are the examples mentioned:
Example #1
Code:
<meta charset="ISO-8859-1"> <title>Alt Attribute</title> <style type="text/css"> h1 { color: blue; text-align: center; } p { color: fuchsia; font-size: 20px; border: 2px solid red; } /*Aligning images side by side*/ * { box-sizing: border-box; } .column { width: 33.33%; padding: 5px; float: left; } .row::after { clear: both; display: table; content: ""; } </style> <h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1> <p>HTML img tag contains alt attribute. This attributes specifies the information about the image like image name, image link, image author, image specification etc. The main purpose of this attribute is when the internet connection is slow the image may not load but is loaded without any problem. So instead of user go back from the if user moved his cursor from the page it will display some text regarding image therefore he can understand that there is some content in this page and wait for some time until page is loaded.</p> <h1 id="Images-with-img-tag-and-alt-attribute">Images with img tag and alt attribute</h1> <div class="row"> <div class="column"> <img src="/static/imghwm/default1.png" data-src="3.jpg" class="lazy" alt="First Bird" style="max-width:90%"> </div> <div class="column"> <img src="/static/imghwm/default1.png" data-src="4.jpg" class="lazy" alt="Second Bird" style="max-width:90%"> </div> <div class="column"> <img src="/static/imghwm/default1.png" data-src="5.jpg" class="lazy" alt="Third Bird" style="max-width:90%"> </div> </div>
Output:
If image resource is available:
If image resource is not available:
Example #2
Code:
<meta charset="ISO-8859-1"> <title>Alt Attribute</title> <style type="text/css"> h1 { color: green; text-align: center; } p { color: navy; font-size: 20px; border: 2px solid orange; } </style> <h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1> <p>HTML img tag contains alt attribute. This attributes specifies the information about the image like image name, image link, image author, image specification etc. The main purpose of this attribute is when the internet connection is slow the image may not load but is loaded without any problem. So instead of user go back from the if user moved his cursor from the page it will display some text regarding image therefore he can understand that there is some content in this page and wait for some time until page is loaded.</p> <h1 id="Images-with-area-tag-and-alt-attribute">Images with area tag and alt attribute</h1> <img src="/static/imghwm/default1.png" data-src="d2.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="Alt Tag in HTML" usemap="#dog"> <map name="dog"> <area shape="rect" coords="0,0,81,125" href="https://www.educba.com/category/software-development/software-development-tutorials/python-tutorial/" alt="Python"> <area shape="circle" coords="91,59,4" href="https://www.educba.com/category/software-development/software-development-tutorials/java-tutorial/" alt="Java"> <area shape="circle" coords="125,59,9" href="https://www.educba.com/category/software-development/software-development-tutorials/bootstrap-tutorial/" alt="Bootstrap"> </map>
Output:
If image resource is available:
If image resource is not available:
Example #3
Code:
<meta charset="ISO-8859-1"> <title>Alt Attribute</title> <style type="text/css"> h1 { color: green; text-align: center; } p { color: navy; font-size: 20px; border: 2px solid orange; } label, input { color: green; font-size: 20px; } </style> <h1 id="Alt-Attribute-Introduction">Alt Attribute Introduction</h1> <p>HTML img tag contains alt attribute. This attributes specifies the information about the image like image name, image link, image author, image specification etc. The main purpose of this attribute is when the internet connection is slow the image may not load but is loaded without any problem. So instead of user go back from the if user moved his cursor from the page it will display some text regarding image therefore he can understand that there is some content in this page and wait for some time until page is loaded.</p> <h1 id="Images-with-input-tag-and-alt-attribute">Images with input tag and alt attribute</h1>
Output:
If image resource is available:
If image resource is not available:
Conclusion
Alt is an attribute available in area, img and input tags. This alt attribute is used to provide information about images like what is an image or image coordinates, image author, etc.
The above is the detailed content of Alt Tag in HTML. For more information, please follow other related articles on the PHP Chinese website!

HTMLtagsareessentialforstructuringwebpages,enhancingaccessibility,SEO,andperformance.1)Theyareenclosedinanglebracketsandusedinpairstocreateahierarchicalstructure.2)SemantictagslikeandimproveuserexperienceandSEO.3)Creativetagslikeenabledynamicgraphics

Self-closingtagsinHTMLandXMLaretagsthatclosethemselveswithoutneedingaseparateclosingtag,simplifyingmarkupstructureandenhancingcodingefficiency.1)TheyareessentialinXMLforelementswithoutcontent,ensuringwell-formeddocuments.2)InHTML5,usageisflexiblebutr

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
