CSS Animation Example: Reveal Drawer

The "Reveal Drawer" (also known as an off-canvas menu) is an essential pattern for mobile layouts, swiping in from the side to reveal navigation links.

Click the button to slide the drawer open and push this content.

This layout positions a sidebar off-screen by setting a negative left value equal to its width (e.g., left: -250px). When triggered, a transition animates transform: translateX(250px) to smoothly slide the menu into view. For a more interactive feel, we can simultaneously apply a margin or transform to the main content area, making it look as though the drawer is physically "pushing" the webpage over.

Here is the code to create the Reveal Drawer animation.

View Output

Accessibility Considerations

Large swaths of the screen moving horizontally can trigger motion sickness for some users. Respecting prefers-reduced-motion is crucial here. prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their operating system or browser to minimize the amount of non-essential animation or motion. By removing the transition, the layout snaps instantly into its final position without the sliding movement.

Here's what we used in our example:


@media (prefers-reduced-motion: reduce) {
    .drawer, #main {
        /* Disables the sliding animation, so the menu jumps into view */
        transition: none; 
    }
}