- 01Setting Up (What You'll Need)
- 02Your First HTML
- 03Lists and Links
- 04Adding Color with CSS
- 05CSS Selectors and Classes
- 06Layout with Flexbox
- 07Trying Out Images and Tables
- 08Trying Out Form Controls
- 09Understanding the Box Model
- 10Intro to Responsive Design (Media Queries)
- 11CSS Variables (Custom Properties)
- 12Layout with CSS Grid
- 13Adding an Animation
- 14How to Write Comments
- 15Adding Interaction with Pseudo-Classes (:hover)
- 16CSS's :not() and Multi-Condition Selectors
- 17The Basics of Meta Tags and SEO
- 18The Basics of Accessibility (alt and aria-label)
- 19Trying Out data Attributes (data-*)
- 20CSS Transitions (Smooth Hover Changes)
- 21iframe (Embedding Another Page)
- 22position (Precisely Positioning an Element)
- 23z-index (Specifying Stacking Order)
- 24The Basics of localStorage (Saving Data in the Browser)
- 25The video and audio Tags (Embedding Media)
- 26Advanced Tables (colspan and rowspan)
- 27The Basics of CSS Specificity
- 28The Basics of SVG (Drawing Vector Images)
- 29Advanced Flexbox (Wrapping and Growing)
- 30Form Validation (required and pattern)
- 31Advanced CSS Grid (grid-template-areas)
- 32The details and summary Tags (Building a Collapsible Panel)
- 33CSS Counters (Automatic Numbering)
- 34Fluid Font Sizes with clamp()
- 35prefers-color-scheme (Dark Mode Support)
- 36Building a Slider with input type=range
- 37Fixing an Aspect Ratio with aspect-ratio
- 38Adjusting How an Image Displays with object-fit
- 39Rotating and Scaling with transform
- 40Serving Responsive Images with the picture Tag
- 41Showing Keyboard Focus with :focus-visible
- 42Scrolling Smoothly with scroll-behavior
- 43Switching Layouts Per-Component with Container Queries
- 44Creating a Frosted-Glass Effect with backdrop-filter
- 45Building a Flexible Grid with repeat() and minmax()
- 46Fixing a Header in Place with position: sticky
- 47Adding Pseudo-Elements with ::before and ::after
- 48Truncating Long Text with an Ellipsis Using text-overflow
- 49Using a Calculated Value in CSS with calc()
- 50[Applied] Build a Simple Website
The Basics of localStorage (Saving Data in the Browser)
In this lesson you'll learn the basics of saving data in the browser with localStorage, so you can understand a mechanism that survives even after the page is closed. This is for people searching "localStorage usage."
localStorage is a "storage locker inside the browser" that doesn't get cleared when you close the page. You save with setItem() and retrieve with getItem(). This is used for things like preserving what someone typed into a to-do app.
The sample code saves a value with localStorage.setItem('name', 'Taro') when you click one button, and loads and displays the saved value with localStorage.getItem('name') using a different button. Try it and confirm for yourself that the saved value survives even after reloading the page.
A common beginner stumbling block is that localStorage can only store strings. If you want to save a number or an object, you first need to convert it into a string with JSON.stringify() before saving it, and turn it back into its original form with JSON.parse() when retrieving it.
Its distinguishing feature is being able to keep settings or notes using only the user's browser, without sending any data to a server. It's also often used behind the scenes of familiar website features, like remembering whether dark mode was selected.
💡 The preview runs entirely on this page — nothing is sent externally.
", "sampleOutput": "", "goal": "Save data with localStorage.setItem() and read it back with getItem().", "note": "localStorage stores data in the browser. It survives closing the page, so the same data is still there on the next visit."}, "advanced": {"starter": "\n\n", "sampleOutput": "", "goal": "Write a program that saves to localStorage when a button is clicked and shows the stored value on screen.", "note": "addEventListener(\"click\", ...) lets a button press trigger both the save to localStorage and the update to the display."}, "intermediate": {"goal": "Save to localStorage with one button and display the value with another."}}}