Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The set() method of the CookieStore interface sets a cookie with the given name and value or options object.


set(name, value)


This method requires one of the following:


A string with the name of the cookie.


A string with the value of the cookie.



An object containing:

domain Optional

A string containing the domain of the cookie.

expires Optional

A timestamp, given as Unix time in milliseconds, containing the expiration date of the cookie.


A string with the name of a cookie.

partitioned Optional

A boolean value that defaults to false. If set to true, the set cookie will be a partitioned cookie. See Cookies Having Independent Partitioned State (CHIPS) for more information.

path Optional

A string containing the path of the cookie.

sameSite Optional

One of the following SameSite values (see SameSite cookies explained for more information):


Cookies will only be sent in a first-party context and not be sent along with requests initiated by third party websites.


Cookies are not sent on normal cross-site subrequests (for example to load images or frames into a third party site), but are sent when a user is navigating to the origin site (i.e. when following a link).


Cookies will be sent in all contexts.


A string with the value of the cookie.

Return value

A Promise that resolves with undefined when setting the cookie completes.



Thrown if setting the cookie with the given values fails.

SecurityError DOMException

Thrown if the origin does not serialize to a URL.


The following example sets a cookie by passing an object with name, value, expires, and domain.

const day = 24 * 60 * 60 * 1000;
  name: "cookie1",
  value: "cookie1-value",
  expires: + day,
  domain: "",


Cookie Store API
# dom-cookiestore-set

Browser compatibility

BCD tables only load in the browser