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

> Canonical HTML version: https://rocketvalidator.com/html-validation/the-name-attribute-is-never-allowed-on-the-div-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 `<div>` element.

The `name` attribute is only allowed on specific HTML elements that have a defined use for it, such as `<input>`, `<form>`, `<iframe>`, `<object>`, `<map>`, `<select>`, `<textarea>`, and `<meta>`. On these elements, `name` serves a purpose: identifying form data sent to a server, targeting frames, or referencing image maps.

The `<div>` element does not accept `name`. If the goal is to identify or reference a `<div>`, use the `id` attribute instead. The `id` attribute is a global attribute, valid on any HTML element, and provides a unique identifier for styling with CSS, targeting with JavaScript, or linking with fragment URLs.

If the `name` attribute was being used as a hook for `document.getElementsByName()`, switching to `id` with `document.getElementById()` (or using a `class` with `document.querySelectorAll()`) is the correct approach.

## Invalid example

```html
<div name="sidebar">
  <p>Some content</p>
</div>
```

## Valid example

```html
<div id="sidebar">
  <p>Some content</p>
</div>
```
