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

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

The `name` attribute is not a valid attribute for the `<span>` element in HTML.

The `name` attribute exists on specific elements like `<a>`, `<form>`, `<input>`, `<map>`, `<meta>`, `<iframe>`, `<object>`, and `<param>`. It was never part of the `<span>` element's specification. In older HTML practices, `<a name="section">` was used to create anchor targets within a page, and some developers incorrectly applied the same pattern to `<span>` elements.

To create an anchor target on a `<span>` or any other element, use the `id` attribute instead. The `id` attribute is a global attribute, valid on every HTML element, and works as a fragment identifier in URLs (e.g., `page.html#section-name`).

If the `name` attribute was being used for JavaScript targeting or styling, switch to `id`, `class`, or `data-*` attributes depending on the use case.

## Invalid example

```html
<span name="intro">Welcome to the site.</span>
```

## Valid examples

Use `id` to create a linkable anchor target:

```html
<span id="intro">Welcome to the site.</span>
```

Use `class` when multiple elements share the same label:

```html
<span class="intro">Welcome to the site.</span>
```

Use a `data-*` attribute for custom metadata consumed by JavaScript:

```html
<span data-name="intro">Welcome to the site.</span>
```
