DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Bookmark Manager App with JavaScript

Browsers already have bookmarks, but they are a mess: hundreds of links, no search, no order. Building your own bookmark manager takes an hour, and it teaches you the most useful skill in front-end development — keeping a list of things in sync with the screen.

What you are building

An app where you save a title and a URL, see all your bookmarks as clickable links, search through them, and delete the ones you no longer need — all saved in localStorage.

The HTML: two inputs and a list

<input id="title-input" placeholder="Site name" />
<input id="url-input" placeholder="https://example.com" />
<button id="save-btn">Save bookmark</button>
<input id="search-input" placeholder="Search bookmarks..." />
<ul id="bookmark-list"></ul>
Enter fullscreen mode Exit fullscreen mode

The JavaScript: the same three-step pattern

let bookmarks = JSON.parse(localStorage.getItem('bookmarks')) || [];

function save() {
  localStorage.setItem('bookmarks', JSON.stringify(bookmarks));
}

function render(filter = '') {
  const list = document.querySelector('#bookmark-list');
  list.innerHTML = '';
  bookmarks
    .filter((b) => b.title.toLowerCase().includes(filter.toLowerCase()))
    .forEach((b, index) => {
      const li = document.createElement('li');
      const link = document.createElement('a');
      link.href = b.url;
      link.textContent = b.title;
      link.target = '_blank';
      li.appendChild(link);
      const del = document.createElement('button');
      del.textContent = 'Delete';
      del.addEventListener('click', () => {
        bookmarks.splice(index, 1);
        save();
        render();
      });
      li.appendChild(del);
      list.appendChild(li);
    });
}

document.querySelector('#save-btn').addEventListener('click', () => {
  const title = document.querySelector('#title-input').value.trim();
  let url = document.querySelector('#url-input').value.trim();
  if (!title || !url) return;
  if (!url.startsWith('http')) url = 'https://' + url;
  bookmarks.push({ title, url });
  save();
  render();
});

document.querySelector('#search-input').addEventListener('input', (e) => {
  render(e.target.value);
});

render();
Enter fullscreen mode Exit fullscreen mode

Two small details do real work here: adding https:// when the user forgets it, and filtering the render by the search box instead of filtering the array — the data stays complete, only the view changes.

The one thing to remember

Build links with document.createElement('a') and set textContent, never with innerHTML and user input. A bookmark title is user input, and innerHTML would let a malicious title run code in your page.

Top comments (0)