About This HTML Issue
The src attribute on an <iframe> tells the browser which document to load and display within the embedded frame. When you leave this attribute empty (src=""), the W3C HTML Validator reports an error because the HTML specification requires the value to be a valid, non-empty URL. An empty string doesn’t resolve to a meaningful resource.
This is more than a cosmetic validation issue. When a browser encounters src="", it typically interprets the empty string as a relative URL pointing to the current page, which causes the browser to re-fetch and embed the current document inside itself. This leads to unnecessary network requests, potential performance degradation, and unexpected rendering behavior. In some cases it can even cause infinite nesting loops or break page functionality.
From an accessibility standpoint, an empty <iframe> with no valid source provides no meaningful content to assistive technologies. Screen readers may announce the frame without being able to describe its purpose, creating a confusing experience for users.
How to fix it
-
Provide a valid URL: Set the
srcattribute to the actual URL of the content you want to embed. -
Use
about:blankfor intentionally empty frames: If you need an<iframe>in the DOM but don’t have content to load yet (e.g., you plan to populate it later via JavaScript), usesrc="about:blank". This is a valid URL that loads a blank page without triggering extra requests. -
Remove the element: If the
<iframe>isn’t needed, remove it from the markup entirely. You can dynamically create and insert it with JavaScript when you have content to load. -
Use
srcdocinstead: If you want to embed inline HTML rather than loading an external URL, use thesrcdocattribute, which accepts an HTML string directly.
Examples
❌ Empty src attribute
<iframe src=""></iframe>
This triggers the validation error because the src value is an empty string.
❌ src attribute with only whitespace
<iframe src=" "></iframe>
Whitespace-only values are also invalid URLs and will produce the same error.
✅ Valid URL in src
<iframe src="https://example.com/map.html" title="Location map"></iframe>
A fully qualified URL is the most straightforward fix. Note the title attribute, which is recommended for accessibility so that assistive technologies can describe the frame’s purpose.
✅ Using about:blank for a placeholder frame
<iframe src="about:blank" title="Dynamic content area"></iframe>
This is a valid approach when you need the <iframe> in the DOM but plan to set its content later with JavaScript using contentDocument.write() or by updating the src attribute dynamically.
✅ Using srcdoc for inline content
<iframe srcdoc="<p>Hello, embedded world!</p>" title="Inline content"></iframe>
The srcdoc attribute lets you embed HTML directly without needing an external URL. When srcdoc is present, it takes priority over src.
✅ Dynamically creating the iframe with JavaScript
<div id="video-container"></div>
<script>
const iframe = document.createElement("iframe");
iframe.src = "https://example.com/video.html";
iframe.title = "Video player";
document.getElementById("video-container").appendChild(iframe);
</script>
If the source URL isn’t available at page load, creating the <iframe> dynamically avoids having an empty src in your HTML altogether.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.