Data URI Validator
Check whether text is a valid data URI as you type it, right in your browser, without sending it anywhere.
Input
Output
No value
Guide
What is a data URI?
A data URI, also called a data URL, carries a small file inside the link itself instead of pointing to it. It starts with data:, then an optional media type and parameters, a comma and the content: data:text/plain;charset=utf-8,Hello%20there holds a line of text, while data:image/png;base64, followed by Base64 text holds a whole picture. The general pattern is data:[media type][;name=value][;base64],content. Without a media type, the content counts as plain text.
Web developers use data URIs to put small icons and images right into HTML and CSS, so a page needs fewer downloads, and a canvas element's toDataURL() hands its picture over as one. You check one when an embedded image doesn't show up, or before your app saves data URIs that people send.
Tool description
Paste a data URI into the Data URI box, and the result shows as you type: "Data URI is valid" or "Data URI is not valid". Spaces and line breaks around it are ignored, and Base64 text broken over several lines passes too. The page has no settings.
What the check looks at
data:at the start, in small letters:DATA:fails- A comma after the header:
data:alone fails, whiledata:,(an empty text) passes - The media type, if there is one: a type and a subtype joined by a slash, such as
image/pngorimage/svg+xml - Parameters after semicolons in the form
name=value, such ascharset=utf-8, with only letters, digits and hyphens in the value. Quotes or dots in a value fail. ;base64only as the last parameter, right before the comma- Content made only of characters a URL allows, plus spaces and line breaks.
<,>,",#,{and letters outside the English alphabet have to be percent-encoded, as in%3Cfor<.
What it doesn't check
- Whether Base64 text really is Base64:
data:image/png;base64,picnicpasses, though it holds no picture - Whether the content matches the media type, or whether the type exists at all:
data:fruit/salad,yumpasses - Whether each
%comes with two hexadecimal digits
Good to know
- Browsers still show some images whose data URIs fail here, such as SVG written with plain
<and>, as indata:image/svg+xml,<svg ...>. Percent-encode those characters and the URI passes. - To check the Base64 part on its own, use the Base64 Validator. To see what a Base64 data URI holds, turn it into a file with the Base64 to File Converter.
Features
- Checks the header, media type, parameters and content of a data URI
- Accepts text and Base64 data URIs, with or without a media type
- Base64 broken over several lines passes
- Results as you type, with no button to press
- Runs in your browser, so nothing you type is sent anywhere