A cookie is small data with a specific job
Cookies sound more mysterious than they are. A cookie is a small piece of data that a browser stores for a website. It usually contains a short value, not a secret file or a complete profile of you.
The reason cookies exist is simple. HTTP, the system browsers use to request web pages, does not remember earlier requests by itself. Without another mechanism, each page request looks separate. A cookie gives the website a way to connect one request with the next.
For example, a cookie can hold a session identifier after you sign in. The actual account data can stay on the server. The identifier tells the server which session belongs to your browser. Cookies can also remember language settings, keep a shopping session active, or help measure visits. MDN explains these common uses in more technical detail.
A server can create a cookie through an HTTP response. Page JavaScript can also create cookies when browser rules allow it. On later eligible requests, the browser can send matching cookies back to the relevant domain. Attributes such as the domain, path, expiry, and security settings control where and how this happens.
