Example 1 — Read cookieEnabled
Log the current Boolean value.
console.log(navigator.cookieEnabled); How It Works
Most everyday browser setups return true. Disable cookies in settings to see false.

navigator.cookieEnabled is a read-only Boolean that tells you whether cookies are enabled. Learn the MDN check pattern, UI messaging, limits of the flag, five examples, and try-it labs.
Read-only property
Boolean
Newly available
Cookies enabled
Blocked / unsupported
Quick capability check
Many sites use cookies for sessions, preferences, and consent. If the user (or browser) blocks cookies, features that depend on them can fail in confusing ways.
navigator.cookieEnabled gives you a simple Boolean answer: are cookies enabled right now? MDN: when it is false, the browser does not support cookies or is blocking them from being set.
true does not mean every cookie attribute combination will succeed. Special cases (for example SameSite=None without HTTPS + Secure) can still be rejected.
cookieEnabled PropertyThink of cookieEnabled as a traffic light for cookie storage at the browser level. You read it once (or when you need to warn the user) — you never assign to it.
General form of the property:
navigator.cookieEnabled // MDN pattern:
if (!navigator.cookieEnabled) {
// The browser does not support or is blocking cookies.
}
// Positive branch:
if (navigator.cookieEnabled) {
console.log("Cookies look enabled");
} | Goal | Code |
|---|---|
| Read the flag | navigator.cookieEnabled |
| Cookies off? | if (!navigator.cookieEnabled) { … } |
| Cookies on? | if (navigator.cookieEnabled) { … } |
| Type | typeof navigator.cookieEnabled === "boolean" |
| Writable? | No (read-only) |
| Status (MDN) | Baseline Newly available |
Four facts to remember about navigator.cookieEnabled.
booleantrue / false
newlySince Sept 2024
read-onlyNo assignment
warningsUX messaging
cookieEnabled vs Test Cookienavigator.cookieEnabled | Write / read document.cookie | |
|---|---|---|
| Speed | Instant Boolean | Needs a small write + check |
| Detail | Browser-level enabled? | Did this cookie stick? |
| Edge cases | May miss attribute-specific blocks | Closer to real storage rules |
| Best for | Quick UI warning | Critical session / auth flows |
| Use together? | Yes — check the flag first, then verify with a test cookie if needed | |
Examples follow MDN navigator.cookieEnabled patterns. Prefer Try It Yourself to inspect your browser. Use View Output for expected messaging.
Read the Boolean and apply the MDN check.
cookieEnabledLog the current Boolean value.
console.log(navigator.cookieEnabled); Most everyday browser setups return true. Disable cookies in settings to see false.
if (!cookieEnabled) CheckBranch when cookies are unsupported or blocked.
if (!navigator.cookieEnabled) {
console.log("Cookies unsupported or blocked");
} else {
console.log("Cookies look enabled");
} This is MDN’s recommended shape: treat false as “do not rely on setting cookies.”
User messaging, type checks, and a reusable helper.
Build a short status string for a banner or settings tip.
const msg = navigator.cookieEnabled
? "Cookies are enabled — preferences can be saved."
: "Cookies are blocked — some features may not work.";
console.log(msg); Show this near login, cart, or consent UI so users know why a feature might fail.
Verify the property is a Boolean (beginner sanity check).
const lines = [
"value: " + navigator.cookieEnabled,
"typeof: " + typeof navigator.cookieEnabled
];
console.log(lines.join("\n")); You get a real Boolean — not the strings "true" / "false".
Combine the flag with a tiny write/read check for extra confidence.
function cookieStatus() {
if (!navigator.cookieEnabled) {
return { ok: false, reason: "cookieEnabled-false" };
}
const key = "ctf_cookie_test";
document.cookie = key + "=1; path=/; max-age=60";
const stored = document.cookie.split("; ").some((c) => c.indexOf(key + "=") === 0);
// cleanup
document.cookie = key + "=; path=/; max-age=0";
return stored
? { ok: true, reason: "enabled-and-writable" }
: { ok: false, reason: "write-failed" };
}
console.log(JSON.stringify(cookieStatus())); Use the flag first; the optional test cookie catches cases where the flag is true but storage still fails for your page.
localStorage or in-memory state when cookies are off.cookieEnabled in support debug panels.navigator.cookieEnabled WorksAccess navigator.cookieEnabled in your script.
Returns true or false for cookie enablement.
Warn, degrade gracefully, or proceed with cookie features.
For critical paths, also verify a short-lived test cookie.
Navigator.true does not guarantee every cookie attribute (for example SameSite=None) will succeed.navigator.cookieEnabled is Baseline Newly available across modern browsers (MDN: since September 2024). Use it as a quick cookies-enabled check and keep a clear message when it is false.
Read the Boolean early for UX warnings. For critical session flows, optionally verify with a test cookie.
Bottom line: Check navigator.cookieEnabled, warn when false, and remember attribute-specific cookie rules can still apply.
navigator.cookieEnabled is a simple, Baseline Boolean for cookie enablement. Use the MDN if (!navigator.cookieEnabled) pattern to warn users, and optionally confirm with a short test cookie when sessions matter.
Continue with credentials, Window methods, or the JavaScript hub.
falsetruetrue means every cookie option workscookieEnabledSecure rules for cross-site cookiescookieEnabledBaseline Boolean — cookies on or blocked.
boolean
TypeCookies enabled
OKBlocked / unsupported
Warnread-only
APIBaseline
ModernMDN notes that even when cookies are generally enabled, browsers may still refuse certain cookies — for example SameSite=None without HTTPS and the Secure attribute.
Credential Management API for smoother sign-in.
8 people found this page helpful