Skip to main content
HTML Validation

The “name” attribute on the “img” element is obsolete. Use the “id” attribute instead.

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 with id="myImage".
  • The remaining attributes like src and alt are 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.

Last reviewed: March 31, 2025

Was this guide helpful?

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Ready to validate your sites?
Start your free trial today.