HTML | DOM Local Storage clear() Method

The clear() method removes all the Storage Object items for the current domain.


Property Values:
No Property Values

Example: Set item, clear and display for the current domain.





<!DOCTYPE html>
        body {
            text-align: center;
        h1 {
            color: green;
    <h2>HTML DOM Storage clear() Method</h2>
      Example to demonstrate the use of storage
      clear() method to delete all the local 
      storage items for this domain.
      Script to create some local storage items.
      Click the button to create the items:
    <button onclick="createItems()">
        Create local storage items
    <h2>Display Items</h2>
      Click the button to display all the items:
    <button onclick="displayItems()">
      Display items
    <p id="demo"></p>
    <h2>Remove Items</h2>
      Click the button to clear the storage:
    <button onclick="deleteItems()">
    <h2>Display Items Again</h2>
      Click the button to display all the items:
    <button onclick="displayItems()">
      Display again
    <p id="demo"></p>
        function createItems() {
            // Set item in local storage.
            localStorage.setItem("GeeksForGeeks", "");
            localStorage.setItem("HTML DOM", "");
            localStorage.setItem("Storage Clear() Method", "");
        function deleteItems() {
            // Clear local storage items.
        function displayItems() {
            var l, i;
            // Display items.
            document.getElementById("demo").innerHTML = "";
            for (i = 0; i < localStorage.length; i++) {
                x = localStorage.key(i);
                document.getElementById("demo").innerHTML += x;



Supported Browsers: The browser supported by DOM Local Storage clear() are listed below:

  • Google Chrome 4.0
  • Internet Explorer 8.0
  • Mizilla Firefox 3.5
  • Opera 10.5
  • Safari 4.0


My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.