# HTTP Cookie

> A small piece of text a site stores in your browser, sent back on each visit.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Cookie, Browser Cookie, Web Cookie, Set-Cookie, HttpOnly

## Think of it like

Think of it like a cloakroom ticket. You show it each time you come back, so they know which coat is yours.

## Definition

A cookie is a small piece of text a website asks the browser to keep. The browser sends it back with every later request to that site. That is how a site remembers you are logged in or what is in your cart. A cookie can be set to expire, and flags like HttpOnly and Secure keep it safer. Cookies used to track people across sites are why many countries require a cookie notice.

## Example

Jack logs into a shop. The site sets a cookie with his session id, so the next page knows who he is.

## Example code

```http
Set-Cookie: session=abc123; HttpOnly; Secure; Max-Age=3600
```

A login cookie that scripts cannot read and that lasts one hour.

## Why it matters

Cookies are how websites remember you between pages. Logins depend on them.

## Common mistake

Storing a login cookie without HttpOnly. Then a script injected into the page can steal it.

## Three principles

- **Kept by the browser.** Sent back on every request.
- **Remembers you.** Logins, carts and settings.
- **Lock it down.** Use HttpOnly and Secure.

## Related terms

- [Local Storage](https://learn.benibix.com/term/development/local-storage)
- [Back End](https://learn.benibix.com/term/development/back-end)
- [Front End](https://learn.benibix.com/term/development/front-end)
- [Web Application](https://learn.benibix.com/term/development/web-application)
- [Cookie Banner](https://learn.benibix.com/term/marketing/cookie-banner)
- [Session Hijacking](https://learn.benibix.com/term/development/session-hijacking)

## Told apart from

- [Cookie vs Local Storage](https://learn.benibix.com/compare/cookie-vs-local-storage): A cookie and local storage both keep small bits of data in the browser. A cookie goes to the server with every request. Local storage stays in the browser and only your page's code reads it.

## Taught in

- [Cookies and Local Storage](https://learn.benibix.com/learn/development-web/cookies-and-local-storage): HTML, CSS and JS, 14/14
- [Browsers, Links and Bookmarks](https://learn.benibix.com/learn/general-internet/browsers-links-and-bookmarks): Online Safety, 4/8

---

Source: https://learn.benibix.com/term/development/cookie
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
