URL - The data URL scheme

About

The data scheme is a scheme that can be used in a URL in order to embed (small) media resources data directly such as:

The benefit is that there is no need for extra HTTP requests in order to fetch the resource, making the page load more efficient.

As for all performance optimizations, there is a trade off between growing the size of your page by inlining all resources and fetching asynchronously the resources. Generally, the inlined media resources are of small size (ie <2kb)

Syntax

data:[<MIME-type>][;charset=<encoding>][;base64],<data>

where

Note that you can create data URL programmatically with the URL.createObjectURL function. See the example below

Example

Jpeg - Base 64

The HTML fragment could be used for a small inline image in a HTML document. (The embedded image is probably near the limit of utility. For anything else larger, data URLs are likely to be inappropriate.)

Image in What is Base64? (Cryptography Cipher)

<img src="data:image/jpg;base64,/9j/4Qp2RXhpZgAASUkqAAgAAAAHAA4BAgAgAAAAYgAAAA8BAgAFAAAAggAAABABAgAIAAAAiAAAADIBAgAUAAAAkAAAABMCAwABAAAAAgCxwmmHBAABAAAAwAAAAKXEBwAcAAAApAAAAAAAAAAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgAFNPTlkAl0RTQy1UMTAAMjAwNzowMzowMyAwNjoyNDozNwBQcmludElNADAzMDAAAAIAAgABAAAAAQEBAAAAHQCaggUAAQAAACICAACdggUAAQAAACoCAAAiiAMAAQAAAAIAAgAniAMAAQAAAMgAAAAAkAcABAAAADAyMjEDkAIAFAAAADICAAAEkAIAFAAAAEYCAAABkQcABAAAAAECAwACkQUAAQAAAFoCAAAEkgoAAQAAAGICAAAFkgUAAQAAAGoCAAAHkgMAAQAAAAUAAAAIkgMAAQAAAAAAAAAJkgMAAQAAAE8AAAAKkgUAAQAAAHICAAB8kgcA9AcAAHoCAAAAoAcABAAAADAxMDABoAMAAQAAAAEAAAACoAQAAQAAAGIAAAADoAQAAQAAAGQAAAAAowcAAQAAAAMAAAABowcAAQAAAAEAAAABpAMAAQAAAAAAAAACpAMAAQAAAAAAAAADpAMAAQAAAAAAAAAGpAMAAQAAAAAAAAAIpAMAAQAAAAAAAAAJpAMAAQAAAAAAAAAKpAMAAQAAAAAAAAAAA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ufxBd3yvIwgQytsfZAnzDpgkgk/nRRRTSd7lvSxua227wxY6goEVxbsnlmPgKMdMenGMfWtDw5dyR+ONTs1OLdoRJs7Ald3HpzRRW6it7amPM+Xlvodobh8nmiiiqOc//2Q=="
ALT="Nico">

Svg

The svg is used in an URL and should then be url encoded. (You can grab a background css directly via this codepen)

.navbar-toggler-icon {
   background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='17' viewBox='0 0 17 17'%3E%3Cg%3E%3C/g%3E%3Cpath d='M17 16v1h-17v-1h17zM12 10h2v5h1v-6h-4v6h1v-5zM7 7h2v8h1v-9h-4v9h1v-8zM2 3h2v12h1v-13h-4v13h1v-12z' /%3E%3C/svg%3E");
}

.navbar-toggler-icon {
    display: inline-block;
    width: 3em;
    height: 3em;
    vertical-align: middle;
    content: "";
    background-size: 100% 100%;
}
<span class="navbar-toggler-icon"></span>

Plain Text to download

Example with the anchor download attribute

  • Plain text
<a href="data:text/plain,Hello World" download="hello-world.txt">Download hello-world.txt</a>
  • Result:
<a href="data:text/plain;base64,SGVsbG8gV29ybGQgIQ==" download="hello-world.txt">Download base64 encoded hello-world.txt</a>

How to create data url with the URL.createObjectURL

The javascript browser api function URL.createObjectURL permits to create data uri programmatically directly. You don't need to form a data url or transform the payload in base64

Example: The same example than above to download a text file can rewritten:

let textBlob = new Blob( ["Hello World !"], { type: 'text/plain' });
let objectUrl = URL.createObjectURL(textBlob);
  • Create the anchor with its attribute
let a = document.createElement("a");
document.body.append(a);
a.href=objectUrl;
let fileName = "hello-world.txt";
a.setAttribute("download",fileName);
a.innerText = `Download ${fileName}`;
// To prevent memory leaks, always revoke the URL after the download.
a.addEventListener('click', (e) => {
    setTimeout(() => URL.revokeObjectURL(e.target.href), 30 * 1000);
});
  • Result:

Documentation / Reference





Discover More
Blob Url In Browser Address
Browser / Javascript - Object URL (createObjectURL / revokeObjectURL)

An ObjectUrl is the representation of blob object as a data URL strings that can be used with any fetch HTML element that accepts an URL as an attribute. HTML Example: This HTML was generated with...
Boxdim
CSS - Background (Image)

The background of an element is the total size of the element: including padding and border but not the margin. The margin is transparent. When two element overlap, you can send one element to...
HTML - How to render SVG in HTML

How to render svg markup in a HTML page. You can render SVG markup via: object, embed, iframe, img, CSS background-image and svg inclusion. HTML A svgSVG element represents the root...
HTML - Image (Img tag)

img is an fetch element that represents an image. An image in HTML can also be represented with a picture element that defines logically the same image but may have different physical image (different...
Html Input File Multiple Warning Dialog
How to handle files in Javascript with the File API of the Browser?

The file api is a browser javascript api that allows file system operation in the browser. FileApiopeneditsave Uploading a file: You can open and read files via the input of type file The...
How to store and use data in HTML

This article shows where you can store and use data
Web Resource - Scheme

A scheme is the first part of an URI. It refers to a network protocol (called also specification) that should be used to communicate with the service defines in the authority part of the URL The scheme...
Card Puncher Data Processing
What is an Icon?

This page is icons. They represent symbolic image. Unicode Block Miscellaneous_SymbolsMiscellaneous Symbols From 2600U+2600 to 26FFU+26FF See also: Icon font for special icon font. with the 260ETelephon...



Share this page:
Follow us:
Task Runner