# Element “img” is missing one or more of the following attributes: “src”, “srcset”.

> Canonical HTML version: https://rocketvalidator.com/html-validation/element-img-is-missing-one-or-more-of-the-following-attributes-src-srcset
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

Every `<img>` element must include at least a `src` or a `srcset` attribute to be valid HTML.

The `<img>` element exists to embed an image into the document, and it needs to know *where* that image is. The `src` attribute provides a single URL for the image, while `srcset` lets you offer multiple image sources for different screen sizes or resolutions.

You might run into this error when using JavaScript to set the image source dynamically, or when using lazy-loading libraries that store the URL in a `data-` attribute like `data-src`. While those techniques work at runtime, they produce invalid HTML because the validator still expects `src` or `srcset` to be present in the markup.

If you genuinely don't have a source yet, you can use a placeholder or a transparent pixel as the `src` value.

## Invalid Example

```html
<img alt="A cute cat" loading="lazy" data-src="cat.jpg">
```

## Valid Examples

Using `src`:

```html
<img src="cat.jpg" alt="A cute cat">
```

Using `srcset`:

```html
<img srcset="cat-400.jpg 400w, cat-800.jpg 800w"
  sizes="(max-width: 600px) 400px, 800px"
  alt="A cute cat">
```

Using both `src` and a lazy-loading `data-src` (keeps the markup valid while still supporting lazy loading):

```html
<img src="placeholder.jpg" data-src="cat.jpg" alt="A cute cat">
```
