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

      The state of DevOps and AI: Not just hype

      September 1, 2025

      A Breeze Of Inspiration In September (2025 Wallpapers Edition)

      August 31, 2025

      10 Top Generative AI Development Companies for Enterprise Node.js Projects

      August 30, 2025

      Prompting Is A Design Act: How To Brief, Guide And Iterate With AI

      August 29, 2025

      Look out, Meta Ray-Bans! These AI glasses just raised over $1M in pre-orders in 3 days

      September 2, 2025

      Samsung ‘Galaxy Glasses’ powered by Android XR are reportedly on track to be unveiled this month

      September 2, 2025

      The M4 iPad Pro is discounted $100 as a last-minute Labor Day deal

      September 2, 2025

      Distribution Release: Linux From Scratch 12.4

      September 1, 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

      Enhanced Queue Job Control with Laravel’s ThrottlesExceptions failWhen() Method

      September 2, 2025
      Recent

      Enhanced Queue Job Control with Laravel’s ThrottlesExceptions failWhen() Method

      September 2, 2025

      August report 2025

      September 2, 2025

      Fake News Detection using Python Machine Learning (ML)

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

      Installing Proxmox on a Raspberry Pi to run Virtual Machines on it

      September 2, 2025
      Recent

      Installing Proxmox on a Raspberry Pi to run Virtual Machines on it

      September 2, 2025

      Download Transcribe! for Windows

      September 1, 2025

      Microsoft Fixes CertificateServicesClient (CertEnroll) Error in Windows 11

      September 1, 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

    Enhanced Queue Job Control with Laravel’s ThrottlesExceptions failWhen() Method

    September 2, 2025
    Artificial Intelligence

    Scaling Up Reinforcement Learning for Traffic Smoothing: A 100-AV Highway Deployment

    September 2, 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

    Microsoft Fixes CertificateServicesClient (CertEnroll) Error in Windows 11

    Operating Systems

    Stanford Researchers Propose FramePack: A Compression-based AI Framework to Tackle Drifting and Forgetting in Long-Sequence Video Generation Using Efficient Context Management and Sampling

    Machine Learning

    Grab this 230-piece Craftsman toolset for just $99 at Lowe’s

    News & Updates

    I’m thankful for those Xbox Helldivers 2 reinforcements, because Sweet Liberty, the latest Major Order is absolutely absurd — can players pull it off?

    News & Updates

    Highlights

    CVE-2025-7483 – PHPGurukul Vehicle Parking Management System SQL Injection Vulnerability

    July 12, 2025

    CVE ID : CVE-2025-7483

    Published : July 12, 2025, 6:15 p.m. | 26 minutes ago

    Description : A vulnerability was found in PHPGurukul Vehicle Parking Management System 1.13. It has been rated as critical. This issue affects some unknown processing of the file /users/forgot-password.php. The manipulation of the argument email leads to sql injection. The attack may be initiated remotely. The exploit has been disclosed to the public and may be used.

    Severity: 7.3 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Sam Altman is afraid of OpenAI’s GPT-5 creation — “The Manhattan Project feels very fast, like there are no adults in the room”

    August 1, 2025

    New Malware Loaders Use Call Stack Spoofing, GitHub C2, and .NET Reactor for Stealth

    April 2, 2025

    CVE-2025-31239 – Apple File Parsing Use-after-free Vulnerability

    May 12, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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