What is Longdesc in HTML ?
Generally, we use alt text to describe the image. Sometimes, we need to provide longer descriptions of images, and in this situation, alt text may not be able to provide proper space. The longdesc attribute is the solution to this problem. We have to provide the link or URL of the web page which contains a description of the image as a value of the longdesc attribute.
We can use the longdesc attribute inside the IMG, iframe and, frame elements. It can be used inside the IMG element, instead of alt text. We can use it inside the HTML iframe element, as a complement to the title attribute. However, the longdesc attribute doesn’t support most browsers as it is removed from HTML5.
<img src="Image_path_URL" longdesc="URL or data URI">
Attribute values: It takes a URL or data URI as a value of the longdesc attribute.
- Full URL: It’s a URL of external resources.
- Relative URL: It’s a link to internal resources.
- ID-based URL: To point out any element on the same page using the id.
- Data URI: encoded version of actual content.
In HTML 5, we can use the <a> tag to provide links to the external or internal resources of the image. It is the best alternative to longdesc and is supported by all browsers.
<a herf="image_description_URL"> <img src="image_path_URL"> </a>