---
title: "Cookie Domain and Path: Scope Rules Explained | CookieBeam"
description: "How the Domain and Path cookie attributes control which requests carry a cookie: host-only vs subdomain sharing, path matching, and the __Host- prefix."
url: "https://cookiebeam.com/articles/cookie-domain-path-scope-explained-2026"
lang: "en"
last_updated: "2026-09-18T19:27:56.848Z"
---

# Cookie Domain and Path Attributes: How Scope Controls Reach

Two attributes decide which requests carry a cookie: Domain controls which hosts, Path controls which URLs. Get them wrong and you either leak a cookie or lose it. Here's how scoping works.

Every HTTP cookie has two attributes that control where the browser sends it: `Domain` and `Path`. Omit `Domain` and the cookie is host-only, visible to `example.com` but not `shop.example.com`. Include it and every subdomain inherits the cookie. `Path` adds a second filter, scoping transmission to a URL prefix so a cookie set on `/app` is never sent to `/blog`. Get these two attributes wrong and you either leak a session cookie to a subdomain you don't control or lose it on the pages that need it. This guide walks through how scoping works and why the `__Host-` prefix exists to lock both attributes down.

## Domain: which hosts get the cookie

The `Domain` attribute controls which hosts the browser will send the cookie to. There are two cases, and the default surprises people.

**No Domain attribute (host-only).** If you set a cookie without `Domain`, it becomes a host-only cookie, sent only to the exact host that set it. A cookie set by `example.com` with no `Domain` won't go to `www.example.com` or `shop.example.com`. Plenty of people expect the opposite, and it's a common source of "why am I logged out on the www version" bugs.

**Domain set.** If you set `Domain=example.com`, the cookie is sent to `example.com` and every subdomain: `www.example.com`, `shop.example.com`, `api.example.com`, and so on. You can only set `Domain` to your own domain or a parent domain, never a subdomain or an unrelated site. A page on `shop.example.com` can set a cookie for `example.com`, but not for `google.com`.

There's a hard limit at the top. You can't set `Domain` to a public suffix like `.com` or `.co.uk`, because that would let one site drop a cookie on every site beneath it. Browsers enforce this with a public suffix list, the same eTLD concept behind "same-site", so a cookie's reach stops at the registrable domain you actually own.

## Path: which URLs get the cookie

The `Path` attribute narrows the cookie to a slice of your URLs. The browser sends it only when the request path matches the cookie's `Path` as a prefix, treating `/` as a directory separator.

With `Path=/docs`, the cookie is sent on `/docs`, `/docs/`, `/docs/web`, and anything deeper. It is _not_ sent on `/`, on `/docsets` (similar spelling, different directory), or on `/fr/docs`. Set `Path=/` and the cookie applies to the entire site, which is what most cookies want. MDN is blunt about one thing: `Path` is a scoping convenience, not a security boundary. Don't rely on it to hide a cookie from part of your own site, because any page under that path can read it anyway.

### How Domain and Path scope a cookie

| Setting | Cookie is sent to |
| --- | --- |
| **No Domain (host-only)** | Only the exact host that set it |
| **Domain=example.com** | example.com and all its subdomains |
| **Path=/** | Every path on the site |
| **Path=/account** | /account and everything under it |

## Domain and Path work together

A cookie is sent only when both tests pass: the host matches the Domain rule and the request path matches the Path rule. That combination is how one site runs different cookies for different areas, say a cart cookie scoped to `Path=/shop` and an admin cookie scoped to `Path=/admin`. When two cookies share a name, the browser sends the one with the more specific (longer) path first.

One consequence trips people up when deleting cookies. To remove a cookie you have to send a matching `Domain` and `Path` with an expiry in the past. Get the scope wrong and you quietly set a second, differently scoped cookie instead of clearing the first, which is why a "logout" sometimes leaves a stale cookie behind.

Two things Domain and Path do not do. They don't consider the scheme, so an `http` and an `https` version of the same host share cookies unless you add `Secure`. And they don't cross to a different registrable domain, which is the boundary that separates first-party from third-party cookies. For that split, see [first-party vs third-party cookies](https://cookiebeam.com/articles/first-party-vs-third-party-cookies).

> **Note: __Host- cookies forbid Domain on purpose**
>
> The hardened `__Host-` name prefix requires a cookie to omit `Domain` entirely and use `Path=/`. That forces the cookie to be host-only, so a sibling subdomain can't set a cookie your main site would trust. For the strongest scoping on a session cookie, that's the combination: no `Domain`, `Path=/`, `Secure`, and a `__Host-` name. See [Secure and HttpOnly flags](https://cookiebeam.com/articles/secure-httponly-cookie-flags-explained-2026).

## Scope, consent, and multiple domains

Scope has a direct consent consequence. A cookie set with `Domain=example.com` spreads across every subdomain, so a tracker set that way is collecting across your whole property and needs consent that covers all of it. Consent itself doesn't cross a registrable domain, though. Because the browser won't share cookies between `example.com` and `example.co.uk`, a visitor's choice stored in a cookie on one won't be visible on the other, which is why running a single banner across several domains takes deliberate setup. See [cross-domain consent sharing](https://cookiebeam.com/guides/cross-domain-consent-sharing).

When CookieBeam scans a site, it captures each detected cookie's Domain and Path alongside its category, so you can see whether a cookie is host-only or spread across subdomains, and which part of the site sets it. That inventory is what turns a vague "we use cookies" into a per-cookie record you can act on.

## Checking scope in practice

In DevTools under Application then Cookies, the Domain and Path columns show each cookie's scope. A leading dot on a domain (`.example.com`) is the older way of writing "include subdomains" and behaves like a plain `Domain=example.com` today. If a cookie isn't showing up where you expect, this is the first place to look.

Related: [how the Set-Cookie header works](https://cookiebeam.com/articles/how-cookies-work-set-cookie-header-2026), [the SameSite attribute](https://cookiebeam.com/articles/samesite-cookie-attribute-explained-2026), and [session vs persistent cookies](https://cookiebeam.com/articles/session-vs-persistent-cookies).

## Sources

- [MDN: Using HTTP cookies (Domain and Path)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies)
- [MDN: Set-Cookie header reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie)
- [RFC 6265: HTTP State Management Mechanism](https://datatracker.ietf.org/doc/html/rfc6265)
