About This HTML Issue
The warning regarding the use of the name attribute on the img element arises because the name attribute is considered obsolete in modern HTML. Historically, name was used to identify form controls and some other elements, but now it’s replaced by more standardized attributes like id.
To resolve this issue, replace the name attribute with the id attribute. The id attribute provides a unique identifier for the element within the document, which can be utilized for styling, scripting, or linking using fragment identifiers.
Here is an example of how to make this change:
HTML with obsolete name attribute:
<img src="example.jpg" name="myImage" alt="Descriptive text">
Updated HTML using the id attribute:
<img src="example.jpg" id="myImage" alt="Descriptive text">
In this modification:
-
The
name="myImage"is replaced withid="myImage". -
The remaining attributes like
srcandaltare retained for specifying the image source and providing alternative text, respectively.
The id attribute should be unique within the document, which ensures that JavaScript or CSS can target the element efficiently.
Learn more:
Last reviewed: March 31, 2025
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.