Clear all cookies

Expire every cookie that JavaScript can see on the current path.

JavaScriptBrowser · DOM Version 1.0.0 · MIT · .md

clear-all-cookies.js
function clearCookies() {
  for (const cookie of document.cookie.split(';')) {
    const name = cookie.split('=')[0].trim();
    if (name) document.cookie = `${name}=; Max-Age=0; path=/`;
  }
}

Usage

usage.js
document.cookie = 'theme=dark; path=/';
document.cookie = 'lang=pt-BR; path=/';
clearCookies();
document.cookie; // → ''

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

Know the limits

  • HttpOnly cookies, such as most session cookies, are invisible to JavaScript; only the server can clear them with Set-Cookie.
  • A cookie set with another Path or Domain must be expired with the same attributes.
  • The original set expires to the current time; Max-Age=0 expires immediately without relying on the client clock.

The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.

Source & maintenance

Based on Clear all cookies from the original 1loc collection by Nguyen Huu Phuoc, with iamandrewluca. Copyright (c) 2020 phuoc-ng. MIT licensed.

Expires cookies with Max-Age=0; HttpOnly and path limits documented. Executed in Chromium. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Usage lines executed in headless Chromium against the fixture markup; no external services · reviewed October 28, 2026.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.