# The “name” attribute on the “a” element is obsolete. Consider putting an “id” attribute on the nearest container instead.

> Canonical HTML version: https://rocketvalidator.com/html-validation/the-name-attribute-on-the-a-element-is-obsolete-consider-putting-an-id-attribute-on-the-nearest-container-instead
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `name` attribute on `<a>` elements is obsolete in HTML5 and should be replaced with the `id` attribute.

In older versions of HTML, the `name` attribute on anchor elements was used to create fragment identifiers — targets you could link to with `#section-name` in a URL. In HTML5, this approach has been deprecated in favor of the `id` attribute, which can be placed on any element, not just `<a>` tags.

Using `id` is more flexible because you can turn any element into a link target directly, without wrapping it in an anchor. The `id` attribute works the same way for fragment navigation: a link pointing to `#section-name` will scroll to the element with `id="section-name"`.

## HTML Examples

### ❌ Obsolete usage with `name`

```html
<a name="about"></a>
<h2>About Us</h2>
<p>Welcome to our site.</p>

<a href="#about">Go to About</a>
```

### ✅ Fixed using `id`

```html
<h2 id="about">About Us</h2>
<p>Welcome to our site.</p>

<a href="#about">Go to About</a>
```

The `id` attribute is placed directly on the `<h2>` heading, eliminating the need for an empty `<a>` tag entirely. The `#about` link works exactly the same way.
