Open In App

How to Style a Dropdown Using CSS?

Last Updated : 19 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

To style a dropdown using CSS means customizing how a <select> element and its options appear—such as changing the width, background, font, border, or hover effects.

You can style dropdowns using basic CSS properties or enhance them further with pseudo-classes like :hover and :focus, and even use wrappers or custom arrows for a more modern look.

Example 1: Basic Styling of a Dropdown Menu

In this example, we'll style the dropdown menu by changing the background color, text color, and font size, and adding a pointer cursor to make it more engaging.

HTML
<html>
<head>
    <style>
        select {
            appearance: none;
            outline: 0;
            background: green;
            background-image: none;
            width: 100%;
            height: 100%;
            color: black;
            cursor: pointer;
            border: 1px solid black;
            border-radius: 3px;
        }

        .select {
            position: relative;
            display: block;
            width: 15em;
            height: 2em;
            line-height: 3;
            overflow: hidden;
            border-radius: .25em;
            padding-bottom: 10px;
        }

        h1 {
            color: green;
        }
    </style>
</head>

<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <div class="select">
            <select name="slct" id="slct">
                <option>Computer Science Subjects</option>
                <option value="1">Operating System</option>
                <option value="2">Computer Networks</option>
                <option value="3">Data Structure</option>
                <option value="4">Algorithm</option>
                <option value="5">C programming</option>
                <option value="6">JAVA</option>
            </select>
        </div>
    </center>
</body>

</html>

Example 2: Cross-browser Compatibility with Vendor Prefixes

Different browsers render dropdowns differently, so using vendor prefixes helps maintain a consistent style across browsers. In this example, we’ll ensure the styling works on Chrome, Firefox, and Edge by using vendor-specific prefixes.

HTML
<!DOCTYPE html>
<html>

<head>
    <style>
        h1 {
            color: green;
        }

        select {
            -webkit-appearance: none;
            -moz-appearance: none;
            -ms-appearance: none;
            appearance: none;
            outline: 0;
            background: green;
            background-image: none;
            border: 1px solid black;
        }

        .select {
            position: relative;
            display: block;
            width: 20em;
            height: 3em;
            line-height: 3;
            background: #2C3E50;
            overflow: hidden;
            border-radius: .25em;
        }

        select {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0 0 0 .5em;
            color: #fff;
            cursor: pointer;
        }

        select::-ms-expand {
            display: none;
        }

        .select::after {
            content: '\25BC';
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            padding: 0 1em;
            background: #34495E;
            pointer-events: none;
        }

        .select:hover::after {
            color: #F39C12;
        }

        < !-- For different browsers -->.select::after {
            -webkit-transition: .25s all ease;
            -o-transition: .25s all ease;
            transition: .25s all ease;
        }
    </style>
</head>

<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <div class="select">
            <select name="slct" id="slct">
                <option>Computer Science Subjects</option>
                <option value="1">Operating System</option>
                <option value="2">Computer Networks</option>
                <option value="3">Data Structure</option>
                <option value="4">Algorithm</option>
                <option value="5">C programming</option>
                <option value="6">JAVA</option>
            </select>
        </div>
    </center>
</body>

</html>

Best Practices for Styling Dropdowns

  • Maintain Accessibility: Ensure that your custom styles do not hinder keyboard navigation or screen reader accessibility.
  • Consistent Design: Keep the dropdown's appearance consistent with the overall theme of your website.
  • Responsive Layout: Make sure the dropdown is usable on various devices, including mobile phones and tablets.
  • Fallbacks: Provide fallback styles for browsers that may not fully support certain CSS properties.

Conclusion

Styling dropdown lists using CSS allows you to create more engaging and user-friendly forms. By customizing the appearance and behavior of dropdowns, you can enhance the overall user experience on your website.

CSS is the foundation of webpages, is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.


Similar Reads