iron-localstorage | Vaadin

Access to localStorage

Published on NPM Build status Published on

⚠️ This element is deprecated ⚠️


Element access to Web Storage API (window.localStorage) by keeping value property in sync with localStorage.

Value is saved as json by default.

See: Documentation, Demo.



npm install --save @polymer/iron-localstorage

In an html file

    <iron-localstorage name="my-app-storage"></iron-localstorage>

    <script type="module">
      import '@polymer/iron-localstorage/iron-localstorage.js';

      const ls = document.querySelector('iron-localstorage');
      // initializes default if nothing has been stored
      function initializeDefaultCartoon() {
        ls.value = {
          name: "Mickey",
          hasEars: true

          'iron-local-storage-load-empty', initializeDefaultCartoon);

      // use path set api to propagate changes to localstorage
      function makeModifications() {
        ls.set('', "Minions");
        ls.set('value.hasEars', false);

In a Polymer 3 element

import {PolymerElement, html} from '@polymer/polymer';
import '@polymer/iron-localstorage/iron-localstorage.js';

class SampleElement extends PolymerElement {
  static get template() {
    return html`
      <iron-localstorage name="my-app-storage"

  static get properties() {
    return {
      cartoon: { type: Object },

  // initializes default if nothing has been stored
  initializeDefaultCartoon() {
    this.cartoon = {
      name: "Mickey",
      hasEars: true

  // use path set api to propagate changes to localstorage
  makeModifications() {
    this.set('', "Minions");
    this.set('cartoon.hasEars', false);
customElements.define('sample-element', SampleElement);


If you want to send a PR to this element, here are the instructions for running the tests and demo locally:


git clone
cd iron-localstorage
npm install
npm install -g polymer-cli

Running the demo locally

polymer serve --npm

Running the tests

polymer test --npm


Link to this version
ImportedReleased 14 September 2018BSD 3-clause "New" or "Revised" License
Framework Support
Polymer 3.0+
Also supported:
Polymer 1 (1.0.6)Polymer 2 (2.1.1)
Browser Independent
Install with
npm install @polymer/iron-localstorage"@3.0.1"
Run the above npm command in your project folder. If you have any issues installing, please contact the author.
Release notes - Version 3.0.1


  • @polymer/polymer#^3.0.0