1 of 12

HTML Web Storage API

Himanay Khajuria

Create a Better User Experience

12 March 2025

2 of 12

  • The Web Storage API allows storing key-value pairs in a web browser.
  • It provides a simple way to store small amounts of data.
  • There are two types:
    • Local Storage (stores data permanently)
    • Session Storage (stores data temporarily)

What is Web Storage API?

3 of 12

Why Use Web Storage API?

  • Faster performance – Reduces server requests.
  • Data persists – Local Storage keeps data even after the browser is closed.
  • Works offline – Can store data for offline use.
  • Simple & Secure – Only accessible via JavaScript within the same domain.

4 of 12

Local Storage vs. Session Storage

5 of 12

Using Local Storage (Examples)

6 of 12

Using Session Storage (Examples)

7 of 12

Storing Objects in Web Storage

8 of 12

Best Practices

Limitations

  • Use for small data storage (5MB limit per origin).
  • Do not store sensitive information (e.g., passwords, tokens).
  • Use JSON.stringify() for storing objects.
  • Always check if storage is available.
  • Can be cleared by the user manually.
  • Only accessible within the same domain.
  • Not encrypted, making it vulnerable if used incorrectly.

9 of 12

Real-World Use Cases

  • Dark mode settings – Save user’s theme preference.
  • Shopping cart items – Store items temporarily before checkout.
  • Form autosave – Prevent losing entered data.
  • Game scores – Store user progress.

10 of 12

Web Storage vs. Cookies

11 of 12

Summary

  • The Web Storage API is a simple and powerful tool.
  • Local Storage persists data even after closing the browser.
  • Session Storage only lasts while the tab is open.
  • Follow best practices to avoid security risks.
  • Useful for saving user preferences, session data, and small app state information.

12 of 12

Thank

You