Source Code

<div class="pn-wrap">
  <h2 class="pn-heading">Sticky Notes</h2>
  <div class="pn-composer">
    <textarea id="pnInput" placeholder="Write a note..." rows="2"></textarea>
    <button id="pnAdd" class="pn-add-btn">Add note</button>
  </div>
  <div class="pn-grid" id="pnGrid"></div>
</div>

Persistent Sticky Notes App — Free HTML CSS JS Snippet

Persistent Sticky Notes App · Misc · Plain HTML, CSS & JS · Live preview

What's included

Features

Notes persisted to localStorage as a JSON array via localStorage.setItem on every add and delete
Notes restored on page load via localStorage.getItem wrapped in try/catch for safety
Automatic pre-seeding of example notes into localStorage on first visit so the grid never starts empty
Randomly assigned pastel background color per note, fixed at creation time
Delete button on each note that immediately updates both the UI and localStorage
Cmd/Ctrl+Enter keyboard shortcut to add a note without touching the button
Responsive auto-fill grid that adapts note card count to available width

About this UI Snippet

Persistent Sticky Notes App — Notes Saved to localStorage

Screenshot of the Persistent Sticky Notes App snippet rendered live

This snippet is a small sticky-notes app: a textarea and "Add note" button create colorful note cards in a grid, and every note is persisted to the browser's localStorage so they survive a page reload.

Reading and writing localStorage as JSON

The entire notes collection is stored under one key, 'notes', as a JSON string. saveNotes(notes) calls localStorage.setItem('notes', JSON.stringify(notes)) after every add or delete. On load, loadNotes() calls localStorage.getItem('notes'), wraps the JSON.parse in a try/catch, and returns null if the key is missing, the JSON is malformed, or the parsed value isn't an array — so a corrupted or absent value never crashes the app.

Pre-seeding for a real first-load experience

If loadNotes() returns null (first visit, nothing saved yet), the app seeds three example notes into the notes array and immediately calls saveNotes() so localStorage itself now holds real content, not just the in-memory array — meaning even a hard refresh right after first load shows the same seeded notes rather than an empty state.

Rendering and mutation

render() rebuilds the grid from the notes array on every change. Each note gets a randomly chosen pastel background from a small COLORS palette at creation time (stored on the note object so its color doesn't change on re-render), and a delete button that filters the note out of the array, persists the updated array, and re-renders.

Step by step

How to Use

  1. 1
    Load the snippetClick "Persistent Sticky Notes App" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

Personal note-taking widgets
A lightweight notes board for dashboards, browser extensions, or personal tools.
Reference for localStorage JSON persistence
Shows the getItem/setItem plus JSON.stringify/parse pattern with defensive error handling.
Teaching client-side persistence
A clear example of pre-seeding default data only when storage is empty.
Idea boards and brainstorming tools
Quick capture of scattered thoughts that persist without any backend.

Got questions?

Frequently Asked Questions

Entirely in the browser via localStorage.setItem('notes', JSON.stringify(notes)) — there is no server or database. Notes persist across page reloads on the same browser and device but are not synced anywhere else.

loadNotes() wraps JSON.parse in a try/catch and returns null on any error, or if the parsed value is not an array. The app then falls back to seeding the default example notes instead of crashing.

So the initial experience — and any screenshot or demo — shows real content instead of an empty grid. The seeded notes are also immediately written to localStorage, not just held in memory.

Yes, the color is chosen once when a note is created and stored as a field on the note object itself, so re-rendering the grid (e.g. after a delete) does not reshuffle colors.