How to style a <select> dropdown with CSS only without JavaScript
Is there a CSS-only way to style a <select>dropdown?
We need to style a <select>form without any JavaScript. What are the properties we can use to do in CSS?
<select> tags can be styled through CSS just like any other HTML element on an HTML page rendered in a browser. Below is an example that will position a select element on the page and render the text of the options in blue.
Example HTML file:
html code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Select Styling</title> <link href="selectExample.css" rel="stylesheet"> </head> <body> <select id="styledSelect" class="blueText"> <option value="apple">Apple</option> <option value="orange">Orange</option> <option value="cherry">Cherry</option> </select> </body> </html>
[ad type=”banner”]
Example CSS file:
css code
/* All select elements on page */ select { position: relative; }
/* Style by class. Effects the text of the contained options. */ .blueText { color: #0000FF; }
/* Style by id. Effects position of the select drop down. */ #styledSelect { left: 100px; }
You may style any HTML element by its tag name:
css code
select { font-weight: bold; }
you can also use a CSS class to style, like any other element:
html code
<select class="important"> <option>Important Option</option> <option>Another Important Option</option> </select>
As of Internet Explorer 10, you can use the ::-ms-expand pseudo element selector to style, and hide, the drop down arrow element.
css code
select::-ms-expand { display:none; /* or visibility: hidden; to keep it's space/hitbox */ }
The largest variation we have noticed when styling select drop-downs is Safari and Google Chrome rendering (Firefox is fully customizable through CSS).
Here the simplest solution by using WebKit:
css code
select { -webkit-appearance: none; }
It removes the dropdown arrow.
You can add a dropdown arrow using a nearby div with a background, negative margin or absolutely positioned over the select dropdown.
Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.