Contact us for quick support! Contact us!

Downloads

Neon Sidebar Dashboard Full Code Documentation

step-by-step guide to understanding and implementing a Neon Sidebar Dashboard.
Please wait 0 seconds...

Scroll down and click on Go to Link to proceed to your destination.

Congrats! Link is Generated

Neon Sidebar Dashboard Full Code Documentation

This article provides a detailed, step-by-step guide to understanding and implementing a Neon Sidebar Dashboard. The dashboard features a collapsible sidebar with a neon aesthetic, dark mode toggle, dynamic content loading, and accessibility support. 

Neon Sidebar Dashboard

We'll break down the complete code into three sections: HTML, CSS, and JavaScript, explaining each component's purpose, structure, and functionality.

Table of Contents

  1. Overview
  2. HTML: Building the Structure
  3. CSS: Styling the Neon Aesthetic
  4. JavaScript: Adding Interactivity
  5. Full Code
  6. How to Use and Customize
  7. Conclusion

Overview

The Neon Sidebar Dashboard is a modern web interface with a responsive sidebar that expands/collapses, supports light and dark modes, and dynamically updates content based on navigation selections. Key features include:

  • HTML: Structures a fixed sidebar with a profile, navigation links, footer buttons, and a main content area.
  • CSS: Implements a neon and glassmorphism aesthetic with smooth transitions, hover effects, and responsive design.
  • JavaScript: Handles sidebar toggling, dark mode switching, dynamic content updates, and keyboard navigation for accessibility.
  • Accessibility: Uses ARIA attributes and keyboard support for screen reader compatibility.
  • Responsiveness: Adapts to different screen sizes using media queries.

This documentation assumes basic familiarity with HTML, CSS, and JavaScript but explains each part in detail for clarity.

HTML: Building the Structure

The HTML defines the dashboard's layout, consisting of a sidebar and a main content area. It includes metadata, external resources, and semantic elements for accessibility.

HTML Breakdown

1. Document Setup

  • Doctype and Language: <!DOCTYPE html> declares an HTML5 document, and <html lang="en"> sets the language to English for accessibility.
  • Head Section:
    • <meta charset="UTF-8" />: Ensures proper character encoding.
    • <meta name="viewport" content="width=device-width, initial-scale=1.0"/>: Enables responsive design for mobile devices.
    • <title>Neon Sidebar</title>: Sets the page title.
    • <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />: Imports Font Awesome icons for navigation.

2. Body Structure

The <body> contains two main sections:

  • Sidebar (<div class="sidebar" id="sidebar" role="navigation" aria-label="Main navigation">):
    • Profile: A <div class="profile"> with an avatar image (<img src="https://i.pravatar.cc/100" alt="Profile picture" />) and a name (<h2>John Doe</h2>).
    • Navigation Links: A <div class="nav-links"> with five <a> tags for Home, Analytics, Projects, Team, and Settings, each with a Font Awesome icon and text. The data-section attribute identifies the content section, and the Home link has the active class by default.
    • Footer: A <div class="sidebar-footer"> with two buttons: one for toggling the sidebar () and one for dark mode (🌙), both with aria-label for accessibility.
  • Main Content (<main id="main-content">):
    • Contains a heading (<h1>Neon Sidebar Dashboard</h1>) and a dynamic content area (<div id="content">) with an initial welcome message.

3. Accessibility Features

  • ARIA attributes (role="navigation", aria-label="Main navigation", aria-current="page") enhance screen reader compatibility.
  • The role="link" on navigation <a> tags clarifies their purpose for assistive technologies.
  • Buttons include aria-label to describe their function (e.g., "Toggle sidebar").

4. Example HTML Snippet

<div class="sidebar" id="sidebar" role="navigation" aria-label="Main navigation">
  <div class="profile">
    <img src="https://i.pravatar.cc/100" alt="Profile picture" />
    <h2>John Doe</h2>
  </div>
  <div class="nav-links">
    <a href="#" data-section="home" class="active" role="link" aria-current="page"><i class="fas fa-home"></i><span>Home</span></a>
    <a href="#" data-section="analytics" role="link"><i class="fas fa-chart-bar"></i><span>Analytics</span></a>
  </div>
  <div class="sidebar-footer">
    <button class="footer-btn" onclick="toggleSidebar()" aria-label="Toggle sidebar">☰</button>
    <button class="footer-btn" onclick="toggleDarkMode()" aria-label="Toggle dark mode">🌙</button>
  </div>
</div>
<main id="main-content">
  <h1>Neon Sidebar Dashboard</h1>
  <div id="content">
    <p>Welcome to the Home section of the Neon Sidebar Dashboard.</p>
  </div>
</main>

5. Purpose

  • The sidebar provides navigation and user controls, remaining fixed on the left.
  • The main content area displays dynamic content based on the selected navigation link.
  • The structure is semantic and accessible, with clear roles for each section.

CSS: Styling the Neon Aesthetic

The CSS defines the visual design, incorporating a neon glow, glassmorphism effects, dark mode, and responsive behavior. It uses CSS custom properties for maintainability and smooth transitions for interactivity.

CSS Breakdown

1. Custom Properties (:root)

  • Defines reusable variables for colors, transitions, and margins:
    • --neon: #00eaff and --neon-secondary: #ff00dd for neon colors.
    • --bg-light: #f8fafc and --bg-dark: #121212 for light/dark backgrounds.
    • --glass-bg-light and --glass-bg-dark for glassmorphism effects.
    • --hover-glow for neon glow effects on hover.
    • --transition: all 0.3s ease for smooth animations.
    • --margin: 2rem for consistent spacing.

2. Global Styles

  • *: Resets margins/padding, uses box-sizing: border-box, and applies font smoothing for crisp text.
  • body: Sets the font family (Segoe UI, Tahoma, Geneva, Verdana, sans-serif), uses a flex layout to position the sidebar and main content, and defaults to light mode (--bg-light).
  • body.dark-mode: Switches to dark mode with --bg-dark and light text (--text-light).

3. Sidebar Styles

  • Base Sidebar:
    • Fixed width of 70px, full viewport height (min-height: 100vh).
    • Uses a glassmorphism effect with backdrop-filter: blur(15px) and a gradient background (linear-gradient).
    • Fixed positioning (position: fixed) keeps it on the left, with z-index: 1000 to ensure it stays above other elements.
  • Expanded Sidebar:
    • .sidebar.expanded: Increases width to 300px and adjusts padding for more space.
  • Profile:
    • Centers an avatar image with a neon conic gradient border (conic-gradient) and animated glow (@keyframes rotateGradient).
    • .sidebar.expanded .profile img: Enlarges the image to 90px when expanded.
    • The <h2> name scales up in expanded mode and adjusts color for dark mode.
  • Navigation Links:
    • .nav-links a: Flexbox-aligned links with icons and hidden text (display: none).
    • .sidebar.expanded .nav-links a span: Shows text when expanded.
    • Hover effects include scaling (transform: scale(1.05)), neon glow (box-shadow: --hover-glow), and a glassmorphism background.
    • .nav-links a.active: Highlights the active link with a neon border and glow.
  • Footer Buttons:
    • .footer-btn: Styled with glassmorphism, rounded corners, and neon hover effects.
    • .sidebar.expanded .sidebar-footer: Switches to a row layout for buttons when expanded.

4. Main Content

  • main: Adjusts margin-left to 70px (collapsed) or 300px (expanded, with .full-width).
  • Uses transition for smooth margin shifts.

5. Dark Mode

  • body.dark-mode modifies backgrounds and text colors for the sidebar, links, and buttons to maintain contrast and the neon aesthetic.

6. Animations

  • @keyframes rotateGradient: Animates the profile image's conic gradient border for a rotating neon effect.
  • Transitions (--transition) ensure smooth changes for hover, expansion, and dark mode toggling.

7. Responsive Design

  • @media (max-width: 768px): Ensures the sidebar remains 70px when collapsed and 300px when expanded on smaller screens, with consistent layout for main content.

8. Example CSS Snippet

:root {
  --neon: #00eaff;
  --bg-light: #f8fafc;
  --bg-dark: #121212;
  --transition: all 0.3s ease;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-light);
  display: flex;
  transition: var(--transition);
}

.sidebar {
  width: 70px;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--glass-bg-light) 0%, rgba(255, 255, 255, 0.15) 100%);
  backdrop-filter: blur(15px);
  position: fixed;
  transition: width 0.4s ease, padding 0.4s ease;
}

.sidebar.expanded {
  width: 300px;
  padding: var(--margin) 1.5rem;
}

.profile img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid transparent;
  background: conic-gradient(var(--neon) 0deg, var(--neon-secondary) 90deg, var(--neon) 180deg, var(--neon-secondary) 270deg);
  box-shadow: var(--hover-glow);
  animation: rotateGradient 4s linear infinite;
}

9. Purpose

  • Creates a visually appealing neon and glassmorphism aesthetic.
  • Ensures smooth transitions and hover effects.
  • Supports light/dark modes and responsive design for various devices.

JavaScript: Adding Interactivity

The JavaScript adds interactivity to the dashboard, handling sidebar toggling, dark mode switching, dynamic content loading, and keyboard navigation.

JavaScript Breakdown

1. Toggle Sidebar (toggleSidebar)

  • Toggles the .expanded class on the sidebar (#sidebar) and .full-width class on the <main> element to expand/collapse the sidebar.
  • Adjusts the layout to accommodate the sidebar's width change.
  • Example:
    function toggleSidebar() {
      const sidebar = document.getElementById("sidebar");
      const main = document.querySelector("main");
      sidebar.classList.toggle("expanded");
      main.classList.toggle("full-width");
    }
    

2. Toggle Dark Mode (toggleDarkMode)

  • Toggles the .dark-mode class on the <body> to switch between light and dark themes.
  • Saves the preference to localStorage for persistence across page reloads.
  • Example:
    function toggleDarkMode() {
      document.body.classList.toggle("dark-mode");
      localStorage.setItem("darkMode", document.body.classList.contains("dark-mode"));
    }
    

3. Load Dark Mode Preference

  • Checks localStorage on page load and applies the .dark-mode class if previously enabled.
  • Example:
    if (localStorage.getItem("darkMode") === "true") {
      document.body.classList.add("dark-mode");
    }
    

4. Dynamic Content Loading

  • Attaches click event listeners to navigation links (.nav-links a).
  • Prevents default link behavior (e.preventDefault()).
  • Removes the active class from all links, adds it to the clicked link, and updates the #content div with text based on the data-section attribute.
  • Example:
    const navLinks = document.querySelectorAll(".nav-links a");
    const contentDiv = document.getElementById("content");
    navLinks.forEach(link => {
      link.addEventListener("click", (e) => {
        e.preventDefault();
        navLinks.forEach(l => l.classList.remove("active"));
        link.classList.add("active");
        const section = link.getAttribute("data-section");
        contentDiv.innerHTML = `<p>Welcome to the ${section.charAt(0).toUpperCase() + section.slice(1)} section.</p>`;
      });
    });
    

5. Keyboard Navigation

  • Adds keydown event listeners to navigation links, triggering a click when Enter or Space is pressed for accessibility.
  • Example:
    navLinks.forEach(link => {
      link.addEventListener("keydown", (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          link.click();
        }
      });
    });
    

6. Purpose

  • Enables interactive features like sidebar expansion, dark mode toggling, and content switching.
  • Enhances accessibility with keyboard navigation.
  • Persists user preferences using localStorage.

Full Code

Below is the complete code for the Neon Sidebar Dashboard, combining HTML, CSS, and JavaScript.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Neon Sidebar</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
  <style>
    :root {
      --neon: #00eaff;
      --neon-secondary: #ff00dd;
      --bg-light: #f8fafc;
      --bg-dark: #121212;
      --text-dark: #1a1a1a;
      --text-light: #f5f5f5;
      --glass-bg-light: rgba(255, 255, 255, 0.25);
      --glass-bg-dark: rgba(30, 30, 30, 0.25);
      --glass-border: 1px solid rgba(255, 255, 255, 0.3);
      --hover-glow: 0 0 12px var(--neon), 0 0 18px var(--neon), 0 0 30px var(--neon), 0 0 60px var(--neon);
      --transition: all 0.3s ease;
      --margin: 2rem;
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }

    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: var(--bg-light);
      color: var(--text-dark);
      display: flex;
      transition: var(--transition);
    }

    body.dark-mode {
      background: var(--bg-dark);
      color: var(--text-light);
    }

    .sidebar {
      width: 70px;
      min-height: 100vh;
      background: linear-gradient(180deg, var(--glass-bg-light) 0%, rgba(255, 255, 255, 0.15) 100%);
      backdrop-filter: blur(15px);
      box-shadow: 3px 0 25px rgba(0,0,0,0.2);
      padding: var(--margin) 0.5rem;
      display: flex;
      flex-direction: column;
      position: fixed;
      z-index: 1000;
      transition: width 0.4s ease, padding 0.4s ease;
    }

    body.dark-mode .sidebar {
      background: linear-gradient(180deg, var(--glass-bg-dark) 0%, rgba(30, 30, 30, 0.15) 100%);
    }

    .sidebar.expanded {
      width: 300px;
      padding: var(--margin) 1.5rem;
    }

    .profile {
      text-align: center;
      margin-bottom: var(--margin);
      position: relative;
    }

    .profile img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 4px solid transparent;
      background: conic-gradient(var(--neon) 0deg, var(--neon-secondary) 90deg, var(--neon) 180deg, var(--neon-secondary) 270deg);
      background-clip: padding-box;
      box-shadow: var(--hover-glow);
      animation: rotateGradient 4s linear infinite;
      transition: var(--transition);
    }

    .sidebar.expanded .profile img {
      width: 90px;
      height: 90px;
    }

    .profile h2 {
      font-size: 0.9rem;
      margin-top: 0.8rem;
      color: var(--text-dark);
      opacity: 1;
      transition: opacity 0.3s ease;
      font-weight: 600;
    }

    .sidebar.expanded .profile h2 {
      font-size: 1.4rem;
    }

    body.dark-mode .profile h2 {
      color: var(--text-light);
    }

    .nav-links {
      flex: 1;
      margin-bottom: var(--margin);
    }

    .nav-links a {
      display: flex;
      align-items: center;
      gap: 1.2rem;
      padding: 1rem 0.5rem;
      margin: 0.6rem 0;
      text-decoration: none;
      color: var(--text-dark);
      font-size: 1rem;
      border-radius: 12px;
      position: relative;
      overflow: hidden;
      transition: var(--transition);
      background: transparent;
    }

    body.dark-mode .nav-links a {
      color: var(--text-light);
    }

    .nav-links a i {
      font-size: 1.3rem;
      color: var(--neon);
      transition: var(--transition);
    }

    .nav-links a span {
      display: none;
      white-space: nowrap;
      font-weight: 500;
    }

    .sidebar.expanded .nav-links a span {
      display: inline;
    }

    .nav-links a:hover {
      background: var(--glass-bg-light);
      color: black;
      transform: scale(1.05);
      box-shadow: var(--hover-glow);
    }

    body.dark-mode .nav-links a:hover {
      background: var(--glass-bg-dark);
    }

    .nav-links a:hover i {
      transform: rotate(15deg);
    }

    .nav-links a.active {
      background: var(--glass-bg-light);
      color: black;
      box-shadow: var(--hover-glow);
      border: 2px solid var(--neon);
    }

    body.dark-mode .nav-links a.active {
      background: var(--glass-bg-dark);
    }

    .nav-links a.active i {
      color: var(--neon);
    }

    .sidebar-footer {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.8rem;
      margin-top: auto;
    }

    .sidebar.expanded .sidebar-footer {
      flex-direction: row;
      justify-content: space-between;
    }

    .footer-btn {
      background: var(--glass-bg-light);
      border: 2px solid transparent;
      padding: 0.5rem 0.8rem;
      border-radius: 12px;
      font-size: 1.1rem;
      color: var(--neon);
      cursor: pointer;
      transition: var(--transition);
      position: relative;
      overflow: hidden;
      width: 40px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }

    body.dark-mode .footer-btn {
      background: var(--glass-bg-dark);
    }

    .sidebar.expanded .footer-btn {
      width: auto;
      padding: 0.5rem 1rem;
    }

    .footer-btn:hover,
    .footer-btn:active {
      border: 2px solid var(--neon);
      color: var(--text-dark);
      box-shadow: var(--hover-glow);
      transform: scale(1.05);
    }

    body.dark-mode .footer-btn:hover,
    body.dark-mode .footer-btn:active {
      color: var(--text-light);
    }

    main {
      margin-left: 70px;
      padding: var(--margin);
      width: 100%;
      transition: var(--transition);
    }

    main.full-width {
      margin-left: 300px;
    }

    @keyframes rotateGradient {
      0% {
        background-position: 0% 50%;
      }
      100% {
        background-position: 360% 50%;
      }
    }

    @media (max-width: 768px) {
      .sidebar {
        width: 70px;
      }

      .sidebar.expanded {
        width: 300px;
        padding: var(--margin) 1.5rem;
      }

      .sidebar.expanded .nav-links a span {
        display: inline;
      }

      .sidebar.expanded .sidebar-footer {
        flex-direction: row;
        justify-content: space-between;
      }

      .sidebar.expanded .footer-btn {
        width: auto;
        padding: 0.5rem 1rem;
      }

      main {
        margin-left: 70px;
      }

      main.full-width {
        margin-left: 300px;
      }
    }
  </style>
</head>
<body>
  <div class="sidebar" id="sidebar" role="navigation" aria-label="Main navigation">
    <div class="profile">
      <img src="https://i.pravatar.cc/100" alt="Profile picture" />
      <h2>John Doe</h2>
    </div>
    <div class="nav-links">
      <a href="#" data-section="home" class="active" role="link" aria-current="page"><i class="fas fa-home"></i><span>Home</span></a>
      <a href="#" data-section="analytics" role="link"><i class="fas fa-chart-bar"></i><span>Analytics</span></a>
      <a href="#" data-section="projects" role="link"><i class="fas fa-folder-open"></i><span>Projects</span></a>
      <a href="#" data-section="team" role="link"><i class="fas fa-users"></i><span>Team</span></a>
      <a href="#" data-section="settings" role="link"><i class="fas fa-cog"></i><span>Settings</span></a>
    </div>
    <div class="sidebar-footer">
      <button class="footer-btn" onclick="toggleSidebar()" aria-label="Toggle sidebar">☰</button>
      <button class="footer-btn" onclick="toggleDarkMode()" aria-label="Toggle dark mode">🌙</button>
    </div>
  </div>

  <main id="main-content">
    <h1>Neon Sidebar Dashboard</h1>
    <div id="content">
      <p>Welcome to the Home section of the Neon Sidebar Dashboard.</p>
    </div>
  </main>

  <script>
    // Toggle sidebar visibility
    function toggleSidebar() {
      const sidebar = document.getElementById("sidebar");
      const main = document.querySelector("main");
      sidebar.classList.toggle("expanded");
      main.classList.toggle("full-width");
    }

    // Toggle dark mode and save preference
    function toggleDarkMode() {
      document.body.classList.toggle("dark-mode");
      localStorage.setItem("darkMode", document.body.classList.contains("dark-mode"));
    }

    // Load dark mode preference
    if (localStorage.getItem("darkMode") === "true") {
      document.body.classList.add("dark-mode");
    }

    // Dynamic content loading
    const navLinks = document.querySelectorAll(".nav-links a");
    const contentDiv = document.getElementById("content");

    navLinks.forEach(link => {
      link.addEventListener("click", (e) => {
        e.preventDefault();
        navLinks.forEach(l => l.classList.remove("active"));
        link.classList.add("active");

        const section = link.getAttribute("data-section");
        contentDiv.innerHTML = `<p>Welcome to the ${section.charAt(0).toUpperCase() + section.slice(1)} section.</p>`;
      });
    });

    // Keyboard navigation support
    navLinks.forEach(link => {
      link.addEventListener("keydown", (e) => {
        if (e.key === "Enter" || e.key === " ") {
          e.preventDefault();
          link.click();
        }
      });
    });
  </script>
</body>
</html>

How to Use and Customize

Using the Dashboard

  1. Setup: Save the code as index.html and open it in a web browser. No server is required since it uses a CDN for Font Awesome and a placeholder image.
  2. Interaction:
    • Click the button to expand/collapse the sidebar.
    • Click the 🌙 button to toggle dark mode.
    • Click navigation links to update the content area.
    • Use Enter or Space on navigation links for keyboard accessibility.
  3. Persistence: Dark mode preference is saved in localStorage and persists across page reloads.

Customization Ideas

  • Change Colors: Modify --neon and --neon-secondary in :root for different neon hues.
  • Add Navigation Links: Add more <a> tags in .nav-links with unique data-section attributes and update the JavaScript content logic.
  • Dynamic Content: Replace the placeholder content in the #content div with API calls or static HTML.
  • Profile Image: Replace https://i.pravatar.cc/100 with a custom image URL.
  • Animations: Adjust the @keyframes rotateGradient duration or add new animations for other elements.

Example Customization

To add a new "Reports" link:

  1. Add to HTML:
    <a href="#" data-section="reports" role="link"><i class="fas fa-file-alt"></i><span>Reports</span></a>
    
  2. Update JavaScript content logic if needed:
    if (section === "reports") {
      contentDiv.innerHTML = `<p>View your reports here.</p>`;
    } else {
      contentDiv.innerHTML = `<p>Welcome to the ${section.charAt(0).toUpperCase() + section.slice(1)} section.</p>`;
    }
    

Conclusion

The Neon Sidebar Dashboard is a fully functional, visually appealing web interface that combines HTML for structure, CSS for a neon and glassmorphism aesthetic, and JavaScript for interactivity. It demonstrates best practices for responsive design, accessibility, and user experience. By following this documentation, you can understand each component, implement the dashboard, and customize it for your needs. Experiment with colors, animations, or additional features to make it your own!

Getting Info...

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.