HTML Guides for embed
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The HTML specification defines the height and width attributes on the <embed> element as valid non-negative integers. This means the value must consist only of digits — for example, 650 — with no units, whitespace, or other characters appended. When you write height="650px", the validator encounters the letter "p" where it expects either another digit or the end of the value, and it raises this error.
This is a common mistake because CSS requires units (e.g., 650px), and it's easy to assume HTML attributes work the same way. They don't. In HTML, the height attribute implicitly means CSS pixels, so writing 650 already means "650 pixels." Adding px is not only redundant — it makes the value invalid.
While most browsers are forgiving and will parse 650px correctly by stripping the unit, relying on this behavior is problematic. It violates the HTML specification, causes validation errors that can mask other real issues in your markup, and there's no guarantee every browser or embedded content handler will be equally tolerant. Standards compliance ensures consistent rendering across browsers and assistive technologies.
How to fix it
You have two approaches:
Remove the unit from the HTML attribute. Change
height="650px"toheight="650". This is the simplest fix and keeps your sizing in the markup.Move sizing to CSS. Remove the
heightattribute entirely and use a stylesheet or inlinestyleattribute instead. This approach is more flexible because CSS supports units like%,em,vh, and more.
The same rule applies to the width attribute on <embed>, as well as height and width on elements like <img>, <video>, <iframe>, and <canvas> — all of which expect plain integers in HTML.
Examples
❌ Invalid: unit included in the HTML attribute
The px suffix causes the validator error because the attribute value must be digits only.
<embed src="file.pdf" type="application/pdf" width="800" height="650px">
Other invalid variations include:
<embed src="file.pdf" type="application/pdf" height="100%">
<embed src="file.pdf" type="application/pdf" height="40em">
<embed src="file.pdf" type="application/pdf" height="50vh">
✅ Fixed: plain integer without a unit
Remove the unit so the value is a valid non-negative integer.
<embed src="file.pdf" type="application/pdf" width="800" height="650">
✅ Fixed: sizing moved to CSS
If you need units other than pixels, or prefer to keep presentation in your stylesheets, use CSS instead of the HTML attribute.
<embed class="pdf-viewer" src="file.pdf" type="application/pdf">
.pdf-viewer {
width: 800px;
height: 650px;
}
✅ Fixed: inline style as an alternative
You can also use the style attribute directly if a separate stylesheet isn't practical.
<embed src="file.pdf" type="application/pdf" style="width: 800px; height: 80vh;">
This is especially useful when you need viewport-relative or percentage-based sizing that HTML attributes can't express.
The HTML specification defines the width and height attributes on <embed> as accepting only valid non-negative integers. This means bare numbers like 600 or 800 that represent dimensions in CSS pixels. When you write width="100%", the validator expects a digit character but encounters the % sign, which doesn't conform to the expected format.
This matters for several reasons. Browsers may interpret invalid attribute values inconsistently — some might ignore the percentage and fall back to a default size, while others might attempt to parse the number portion and discard the %. This leads to unpredictable rendering across different browsers and devices. Following the specification ensures your embedded content displays at predictable dimensions everywhere.
The same rule applies to the height attribute. Neither width nor height on <embed> supports units of any kind — no px, %, em, or other suffixes. Just a plain integer.
How to Fix It
You have two main approaches:
Use integer pixel values directly. Replace
width="100%"with a specific pixel value likewidth="800". This is the simplest fix when you know the desired dimensions.Use CSS for responsive or percentage-based sizing. Remove the
widthandheightattributes (or set them to reasonable defaults) and apply CSS through aclass,styleattribute, or external stylesheet. This is the better approach when you need the embed to be fluid or responsive.
Examples
Invalid — percentage in the width attribute
This triggers the validator error because 100% is not a valid non-negative integer:
<embed src="file.pdf" type="application/pdf" width="100%" height="600">
Fixed — using pixel values in attributes
Replace the percentage with a plain integer:
<embed src="file.pdf" type="application/pdf" width="800" height="600">
Fixed — using CSS for percentage-based sizing
Remove the dimension attributes and use CSS to control the size:
<embed src="file.pdf" type="application/pdf" class="embed-fluid">
.embed-fluid {
width: 100%;
height: 600px;
}
Fixed — responsive embed with a wrapper container
For a fully responsive embed that maintains an aspect ratio, wrap it in a container and use CSS:
<div class="embed-wrapper">
<embed src="file.pdf" type="application/pdf">
</div>
.embed-wrapper {
width: 100%;
max-width: 960px;
aspect-ratio: 4 / 3;
}
.embed-wrapper embed {
width: 100%;
height: 100%;
}
This approach gives you full control over sizing and responsiveness without relying on invalid HTML attributes. The aspect-ratio property ensures the container (and therefore the embed) maintains consistent proportions as it scales.
The <embed> element has no name attribute in HTML5, so identify it with id instead.
Old plugin markup, especially Flash movies wrapped in <object> and <embed>, often gave the embed a name so scripts could reach it through document.embeds["movie"] or document["movie"]. The HTML standard lists name on <embed> as obsolete. The validator reports this message together with a second one that calls the attribute obsolete and suggests id. Removing name clears both.
An id does the same job. document.getElementById("movie") returns the element, and document.embeds["movie"] also finds it by its id. A script that used the document["movie"] shortcut needs to switch to getElementById, because that shortcut does not pick up an <embed> by id. If no script or CSS refers to the name, you can delete the attribute without adding an id.
Invalid example
<embed src="intro.mp4" type="video/mp4" name="intro" width="640" height="360">
Valid example
<embed src="intro.mp4" type="video/mp4" id="intro" width="640" height="360">
Replace name on an <embed> element with id, or delete it if nothing refers to it.
The name attribute on <embed> dates from the plugin era, when pages named a Flash movie or other plugin content so a script could find it. The HTML standard lists it among the obsolete attributes and points to id as the way to identify the element. The validator reports this warning together with a second message saying that name is never allowed on <embed>. Both point at the same attribute, and the same change fixes both.
Before you rename it, search your scripts and stylesheets for the old name. Code that looked the element up by name should call document.getElementById() with the new id, and an id must be unique in the document. If no code uses the name, remove the attribute and leave the id out.
Invalid example
<embed src="sales-chart.svg" type="image/svg+xml" name="sales" width="600" height="400">
Valid example
<embed src="sales-chart.svg" type="image/svg+xml" id="sales" width="600" height="400">
<script>
const chart = document.getElementById("sales");
</script>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries