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

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

No HTML specification has defined `name` on header cells, so it has no effect on how the table renders or how assistive technology reads it. The validator reports it twice: this warning, and an error saying that the attribute is not allowed on `th` at this point. Both go away once the attribute is removed.

What to use instead depends on what the `name` was meant to do. To identify a header cell, give it an `id`. An `id` works as a link target (`page.html#year`), and data cells can point to it through their `headers` attribute. To mark a header as labeling its column or row, add `scope="col"` or `scope="row"`. To keep a value that only scripts read, move it to a `data-*` attribute such as `data-name`.

Scripts that look these cells up with `document.getElementsByName()` still find them while the attribute is there, so update them to `getElementById()` or a `[data-name]` selector when you change the markup.

## Invalid example

```html
<table>
  <tr>
    <th name="year">Year</th>
    <th name="revenue">Revenue</th>
  </tr>
  <tr>
    <td>2024</td>
    <td>1,200</td>
  </tr>
</table>
```

## Valid example

Using `id` and `scope` on the header cells, with `headers` on the data cells:

```html
<table>
  <tr>
    <th id="year" scope="col">Year</th>
    <th id="revenue" scope="col">Revenue</th>
  </tr>
  <tr>
    <td headers="year">2024</td>
    <td headers="revenue">1,200</td>
  </tr>
</table>
```

If the value is only metadata for scripts, a `data-*` attribute works:

```html
<table>
  <tr>
    <th data-name="year">Year</th>
    <th data-name="revenue">Revenue</th>
  </tr>
  <tr>
    <td>2024</td>
    <td>1,200</td>
  </tr>
</table>
```
