Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to Make a Dropdown Menu with shadcn/ui

    How to Make a Dropdown Menu with shadcn/ui

    July 17, 2025

    Dropdown menus are little pop-up menus that help you show more options without cluttering your screen. They’re super helpful in websites and apps.

    In this guide, you’ll learn how to build a dropdown menu using shadcn/ui. It’s a tool that works well with Tailwind CSS and Radix UI to help you make nice-looking, easy-to-use menus.

    Table of Contents

    • What is shadcn/ui?

    • Why Use shadcn/ui for Dropdowns?

    • Let’s Build a Dropdown Step-by-Step

      • Step 1: Start a New Project

      • Step 2: Add the Dropdown Menu Component

      • Step 3: Import What You Need

      • Step 4: Build a Simple Dropdown

      • Step 5: Make It Look Better

      • Step 6: Make It Work on All Screens

      • Step 7: Add Cool Icons

      • Step 8: It’s Already Accessible!

    • Real-World Use Case: Country Dropdown with Flags

    • Final Thoughts

    💡 Prerequisites

    Before we start, make sure you have:

    • Basic knowledge of React and JavaScript

    • Node.js and a package manager like npm, pnpm, or yarn are installed

    • Familiarity with Tailwind CSS is a bonus, but not required

    We’ll walk through everything step by step, so don’t worry if you’re not an expert yet.

    What is shadcn/ui?

    shadcn/ui is a group of tools (called components) that help you build parts of a website, like buttons, modals, and dropdowns. It’s built with Radix UI and styled using Tailwind CSS. It’s perfect if you’re using React or Next.js.

    With shadcn/ui, you don’t get just styled components, you get full control over how everything works and looks. That makes it perfect for teams that want consistency in design without giving up flexibility.

    Why Use shadcn/ui for Dropdowns?

    Dropdown menus are a great use case for shadcn/ui because:

    • It’s easy to use with keyboard and screen readers

    • You can create custom looks using Tailwind CSS

    • You control how it works and looks

    • It works great in real websites and apps

    • It integrates well with modern React workflows

    Let’s Build a Dropdown Step-by-Step

    Step 1: Start a New Project with shadcn/ui

    You don’t need to set up React, Next.js, or Tailwind manually. Just run this command:

    pnpm dlx shadcn@latest init
    

    This will automatically create a new Next.js app with Tailwind CSS and shadcn/ui preconfigured.

    Tip: You can also use npx instead of pnpm dlx if you prefer:

    npx shadcn@latest init
    

    Step 2: Add the Dropdown Menu Component

    After your project is ready, add the dropdown component using:

    npx shadcn@latest add dropdown-menu
    

    This will pull in all the necessary components to create a dropdown menu.

    Step 3: Import What You Need

    In your React file, import the full dropdown module so you can access all its features:

    import {
      DropdownMenu,
      DropdownMenuTrigger,
      DropdownMenuContent,
      DropdownMenuItem,
      DropdownMenuLabel,
      DropdownMenuSeparator,
      DropdownMenuShortcut,
      DropdownMenuGroup,
      DropdownMenuSub,
      DropdownMenuSubContent,
      DropdownMenuSubTrigger,
      DropdownMenuPortal,
    } from "@/components/ui/dropdown-menu"
    

    Step 4: Build a Simple Dropdown

    Screenshot of basic dropdown we're building

    Here’s a basic dropdown example:

    export function ProfileMenu() {
      return (
        <DropdownMenu>
          <DropdownMenuTrigger asChild>
            <button className="px-4 py-2 bg-primary text-white rounded">
              Open Menu
            </button>
          </DropdownMenuTrigger>
          <DropdownMenuContent className="w-56">
            <DropdownMenuLabel>My Account</DropdownMenuLabel>
            <DropdownMenuSeparator />
            <DropdownMenuItem>Profile</DropdownMenuItem>
            <DropdownMenuItem>Settings</DropdownMenuItem>
            <DropdownMenuItem>Log out</DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
      )
    }
    

    This is just the start. You can add groups, submenus, and keyboard shortcuts for power users.

    Step 5: Make It Look Better

    Screenshot showing dropdown with styling applied

    Use Tailwind CSS to style your dropdown, and hover effects like this:

    <DropdownMenu>
            <DropdownMenuTrigger asChild>
              <button className="px-3 py-1.5 bg-primary text-white text-sm font-medium rounded-md hover:bg-primary/90 transition-colors">
                Open Menu
              </button>
            </DropdownMenuTrigger>
            <DropdownMenuContent className="w-52 border-gray-200 shadow-lg rounded-md space-y-0.5">
              <DropdownMenuLabel className="text-xs text-gray-500">
                My Account
              </DropdownMenuLabel>
              <DropdownMenuSeparator className="border-t border-gray-100" />
              <DropdownMenuItem className="px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100 rounded-md cursor-pointer transition-colors">
                Profile
              </DropdownMenuItem>
              <DropdownMenuItem className="px-3 py-1.5 text-sm text-gray-700 hover:bg-gray-100 rounded-md cursor-pointer transition-colors">
                Settings
              </DropdownMenuItem>
              <DropdownMenuItem className="px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 rounded-md cur
    

    Step 6: Make It Work on All Screens

    Want your dropdown to be responsive? Use Tailwind’s responsive classes:

    <DropdownMenuContent className="w-full md:w-64">
    

    You can also dynamically position the dropdown using Radix’s built-in portal support.

    Step 7: Add Cool Icons

    Screenshot of dropdown with icons added

    Install Lucide icons:

    npm install lucide-react
    

    Then use them in your menu:

    import { User, Settings, LogOut } from "lucide-react"
    
    <DropdownMenuItem>
      <User className="mr-2 h-4 w-4" /> Profile
    </DropdownMenuItem>
    

    Icons help users scan options quickly – a great touch for UX.

    Step 8: It’s Already Accessible!

    shadcn/ui (thanks to Radix UI) makes your dropdown menu:

    • Keyboard friendly

    • Screen-reader ready

    • Following best web practices

    You don’t need to configure accessibility – it just works 🙂

    Real-World Use Case: Country Dropdown with Flags

    Looking for a more advanced dropdown? Here’s an amazing example that includes search, flag icons, and grouping:

    Shadcn dropdown example

    👉 shadcn-country-dropdown.vercel.app

    It’s open-source and a great place to see what’s possible with shadcn/ui.

    Final Thoughts

    Using shadcn/ui to create a dropdown menu is fast, simple, and powerful. You get great styling, accessibility, and full control over how things look and work. Whether you’re just starting out or building for production, this is a solid tool to use.

    Dropdowns are just the beginning. shadcn/ui offers a whole library of headless components for building modern UIs.

    I hope you found this article helpful! If you’re building a SaaS product or any web app that involves user interaction or conversion, consider enhancing user trust with real-time notifications like modal pop-ups, sales pop up, etc.

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMove over, Tesla Powerwall: EcoFlow’s new home backup system claims to reduce energy bills by up to 90%
    Next Article CVE-2025-7757 – PHPGurukul Land Record System SQL Injection Vulnerability

    Related Posts

    Development

    GPT-5 is Coming: Revolutionizing Software Testing

    July 22, 2025
    Development

    Win the Accessibility Game: Combining AI with Human Judgment

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    The best Memorial Day deals aren’t at Amazon — 5 ultimate discounts on top tech

    News & Updates

    Want a free VPN? How to use ProtonVPN on Android without having to pay

    News & Updates

    CVE-2025-6499 – Apache vstakhov libucl Heap-Based Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-7206 – D-Link DIR-825 HTTPd Stack-Based Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CitrixBleed 2 might be actively exploited (CVE-2025-5777)

    June 30, 2025

    CitrixBleed 2 might be actively exploited (CVE-2025-5777)

    While Citrix has observed some instances where CVE-2025-6543 has been exploited on vulnerable NetScaler networking appliances, the company still says that they don’t have evidence of exploitation for …
    Read more

    Published Date:
    Jun 30, 2025 (2 hours, 57 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2025-6543

    CVE-2025-5777

    CVE-2025-5349

    CVE-2025-5439

    CVE-2023-4966

    CISA Warns of Vulnerabilities in ControlID iDSecure Software Allowing Authentication Bypass

    June 26, 2025

    “You are a shining example of French audacity and creativity.” Clair Obscur: Expedition 33 praised by French President Emmanuel Macron

    May 2, 2025

    Unlocking AI-First Strategy at Agentforce World Tour Boston

    June 20, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.