DOM Document.cookie Property
The cookie property reads all cookies for the page as one string, or writes a single cookie when assigned.
Description
The cookie property gives access to the page's cookies. Reading it returns every cookie visible to the script as one name=value string separated by semicolons. Assigning to it sets or updates one cookie, with optional attributes such as max-age, expires, path, secure and samesite; to delete a cookie, set it with max-age=0.
Cookies marked HttpOnly by the server can't be seen by scripts, which protects session cookies. For data only needed in the browser, localStorage is simpler, and newer browsers also offer the asynchronous cookieStore API.
Cookie values can't contain semicolons, commas or spaces without encoding, so wrap values in encodeURIComponent() when setting them and decode them when reading. Cookies are sent to the server with every matching request, so keep them small.
Syntax
document.cookie
document.cookie = "name=value; max-age=seconds; path=/; samesite=lax"Value
A string of all cookies visible to the page, in the form "a=1; b=2".
Example
Browser Support
The following information will show you the current browser support for the Document.cookie property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





