Cookies vs localStorage vs sessionStorage

I thought this video by Beau at Free Code Camp was awesome.

I pulled this table out from the video for comparing between cookies, localStorage, and sessionStorage.

Comparing Cookies, localStorage, and sessionStorage

Cookies Local Storage Session Storage
Capacity 4kb 10mb 5mb
Browsers HTML4/Html5 Html5 Html5
Accessible from Any window Any window Same tab
Expires Manually set Never On tab close
Storage Location Browser and server Browser only Browser only
Sent with requests Yes No No
Security Considerations


  • Cookies, sessionStorage and localStorage should only be used for persisting non-sensitive data between pages since they can be read and modified from the client
  • Cookies information can be intercepted in transit if not on HTTPS
  • Cookies should use the HTTPonly flag will prevent access to the cookies and values from JavaScript
  • Cookies should not be used to store large amounts of information since all cookies valid for a page are sent for every request to the same domain.

Duncan Leung

Front End Developer at

Irvine, CA

Subscribe to Duncan Leung: Javascript and Front End Development

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!