A small text file stored by a web browser is called a cookie. More precisely, an HTTP cookie is a small piece of data that a website asks the browser to store and send back with later requests to that site.
Cookies helped solve a major limitation of HTTP: each request is normally independent, so a website does not automatically remember earlier page visits. A cookie can associate requests with a shopping cart, login session, language preference, or other state. The server usually creates one with the Set-Cookie response header, and the browser returns it in a Cookie request header.
Session cookies are generally removed when the browser session ends, while persistent cookies include an expiration time or maximum age. Security attributes such as Secure, HttpOnly, and SameSite help control how cookies are transmitted and accessed.
The term is associated with “magic cookies,” a computing phrase for a token passed between programs. Cookies are not the same as cache: a cache stores reusable copies of resources, while a cookie carries small pieces of state or identifiers. Cookies can support useful features but are also used for tracking.