Skip to main content

HTML Guide

Bad value X for attribute “width” on element “embed”: Expected a digit but saw “%” instead.

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’s width and height content attributes accept only non-negative integers representing CSS pixels, per WHATWG HTML. A value like width="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 on embed.
    • Omit width/height and use CSS like style="width:100%; height:400px;".
    • For fully responsive aspect ratios, wrap embed in a container and size via CSS.

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