HTML Guide
embed
does not allow percentage values for the width
(or height
) attribute; only non-negative integers in CSS pixels are valid.
Explanation
-
The
embed
element’swidth
andheight
content attributes accept only non-negative integers representing CSS pixels, per WHATWG HTML. A value likewidth="100%"
is invalid. -
To make an embedded resource responsive or percentage-based, set numeric pixel values in attributes (or omit them) and control sizing with CSS using the
style
attribute or external stylesheets. -
Valid approaches:
-
Use
width="600"
(pixels) directly onembed
. -
Omit
width
/height
and use CSS likestyle="width:100%; height:400px;"
. -
For fully responsive aspect ratios, wrap
embed
in a container and size via CSS.
-
Use
HTML examples
Invalid example (reproduces the validator error)
<!doctype html>
<html lang="en">
<head>
<title>Invalid embed width</title>
</head>
<body>
<embed src="file.pdf" type="application/pdf" width="100%" height="600"></embed>
</body>
</html>
Fixed example (valid pixels in attributes, or CSS for percentage)
<!doctype html>
<html lang="en">
<head>
<title>Valid embed width</title>
<style>
.embed-fluid {
width: 100%;
height: 600px;
max-width: 800px; /* optional */
}
</style>
</head>
<body>
<!-- Option A: pixel attributes -->
<embed src="file.pdf" type="application/pdf" width="800" height="600"></embed>
<!-- Option B: CSS controls percentage width -->
<embed src="file.pdf" type="application/pdf" class="embed-fluid"></embed>
</body>
</html>
Learn more:
Related W3C validator issues
The width and height attributes on <img> elements expect a digit to specify the dimension in pixels. It should not contain units, letters or percent signs.
You can achieve this using CSS instead, for example:
<!-- Invalid syntax, the height attribute expects only digits -->
<img src="photo.jpg" alt="cat" height="auto" />
<!-- Valid syntax using CSS -->
<img src="photo.jpg" alt="cat" style="height: auto" />
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.
The error message is indicating that the width attribute of the <video> element has an invalid value. According to the HTML specification, the width attribute expects a non-negative integer value, representing the pixel width of the video.
The value "auto" is not valid for the width attribute. Instead, specify a full number that indicates the pixel width of the video. If you want the video to be responsive without specifying a fixed width, you can use CSS to achieve that.
Here are two ways to resolve this:
-
Specify a valid pixel value for width:
<video width="640" height="360" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
-
Use CSS for a responsive video player:
Instead of using the width attribute, use CSS to set the width of the video element. This allows the video to adjust its size according to the container or viewport.
<style> .responsive-video { width: 100%; height: auto; } </style> <video class="responsive-video" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
In the second example, the video will scale based on its containing element, maintaining its aspect ratio due to the height: auto; CSS rule. This approach offers more flexibility for responsive design.
The sizes attribute is used to complement the srcset attribute on an <img> tag for responsive images. When this attribute is present, all image candidates must specify its width.
The attributes width and height of <iframe> elements expect a non-negative integer, so an empty string is not allowed. Either define the correct dimension, or remove this attribute.
The attributes width and height of <img> elements expect a non-negative integer, so an empty string is not allowed. Either define the correct dimension, or remove this attribute.
Remove the unit; height on embed expects a non-negative integer (pixels) or a valid CSS length only when set via CSS, not the HTML attribute.
Detailed explanation
The embed element supports the presentational attributes width and height as unsigned integers representing CSS pixels. In HTML, the height attribute must be a number without a unit, for example 650. Supplying 650px violates the attribute’s value syntax and triggers the validator error.
If you want to use units or other CSS lengths (e.g., px, em, %, vh), set them with CSS via the style attribute or a stylesheet using the height property, not the HTML attribute.
HTML examples
Example reproducing the issue
<!DOCTYPE html>
<html lang="en">
<head>
<title>Embed height invalid</title>
</head>
<body>
<embed src="file.pdf" type="application/pdf" width="800" height="650px">
</body>
</html>
Corrected example (HTML attribute as integer)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Embed height fixed</title>
</head>
<body>
<embed src="file.pdf" type="application/pdf" width="800" height="650">
</body>
</html>
Alternative corrected example (use CSS units)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Embed height via CSS</title>
<style>
.viewer { width: 800px; height: 650px; }
</style>
</head>
<body>
<embed class="viewer" src="file.pdf" type="application/pdf">
</body>
</html>
The srcset attribute requires a width descriptor (w) or pixel density descriptor (x) for each image candidate when the sizes attribute is present.
When using the sizes attribute on an img element, each entry in srcset must include either a width descriptor (e.g., 860w) or a pixel density descriptor (e.g., 2x). This tells browsers how to select the most appropriate image source for the current viewport or display density. Omitting the descriptor leads to HTML validation errors and unexpected image selection.
Correct usage with width descriptors:
<img
alt=""
sizes="(min-width:568px) 140px"
srcset="photo.png?w=860&q=90 860w"
src="photo.png?w=860&q=90">
Correct usage with pixel density descriptors (if sizes is removed):
<img
alt=""
srcset="photo.png?w=860&q=90 2x"
src="photo.png?w=860&q=90">
Key points:
- With sizes, use width descriptors (e.g., 860w).
- Without sizes, you may use pixel density descriptors (e.g., 2x).
- Always use either px or w units in the sizes attribute values; do not use w.
The sizes attribute is used to complement the srcset attribute on an <img> tag for responsive images. When this attribute is present, all image candidates must specify its width.
The attributes width and height on an iframe expect a valid positive integer without any decimals.
Here’s an example of incorrect code where decimals are being used for dimension attributes:
<iframe src="example.html" height="602.88" width="800.2"></iframe>
Corrected code without decimals:
<iframe src="example.html" height="603" width="800"></iframe>
In the corrected code, the width and height values has been changed to a whole number, which conforms to the standard integer value expected by the W3C validator.