HTML Guides for non-empty
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 <link> element is used to define relationships between the current document and external resources — most commonly stylesheets, icons, and preloaded assets. The href attribute specifies the URL of that external resource, and it is the core purpose of the element. An empty href attribute makes the <link> element meaningless because there is no resource to fetch or reference.
Why This Is a Problem
Standards compliance: The HTML specification requires the href attribute on <link> to be a valid, non-empty URL. An empty string does not qualify as a valid URL, so the validator flags it as an error.
Unexpected browser behavior: When a browser encounters an empty href, it may resolve it relative to the current document's URL. This means the browser could end up making an unnecessary HTTP request for the current page itself, interpreting the HTML response as a stylesheet or other resource. This wastes bandwidth, can slow down page loading, and may trigger unexpected rendering issues.
Accessibility and semantics: An empty href provides no useful information to browsers, screen readers, or other user agents about the relationship between the document and an external resource. It adds noise to the DOM without contributing anything functional.
How to Fix It
- Provide a valid URL: If the
<link>element is meant to reference a resource, sethrefto the correct URL of that resource. - Remove the element: If no resource is needed, remove the entire
<link>element rather than leaving it with an emptyhref. - Check dynamic rendering: This issue often occurs when a templating engine or CMS outputs a
<link>element with a variable that resolves to an empty string. Add a conditional check so the element is only rendered when a valid URL is available.
Examples
❌ Incorrect: Empty href attribute
<linkrel="stylesheet"href="">
This triggers the validation error because href is empty.
❌ Incorrect: Empty href from a template
<!-- A template variable resolved to an empty string -->
<linkrel="icon"type="image/png"href="">
✅ Correct: Valid href pointing to a resource
<linkrel="stylesheet"href="/css/main.css">
✅ Correct: Valid href for a favicon
<linkrel="icon"type="image/png"href="/images/favicon.png">
✅ Correct: Remove the element if no resource is needed
<!-- Simply omit the <link> element entirely -->
✅ Correct: Conditional rendering in a template
If you're using a templating language, wrap the <link> in a conditional so it only renders when a URL is available. For example, in a Jinja2-style template:
{% if stylesheet_url %}
<linkrel="stylesheet"href="{{ stylesheet_url }}">
{% endif %}
This ensures the <link> element is never output with an empty href.
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
<iframesrc=""></iframe>
This triggers the validation error because the src value is an empty string.
❌ src attribute with only whitespace
<iframesrc=""></iframe>
Whitespace-only values are also invalid URLs and will produce the same error.
✅ Valid URL in src
<iframesrc="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
<iframesrc="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
<iframesrcdoc="<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
<divid="video-container"></div>
<script>
constiframe=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.
The src attribute on a <script> element tells the browser where to fetch an external JavaScript file. According to the HTML specification, when the src attribute is present, its value must be a valid non-empty URL. An empty string does not qualify as a valid URL, so the validator flags it as an error.
This issue typically arises in a few common scenarios:
- Templating or CMS placeholders — A template engine or content management system outputs an empty
srcwhen no script URL is configured. - Dynamic JavaScript — Client-side code is intended to set the
srclater, but the initial HTML ships with an empty value. - Copy-paste mistakes — The attribute was added in anticipation of a script file that was never specified.
Beyond failing validation, an empty src causes real problems. Most browsers interpret an empty src as a relative URL that resolves to the current page's URL. This means the browser will make an additional HTTP request to re-fetch the current HTML document and attempt to parse it as JavaScript, wasting bandwidth, slowing down page load, and potentially generating console errors. It can also cause unexpected side effects in server logs and analytics.
How to Fix It
Choose the approach that matches your intent:
- Provide a valid URL — If you need an external script, set
srcto the correct file path or full URL. - Use an inline script — If your JavaScript is written directly in the HTML, remove the
srcattribute entirely. Note that whensrcis present, browsers ignore any content between the opening and closing<script>tags. - Remove the element — If the script isn't needed, remove the
<script>element altogether.
Also keep in mind:
- Ensure the file path is correct relative to the HTML file's location.
- If using an absolute URL, verify it is accessible and returns JavaScript content.
- If a script should only be loaded conditionally, handle the condition in your server-side or build logic rather than outputting an empty
src.
Examples
❌ Invalid: Empty src attribute
<scriptsrc=""></script>
This triggers the validation error because the src value is an empty string.
❌ Invalid: Whitespace-only src attribute
<scriptsrc=""></script>
A value containing only whitespace is also not a valid URL and will produce the same error.
✅ Fixed: Valid external script
<scriptsrc="js/app.js"></script>
The src attribute contains a valid relative URL pointing to an actual JavaScript file.
✅ Fixed: Valid external script with a full URL
<scriptsrc="https://example.com/js/library.min.js"></script>
✅ Fixed: Inline script without src
If you want to write JavaScript directly in your HTML, omit the src attribute:
<script>
console.log("This is an inline script.");
</script>
✅ Fixed: Conditionally omitting the element
If the script URL comes from a template variable that might be empty, handle it at the template level so the <script> element is only rendered when a URL is available. For example, in a templating language:
<!-- Pseudocode — only output the tag when the URL exists -->
<!-- {% if script_url %} -->
<scriptsrc="analytics.js"></script>
<!-- {% endif %} -->
This prevents the empty src from ever reaching the browser.
The <source> element is used inside <video>, <audio>, and <picture> elements to specify one or more media resources for the browser to choose from. Its src attribute is defined as a valid non-empty URL, meaning it must resolve to an actual file path or web address. An empty string does not satisfy this requirement and violates the HTML specification.
Why this is a problem
Standards compliance: The WHATWG HTML living standard explicitly requires the src attribute on <source> to be a non-empty, valid URL. An empty value makes the document invalid HTML.
Unexpected browser behavior: When a browser encounters an empty src, it may attempt to resolve it relative to the current page URL. This can trigger an unnecessary HTTP request back to the current page, resulting in wasted bandwidth, unexpected server load, or confusing errors in your network logs.
Broken media playback: An empty src means the browser has no media file to load. If the <source> element is the only one provided, the media element will fail to play entirely — often without a clear indication to the user of what went wrong.
Accessibility concerns: Screen readers and assistive technologies rely on well-formed HTML. Invalid markup can lead to unpredictable behavior or missed content announcements for users who depend on these tools.
How to fix it
- Provide a valid URL — Set the
srcattribute to the correct path or URL of your media file. - Remove the element — If the media source is not yet available or is being set dynamically via JavaScript, remove the
<source>element from the HTML entirely and add it later through script when the URL is known. - Check for template or CMS issues — This error often appears when a CMS or templating engine outputs a
<source>tag with an empty variable. Ensure your template conditionally renders the element only when a valid URL exists.
Examples
Incorrect: empty src on <source> in a video
<videocontrols>
<sourcesrc=""type="video/mp4">
Your browser does not support the video tag.
</video>
Correct: valid URL in src
<videocontrols>
<sourcesrc="movie.mp4"type="video/mp4">
Your browser does not support the video tag.
</video>
Incorrect: empty src on <source> in a picture element
<picture>
<sourcesrc=""type="image/webp">
<imgsrc="photo.jpg"alt="A sunset over the ocean">
</picture>
Note that <source> inside <picture> uses srcset, not src. This example is doubly wrong — the attribute is both empty and incorrect. Here is the fix:
Correct: using srcset with a valid URL in a picture element
<picture>
<sourcesrcset="photo.webp"type="image/webp">
<imgsrc="photo.jpg"alt="A sunset over the ocean">
</picture>
Incorrect: multiple sources with one empty src
<audiocontrols>
<sourcesrc="song.ogg"type="audio/ogg">
<sourcesrc=""type="audio/mpeg">
</audio>
Correct: remove the source if no file is available
<audiocontrols>
<sourcesrc="song.ogg"type="audio/ogg">
<sourcesrc="song.mp3"type="audio/mpeg">
</audio>
Correct: conditionally add sources with JavaScript
If the URL is determined at runtime, avoid placing an empty <source> in your markup. Instead, add it dynamically:
<videoid="player"controls>
Your browser does not support the video tag.
</video>
<script>
constvideoUrl=getVideoUrl();// your logic here
if(videoUrl){
constsource=document.createElement("source");
source.src=videoUrl;
source.type="video/mp4";
document.getElementById("player").appendChild(source);
}
</script>
This approach keeps your HTML valid at all times and only inserts a <source> element when a real URL is available.
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.
Pro Trial
Full Pro access. Cancel anytime.
Start Pro Trial →Join teams across 40+ countries