Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including side-drawer with all npm packages installed. Try it out:

var sideDrawer = require("side-drawer")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

side-drawer v2.3.0

A simple side drawer element with no dependencies and small as possible

Published on npm



A simple, animating side drawer built as a Web Component

side-drawer demo



You can integrate side-drawer via <script> tag or via NPM.

Via <script> tag

In the <head> of your index.html put a script tag like this:


Now you can use the side-drawer element anywhere in your html, JSX, template, etc.


npm install side-drawer --save

And then you need to import the module before you can use it in your html/jsx/template:

import "side-drawer";

Web Component Browser Support

This web component uses HTML templates, the shadow DOM, and custom elements. If you need to polyfill for any of these standards then take a look at the web components polyfill.

API and Customization


  • open
    • Add this attribute to open the drawer.
      • Example: <side-drawer open></side-drawer>
    • Set the property in Javascript to imperatively toggle the drawer
      • Example: = true
    • In (p)react you might need to set undefined in your JSX (since false !== undefined for html attribute existence)
      • Example: <side-drawer open={this.state.isDrawerOpen || undefined}></side-drawer>


  • open
    • Raised when the drawer is opened.
    • Example: drawer.addEventListener("open", handleOpen())
    • When subscribing in html listen for onopen
      • Ex: <side-drawer onopen="handleOpen()">
  • close -Raised when the drawer is closed.
    • Example: drawer.addEventListener("close", handleClose())
    • When subscribing in html listen for onclose
      • Ex: <side-drawer onclose="handleClose()">


You can style the side-drawer element as you would any regular element, in CSS. A list of supported CSS properties are below, along with the default values.

side-drawer {
  background-color: #ffffff;
  color: inherit;
  width: 350px;
  max-width: 75vw;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;

You can set a backdrop filter using the following CSS variable.

  • --side-drawer-backdrop-filter
    • Sets the backdrop-filter for both the drawer and the overlay that appears to the right of the drawer (when it's open).
    • Default is none

You can customize the overlay that appears to the right of the drawer (when it's open) by setting one of the following CSS variables.

  • --side-drawer-overlay-transition
    • Sets the transition
    • Default is opacity 0.25s ease-in-out 0.25s
  • --side-drawer-overlay-opacity
    • Sets the opacity of the overlay
    • Default is 0.7


This project is built with standard HTML/CSS/TS, no frameworks or special web-component compilers here (for maximum simplicity and minimum size). If you want to learn more about writing custom elements see MDN or this web fundamentals page.

npm install
npm start

This will start a live-server on port localhost:8080. Any changes you make to files in lib/ or any changes to example/index.html should get live reloaded.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free