HTML Guides for data uri
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.
A data: URI in the src attribute of an <img> element can't contain a raw <, so inline SVG markup in that URI needs its angle brackets written as %3C and %3E.
A data: URI puts the file itself inside the URL, and everything after the comma has to be made of URL characters. Angle brackets, spaces and double quotes aren't. The validator stops at the first illegal character, which in inline SVG is the < that opens the <svg> tag. The ta: in the message is just the end of data:. The validator quotes the scheme, not the spot where the bad character sits.
This markup often comes from lazy-loading scripts. An empty SVG with only width and height sits in src as a placeholder that reserves the image's box, while the real file waits in data-src or data-srcset. Browsers usually render the placeholder anyway, but the value is still an invalid URL.
Encoding only the angle brackets isn't enough: the validator then reports the first space. Write < as %3C, > as %3E and each space as %20, and use single quotes inside the SVG or encode double quotes as %22. Also remove the ;utf8 after the media type, or write it as ;charset=utf-8. Once the brackets are encoded, the validator rejects a parameter with no value. In JavaScript, encodeURIComponent() produces a valid string, and a base64-encoded SVG with ;base64 before the comma avoids the problem too.
Invalid example
<img src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='200'></svg>" data-src="photo.jpg" alt="Product photo">
Valid example
<img src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='300'%20height='200'%3E%3C/svg%3E" data-src="photo.jpg" alt="Product photo">
A data: URI in the src attribute of an <img> element can't contain literal spaces, so an inline SVG in that URI needs every space written as %20.
The data: scheme, defined in RFC 2397, puts the file itself in the attribute value. The data after the comma may only contain URL characters, and a space isn't one of them. The ta: in the message is the end of data:. The validator quotes the scheme rather than the position of the space, so the space can be anywhere in the value.
Inline SVG is the usual cause. SVG markup needs a space between the element name and each attribute, as in <svg xmlns='...' width='300'>, and encoding the angle brackets as %3C and %3E leaves those spaces alone. A common case is an empty SVG with only width and height, used as a placeholder that holds the image's box until the real file loads.
Browsers usually render the image anyway, but the value is still an invalid URL. Replace every space with %20, or base64-encode the SVG and add ;base64 before the comma. In JavaScript, encodeURIComponent() converts the spaces to %20, along with the angle brackets and double quotes. If the SVG is large or reused, save it as a file and point src at that file.
Invalid example
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='200'/%3E" alt="">
Valid examples
<img src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='300'%20height='200'/%3E" alt="">
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMDAiIGhlaWdodD0iMjAwIi8+" alt="">
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