devxlogo

JavaScript Cookies

JavaScript Cookies

Question:
How long can a document.cookie string be? In other words, how many cookies can I set?

Answer:
There are a number of important limitations on the use of cookies by Web site developers. These limitations originate from the fact that cookies are intended to be used for infrequent storage of small amounts of data on the user’s machine. Although how much cookie information is stored and for how long are up to browser makers, the following limits generally apply:

300 cookies total
20 cookies per server (not per page or site)
4K of data per cookie (both the name and value of the cookie count towards this limit)

As a result, it is not a good idea to create separate cookies for each value you’d like to save. Instead, combine those values into a single cookie separated by a known delimiter.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist