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

> Canonical HTML version: https://rocketvalidator.com/html-validation/the-name-attribute-is-never-allowed-on-the-img-element
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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

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

## Valid example

```html
<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")`.
