
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to create an animated, closable side navigation menu with CSS?
Following is the code to create an animated, closable side navigation menu −
Example
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> .sideNav { height: 100vh; width: 0; position: fixed; z-index: 1; top: 0; left: 0; background-color: rgb(46, 218, 195); overflow-x: hidden; padding-top: 60px; transition: 0.5s; } .sideNav a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #000000; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; display: block; transition: 0.3s; } .sidenav a:hover { color: #f1f1f1; } .sideNav .closeBtn { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; } button { padding: 15px; background-color: rgb(0, 27, 145); color: rgb(255, 255, 255); font-size: 20px; border: none; border-radius: 2%; } </style> </head> <body> <nav class="sideNav"> <a href="#" class="closeBtn">×</a> <a href="#">Login</a> <a href="#">Register</a> <a href="#">Home</a> <a href="#">About Us</a> </nav> <button class="openSideNav">Click here to open sideNav</button> <script> let openBtn = document.querySelector(".openSideNav"); openBtn.addEventListener("click", () => { showNav(); }); let closeBtn = document.querySelector(".closeBtn"); closeBtn.addEventListener("click", () => { hideNav(); }); function showNav() { document.querySelector(".sideNav").style.width = "300px"; } function hideNav() { document.querySelector(".sideNav").style.width = "0"; } </script> </body> </html>
Output
This will produce the following output −
On clicking the button side navigation will open −
On clicking the cross button the side navigation will close.
- Related Articles
- How to create a fixed side navigation menu with CSS?
- How to create a responsive side navigation menu with CSS?
- How to create a side navigation menu with icons using CSS?\n
- How to create a bottom navigation menu with CSS?
- How to create a pill navigation menu with CSS?
- How to create a curtain navigation menu with CSS and JavaScript?
- How to create a responsive navigation menu with icons, using CSS?\n
- How to create a responsive bottom navigation menu with CSS and JavaScript?
- Create a responsive navigation menu with CSS Media Queries
- How to add a navigation menu on an image with CSS?
- How to create an animated search form with CSS?
- How to create a full screen overlay navigation menu with CSS and JavaScript?
- How to create a top navigation menu for smartphones / tablets with CSS and JavaScript?
- How to create a mega menu (full-width dropdown menu in a navigation bar) with HTML and CSS?
- How to create a navigation menu with an input field inside of it?

Advertisements