About This HTML Issue
The HTML specification defines the width attribute on <video> as a “valid non-negative integer,” which means it must consist only of digits (e.g., 640). It cannot include units like px, em, or %. When you write something like width="100%", the validator expects a digit character but encounters the % sign, producing this error.
This is a common mistake because CSS allows percentage values for width, and some older HTML elements (like <table>) historically accepted percentage values in their width attributes. However, the <video> element follows the modern HTML specification, which restricts width to pixel integers only.
Why this matters
-
Standards compliance: Browsers may interpret invalid attribute values unpredictably. While most modern browsers might ignore the
%and attempt to parse the number, this behavior is not guaranteed. -
Responsive design intent is lost: Even if a browser tries to handle
width="100%", it may treat it aswidth="100"(100 CSS pixels), which is almost certainly not what you intended. - Accessibility and consistency: Valid markup ensures assistive technologies and all browsers render your content as expected.
How to fix it
If you need a fixed pixel width, set the width attribute to a plain integer. If you need a responsive or percentage-based width, remove the width attribute entirely and use CSS.
Examples
❌ Invalid: percentage value in the width attribute
<video controls width="100%">
<source src="/media/video.mp4" type="video/mp4">
</video>
✅ Fixed: using a pixel integer for a fixed width
<video controls width="640" height="360">
<source src="/media/video.mp4" type="video/mp4">
</video>
✅ Fixed: using CSS for a percentage-based width
<video controls style="width: 100%;">
<source src="/media/video.mp4" type="video/mp4">
</video>
✅ Fixed: using an external stylesheet for responsive video
<style>
.responsive-video {
width: 100%;
max-width: 800px;
height: auto;
}
</style>
<video controls class="responsive-video">
<source src="/media/video.mp4" type="video/mp4">
</video>
The CSS approach is generally preferred for responsive layouts because it gives you much more control — you can combine width, max-width, and height: auto to create a video that scales proportionally within its container. The width and height HTML attributes are best used when you want to specify the video’s intrinsic dimensions in pixels, which also helps the browser reserve the correct amount of space before the video loads, reducing layout shifts.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.