Skip to main content

HTML Guide

Bad value “auto” for attribute “width” on element “img”: Expected a digit but saw “a” instead.

The width attribute on the img element must be a positive integer representing the number of pixels.

The HTML img element’s width and height attributes are expected to specify image dimensions in pixels. According to the HTML Living Standard, these attributes accept only non-negative integers. These integers define the rendered dimension of the image, overriding the actual image size based on its native resolution. The value “auto” is not a valid integer, which leads to the validation error you’ve encountered.

Here is a correct usage example of the img element:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Valid Image Width</title>
</head>
<body>
  <img src="example.jpg" alt="Example image" width="200" height="100">
</body>
</html>

In the example above, the width is set to 200, and the height is set to 100. Both values are non-negative integers representing pixel dimensions. If you intend to maintain the image’s aspect ratio while adjusting another dimension, you can omit one of the attributes, and modern browsers will automatically adjust the aspect ratio based on the given dimension.

Learn more:

Related W3C validator issues