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

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

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

Older versions of HTML used `<a name="section1">` to create anchor targets within a page. HTML5 dropped this approach. The `id` attribute on any element now serves the same purpose, and it works on `<a>` tags as well as `<div>`, `<section>`, `<h2>`, or any other element. Fragment links like `href="#section1"` will scroll to whatever element has `id="section1"`, regardless of element type.

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

## Invalid example

```html
<a name="about">About us</a>

<p>Read more in our <a href="#about">about section</a>.</p>
```

## Valid example

```html
<h2 id="about">About us</h2>

<p>Read more in our <a href="#about">about section</a>.</p>
```

If the anchor wraps content that has no better semantic element, a `<span>` or `<div>` with an `id` works fine:

```html
<span id="about">About us</span>
```
