# Element X is missing required attribute Y.

> Canonical HTML version: https://rocketvalidator.com/html-validation/element-x-is-missing-required-attribute-y
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

Required attributes exist because they provide information that is fundamental to the element's purpose. For example, an `<img>` element without a `src` attribute has no image to display, and without an `alt` attribute, assistive technologies have no fallback text to describe the image. A `<link>` element without `rel` gives the browser no way to understand the relationship of the linked resource. When you omit a required attribute, several things can go wrong:

- **Accessibility issues**: Screen readers and other assistive technologies depend on specific attributes to convey meaning. A missing `alt` on `<img>` leaves visually impaired users without any description of the content.
- **Broken functionality**: Some elements simply won't work without their required attributes. A `<form>` with an `<input>` that's missing a `type` attribute may still render (browsers default to `type="text"`), but other elements like `<map>` without `name` won't function as intended.
- **Standards non-compliance**: Omitting required attributes produces invalid HTML, which can lead to unpredictable rendering across different browsers.

To fix this issue, identify which attribute is missing from the element flagged by the validator, then add it with an appropriate value. Here are common elements and their required attributes:

| Element    | Required Attribute(s)          |
|------------|-------------------------------|
| `<img>`    | `src`, `alt`                  |
| `<link>`   | `rel`                         |
| `<script>` | `src` (if no inline content)  |
| `<input>`  | `type` (recommended)          |
| `<meta>`   | `charset`, `name`, or `http-equiv` (at least one) |
| `<map>`    | `name`                        |
| `<bdo>`    | `dir`                         |
| `<style>`  | None in HTML5, but `type` was required in HTML4 |

## Examples

### Missing `alt` attribute on `<img>`

This is one of the most common validation errors. The `alt` attribute is required on every `<img>` element.

❌ **Incorrect** — missing `alt` attribute:

```html
<img src="photo.jpg">
```

✅ **Correct** — `alt` attribute provided:

```html
<img src="photo.jpg" alt="A sunset over the ocean">
```

If the image is purely decorative and carries no meaningful content, use an empty `alt` attribute:

```html
<img src="decorative-border.png" alt="">
```

### Missing `rel` attribute on `<link>`

The `rel` attribute tells the browser what the linked resource is for.

❌ **Incorrect** — missing `rel` attribute:

```html
<link href="styles.css">
```

✅ **Correct** — `rel` attribute provided:

```html
<link rel="stylesheet" href="styles.css">
```

### Missing `name` attribute on `<map>`

The `<map>` element requires a `name` attribute so it can be referenced by an `<img>` element's `usemap` attribute.

❌ **Incorrect** — missing `name` attribute:

```html
<map>
  <area shape="rect" coords="0,0,100,100" href="/section" alt="Section">
</map>
```

✅ **Correct** — `name` attribute provided:

```html
<map name="navigation">
  <area shape="rect" coords="0,0,100,100" href="/section" alt="Section">
</map>
<img src="nav.png" alt="Site navigation" usemap="#navigation">
```

### Missing `dir` attribute on `<bdo>`

The `<bdo>` (bidirectional override) element exists specifically to override text direction, so the `dir` attribute is essential.

❌ **Incorrect** — missing `dir` attribute:

```html
<p>The word in Arabic is <bdo>مرحبا</bdo>.</p>
```

✅ **Correct** — `dir` attribute provided:

```html
<p>The word in Arabic is <bdo dir="rtl">مرحبا</bdo>.</p>
```

When you encounter this validation error, read the validator message carefully — it will tell you exactly which element and which attribute is missing. Add the attribute with a meaningful value appropriate to your content, and revalidate to confirm the issue is resolved.
