Skip to content
BENIBIX Learn

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.

Development🌐 Web Development

HTTP Cookie

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

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.
Why it matters
Cookies are how websites remember you between pages. Logins depend on them.
Full entry
Development🌐 Web Development

Local Storage

A small store in the browser for a site's data. It stays after you close it.

Local storage is a small store in the browser for a site's data. The data is kept as text. Unlike a cookie, it is not sent to the server with each request. The data stays even after the browser is closed, until the site or the user clears it. Each site gets its own space, usually around 5 megabytes. Its cousin, session storage, is wiped when the tab closes.

Example
Emma's site remembers that Lucy chose dark mode. It saves theme=dark in local storage and reads it on her next visit.
Why it matters
It lets a site remember small choices without a server or a login.
Full entry

In one line

HTTP Cookie
A small piece of text a site stores in your browser, sent back on each visit.
Local Storage
A small store in the browser for a site's data. It stays after you close it.