Skip to content

Slide Drawer

A copy-paste modals & overlays component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Modals & OverlaysHTMLCSSJavaScriptany framework

Copy into your project

HTML
<!-- Backdrop -->
<div class="nuda-drawer-backdrop" id="drawer-backdrop">
  <!-- Drawer panel -->
  <aside class="nuda-drawer" role="dialog" aria-label="Navigation drawer">
    <button class="nuda-drawer__close" aria-label="Close">&times;</button>
    <nav class="nuda-drawer__nav">
      <a href="#" class="nuda-drawer__link">Home</a>
      <a href="#" class="nuda-drawer__link">About</a>
      <a href="#" class="nuda-drawer__link">Projects</a>
      <a href="#" class="nuda-drawer__link">Contact</a>
    </nav>
  </aside>
</div>
CSS
/* Slide Drawer
   Off-canvas drawer that slides in from the right.
   Customize: --drawer-width, --drawer-bg */

.nuda-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.nuda-drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.nuda-drawer {
  --drawer-width: 320px;
  --drawer-bg: #111;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 85%;
  background: var(--drawer-bg);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding: 2rem 1.5rem;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.nuda-drawer-backdrop.is-open .nuda-drawer {
  transform: translateX(0);
}

.nuda-drawer__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: #666;
  font-size: 1.25rem;
  cursor: pointer;
}

.nuda-drawer__nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 2rem;
}

.nuda-drawer__link {
  color: #ccc;
  text-decoration: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
}

.nuda-drawer__link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .nuda-drawer-backdrop,
  .nuda-drawer {
    transition: none;
  }
}
JavaScript
/* Slide Drawer — Toggle with .is-open class */

(function () {
  var backdrop = document.getElementById('drawer-backdrop');
  if (!backdrop) return;

  var closeBtn = backdrop.querySelector('.nuda-drawer__close');

  function close() {
    backdrop.classList.remove('is-open');
  }

  if (closeBtn) closeBtn.addEventListener('click', close);

  backdrop.addEventListener('click', function (e) {
    if (e.target === backdrop) close();
  });

  document.addEventListener('keydown', function (e) {
    if (e.key === 'Escape') close();
  });
})();

How to use Slide Drawer

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More modals & overlays components

← Browse all NudaUI components