Document.cookie lets you read and write cookies for the current document (MDN). Reading returns a semicolon-separated list of name=value pairs. Assigning sets or updates one cookie at a time.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Create a temp cookie. Confirm it appears in document.cookie.
Expire it. A past UTC date tells the browser to remove that name.
Match path. If you set path=/, delete with the same path or removal can fail.
Verify.includes("temp=") should become false.
Compatibility
Browser Support
Document.cookie is Baseline Widely available on MDN. It works across modern browsers. For asynchronous cookie access, consider the Cookie Store API where supported.
✓ Baseline · Widely available
Document.cookie
Read/write accessor for script-visible cookies — one cookie per assignment; semicolon-separated string on read.
99%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
cookieExcellent
Bottom line: Safe and universal for basic cookie work. Prefer SameSite=Lax (default in modern browsers), encode values, and use HttpOnly + Secure on the server for auth cookies.
Frequently Asked Questions
It is an accessor property that lets you read and write cookies for the current document. Reading returns a semicolon-separated list of name=value pairs. Assigning sets or updates one cookie at a time.
No. MDN marks Document.cookie as Baseline Widely available. It is a standard property. For async cookie work, MDN also points to the Cookie Store API as a modern alternative.
What you write is not the same as what you read. The setter accepts one cookie plus optional attributes (expires, path, SameSite…). The getter returns only name=value pairs for cookies visible to the script — no attributes.
Set the same cookie name again with an expires date in the past (or max-age=0), and match path/domain if you set them originally.
No. Cookies marked HttpOnly are sent to the server but are not visible to document.cookie. That helps reduce damage from XSS cookie theft.
Yes. Use encodeURIComponent() so values do not contain commas, semicolons, or whitespace, which are disallowed in cookie values (MDN).