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

      Report: 71% of tech leaders won’t hire devs without AI skills

      July 17, 2025

      Slack’s AI search now works across an organization’s entire knowledge base

      July 17, 2025

      In-House vs Outsourcing for React.js Development: Understand What Is Best for Your Enterprise

      July 17, 2025

      Tiny Screens, Big Impact: The Forgotten Art Of Developing Web Apps For Feature Phones

      July 16, 2025

      Too many open browser tabs? This is still my favorite solution – and has been for years

      July 17, 2025

      This new browser won’t monetize your every move – how to try it

      July 17, 2025

      Pokémon has partnered with one of the biggest PC gaming brands again, and you can actually buy these accessories — but do you even want to?

      July 17, 2025

      AMD’s budget Ryzen AI 5 330 processor will introduce a wave of ultra-affordable Copilot+ PCs with its mobile 50 TOPS NPU

      July 17, 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 details of TC39’s last meeting

      July 18, 2025
      Recent

      The details of TC39’s last meeting

      July 18, 2025

      Reclaim Space: Delete Docker Orphan Layers

      July 18, 2025

      Notes Android App Using SQLite

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

      KeySmith – SSH key management

      July 17, 2025
      Recent

      KeySmith – SSH key management

      July 17, 2025

      Pokémon has partnered with one of the biggest PC gaming brands again, and you can actually buy these accessories — but do you even want to?

      July 17, 2025

      AMD’s budget Ryzen AI 5 330 processor will introduce a wave of ultra-affordable Copilot+ PCs with its mobile 50 TOPS NPU

      July 17, 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

    Artificial Intelligence

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

    July 18, 2025
    Repurposing Protein Folding Models for Generation with Latent Diffusion
    Artificial Intelligence

    Repurposing Protein Folding Models for Generation with Latent Diffusion

    July 18, 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

    “Create a replica of this image. Don’t change anything” AI trend takes off

    Artificial Intelligence

    AMD Radeon RX 9060 XT GPU Now Available In 8GB & 16GB VRAM Options

    Operating Systems

    Escritoire creates standards-compliant letters

    Linux

    What Apple’s controversial research paper really tells us about LLMs

    News & Updates

    Highlights

    News & Updates

    Mixtape is one of the most unique indie games I’ve played, and it’s coming to Xbox Game Pass

    June 17, 2025

    I went hands-on with Mixtape at Summer Game Fest 2025. It’s one of the most…

    A Coding Guide to Compare Three Stability AI Diffusion Models (v1.5, v2-Base & SD3-Medium) Diffusion Capabilities Side-by-Side in Google Colab Using Gradio

    May 5, 2025

    CVE-2025-48376 – DNN External URL Site Export RCE

    May 23, 2025

    CVE-2025-5273 – Mcp-Markdownify-Server File Access Vulnerability

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

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