DOM storage is a mechanism that is used to store string values in key:value pairs. It is similar to cookies, but more secure, easy to use and also able to handle large size of data. The size of data is browser dependent; however, it ranges up to few MB’s compared to 4KB cookie data. The storage is property of the window object and can be accessed globally. The DOM storage may be created as one of the following 3 types:

  • Local storage: This storage type saves the data in user’s computer indefinitely across browsers and tabs.
  • Session storage: This storage type is available till the page session exist. Once browse closes the session storage expires.
  • Global storage: This type is obsolete version of local storage.
NOTE: DOM storage is supported from FireFox 3.5+, Chrome 4+, Safari 4+, Opera 10.5+, and IE 8+.

The local and session storages support following methods:


Returns a value for the ’key’ passed into the function. If key does not exists, null is returned.

setItem(key, value)

Stores the ‘value’ to the ‘key’. The value is string object. If key exists, the previos value is rewritten with new one.


Returns the key of the item at index location.


Clears all data from DOM storage area for the current domain.


This property returns length of items listed in DOM storage area.

Details of all these storages are given in further pages.


›› go to examples ››