Html – Data protocol URL size limitations


Is there any size limitation for "data:" URL scheme
values? I'm interested in limitations in popular web browsers. In other words, how long can data:image/jpg;base64,base64_encoded_data be in <img src="data:image/jpg;base64,base64_encoded_data" /> or background-image: url(data:image/jpg;base64,base64_encoded_data)?

Best Solution

Short answer: The data URI limit varies.

There are a lot of answers. As the question was asked 5+ years ago, most are now incorrect due to becoming dated, yet this question sits at the top of Google results for "data uri limit". Data URIs are now widely supported and IE 7/8 is no longer a relevant browser. There are many references below because the answer is nuanced today.

Data URI Limits

The data URI spec does not define a size limit but says applications may impose their own.

  • Chrome - 2MB for the current document. Otherwise the limit is the in-memory storage limit for arbitrary blobs: if x64 and NOT ChromeOS or Android, then 2GB; otherwise, total_physical_memory / 5 (source).
  • Firefox - unlimited
  • IE ≥ 9 & Edge - 4GB
  • Safari & Mobile Safari - ?


One technology with a higher limit (500MiB in Chrome) that may be an alternative for your use case is Blob URLs via URL.createObjectURL() using the URL API together with blobs via the File API. An example of that is provided in Using URL.createObjectURL().

A few other alternatives as mentioned in How to write a file / give it to the user are: FileSaver.js, StreamSaver.js, and JSZip.

You can use Modernizr to detect support for data URIs over 32kb.

Related Questions

These answers are pretty much the same as this question, but I mention them to save you the time of reading each one.