Skip to main content
HTML Validation

The “name” attribute is never allowed on the “img” element.

About This HTML Issue

The name attribute on the <img> element is obsolete in HTML5 and must be replaced with the id attribute.

Older pages used <img name="logo"> so scripts could reach the image through document.images["logo"], a pattern common in pre-DOM rollover scripts. HTML5 dropped the attribute. An id serves the same purpose: document.getElementById("logo") finds the image, and document.images also indexes images by their id.

The name attribute is still valid on elements like <input>, <form>, <meta>, and <map>, where it has a distinct function. On <img>, though, it has no valid use in modern HTML.

Invalid example

<img src="logo.png" name="logo" alt="Acme logo">

Valid example

<img src="logo.png" id="logo" alt="Acme logo">

Any script that referenced the image as document.images["logo"] keeps working with the id in place, or can switch to document.getElementById("logo").

Find issues like this automatically

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

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries