Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM Local Storage clear() Method

  • Last Updated : 26 Jul, 2019

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
Recommended Articles
Page :

Start Your Coding Journey Now!