Introduction
In this article, I'll tell you about the difference between Session Storage, Local Storage, and Cookies.
Different kind of storage space is available for our data on the client as well as server-side, we can choose any of them according to our need and level of transparency. Among these storage spaces, three are Session Storage, Local Storage, and Cookie.
Among these three, Session and Local Storage comes under Web Storage, so first let's compare and see the difference between them.
Session Storage and Local Storage
I had created a sample application to show the difference.
I just created a .NET application in which an HTML5 page is added, and on that page, script tag is added so that we can assign some values under the two storage.
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title></title>
- <script>
- </script>
- </head>
- <body>
- </body>
- </html>
After this, I added single values in both sessions and local storage.
- <script>
- sessionStorage.setItem("sessionData", "I am set in session storage.");
- localStorage.setItem("localData", "I am set in local storage.");
- </script>
Now just simply run the application and on browser open the console. In the console, you can find the values in this simple way,
You can see that both the values are available, up to here everything is fine and normal, even both look the same. But now open any other page of the application and again check the console.
Did you find the value in both of them! NO.
Here comes the difference, session storage value will persist for a particular page only and will not be available on any other page but local storage value once entered can be accessed on any page.
Still, one more thing to come, just close the browser and open it again. Now again go to any other page and check the console for the value of the session and local storage.
Did you find anything? Yes, local storage is still available and will remain available until you clear your browser's history or clear it from JavaScript.
So, till now we have seen the difference between session and local storage and clearly local storage is proved as more helpful (depend on the case) than session storage.
Now let's move towards local storage and cookies.
Local Storage and Cookies
I am adding a Web Form to my application and just provide some controls on it.

Dara SroksraePosted Jul 19, 2020, 9:10 PM
Great explanation.Thank you so much
Hana AanaaPosted Apr 15, 2019, 9:59 AM
Great explanation. Thank you
Bg BhuvaneswariPosted Jul 30, 2018, 12:10 AM
Thanks alot.... Understood best....
Animesh GhoshPosted Oct 15, 2017, 12:51 AM
Very good explanation and understood the difference
vikash bajiyaPosted May 29, 2017, 6:59 AM
Very good example to understand local storage, session storage and cookies
Soumalya DasPosted Aug 11, 2016, 11:25 AM
Good example for understanding
Karthik ElumalaiPosted Jul 1, 2016, 10:54 PM
Very well explained and easy to understand..Thanks for this..:)
Prasanna MuraliPosted May 20, 2016, 11:23 AM
Nice one....
Bhuvanesh MohankumarPosted Apr 30, 2016, 3:11 PM
Good one...
Asfend YarPosted Feb 29, 2016, 1:59 PM
good
Anubhav ChaudharyPosted Jan 6, 2016, 11:16 PM
Thanks Abhishek Mishra and Sabyasachi Mishra
Sabyasachi MishraPosted Jan 6, 2016, 3:45 PM
Nice one
Abhishek MishraPosted Jan 6, 2016, 3:12 PM
very informative article.
Anubhav ChaudharyPosted Jan 6, 2016, 6:12 AM
Thanks Senthil Kiumar and Jainish Shah
Jainish ShahPosted Jan 6, 2016, 5:01 AM
Very Informative article
Senthil KiumarPosted Jan 6, 2016, 3:49 AM
Thanks nice article
Anubhav ChaudharyPosted Jan 6, 2016, 3:42 AM
Thanks to all those who have read the article.
Ankit BansalPosted Jan 6, 2016, 2:19 AM
Thanks for sharing
Santhakumar MunuswamyPosted Jan 5, 2016, 11:06 PM
Thanks for nice share
Anubhav ChaudharyPosted Jan 5, 2016, 2:14 PM
Thanks All :)
Ankur MistryPosted Jan 5, 2016, 2:03 PM
nice share
Maruthi PalllamalliPosted Jan 5, 2016, 12:08 PM
Informative article. Small doubt in your article, What happen if my browser disable cookies ? and It is working at page level or application level ?
Gowtham KPosted Jan 5, 2016, 11:49 AM
Good One, thanks for sharing it
Arul RPosted Jan 5, 2016, 9:38 AM
Nice Share
Anubhav ChaudharyPosted Jan 5, 2016, 8:04 AM
It feels really good when people first read the article and then comment on it, no matter if they are appreciating or criticizing, at least they read the article and make time spend by author worthy.
Anubhav ChaudharyPosted Jan 5, 2016, 7:52 AM
Thanks All
Gowtham RajamanickamPosted Jan 5, 2016, 7:21 AM
Good article
Yashwant VishwakarmaPosted Jan 5, 2016, 6:47 AM
Nice article, thanks for sharing !!
Kumaresh RajalingamPosted Jan 5, 2016, 6:46 AM
Good one
Nanddeep NachanPosted Jan 5, 2016, 6:23 AM
Cleanly explained, Thanks!
Gaurav GuptaPosted Jan 5, 2016, 6:22 AM
Good Explanation. Keep it up.. :)
Pankaj Kumar ChoudharyPosted Jan 5, 2016, 6:02 AM
Nice Explain Anubhav .......
Humayun Kabir MamunPosted Jan 5, 2016, 5:51 AM
Nice...