What is the difference between cookies, local storage, and session storage?

Cookies

Cookies store small amounts of data that has to be sent back to the server with subsequent requests and their expiration can be set from either server or client. They are primarily used for server-side reading.

Local storage

Local storage stores a larger amount of data on the client’s computer in a key-value pair format and has no expiration date. Data is never transferred to the server and is accessible via JavaScript and HTML5.

Session storage

Session storage stores a larger amount of data on the client’s computer only for the current session, expiring the data on tab close. Data is never transferred to the server and is accessible client-side from the same tab.

Cookies Local storage Session storage
Capacity 4KB 10MB 5MB
Accessible from Any window Any window Same tab
Expiration Manually set Never On tab close
Storage location Browser and server Browser only Browser only
Sent with requests Yes No No
Blockable by users Yes Yes Yes
Editable by users Yes Yes Yes