Style a Select Box Using Only CSS
by c.bavota | Posted in Tutorials | 36 comments
I often have to use a select box when I’m putting together a custom form that requires a drop down list. It took me a while to figure out how to easily style the select box using only CSS since certain parts are browser specific, such as the drop down arrow.
Here is how a select box will look by default:
This is the HTML code:
<select> <option>Here is the first option</option> <option>The second option</option> </select>
There are certain elements of a select box that we can style such as the font, border, color, padding and background color:
But that annoying drop down arrow always stays the same. There is no direct way to do style it, but the workaround is pretty simple.
First we need to surround our select box element with a div container:
<div class="styled-select">
<select>
<option>Here is the first option</option>
<option>The second option</option>
</select>
</div>
Next we need to add a bit of CSS to make sure that the elements of the select box are styled a certain way:
.styled-select select {
background: transparent;
width: 268px;
padding: 5px;
font-size: 16px;
line-height: 1;
border: 0;
border-radius: 0;
height: 34px;
-webkit-appearance: none;
}
We need to make sure that our select box actually spans wider than the surrounding div container so that the default drop down arrow disappears.
This is the new drop down arrow I want to use:

Our div container needs to be styled like so in order for the new arrow to appear where we want it to:
.styled-select {
width: 240px;
height: 34px;
overflow: hidden;
background: url(new_arrow.png) no-repeat right #ddd;
border: 1px solid #ccc;
}
Our select box should now look like this:
Knowing this little workaround will make it a whole lot easier to style your select box exactly how you want it to be styled using nothing but CSS.



Hi C,
That is a really clever bit of coding. Looks devilishly simple and should do the job just fine. Thanks for sharing!
David
It’s not working properly in chrome..
You need to add
-webkit-appearance: none;and a height value for Chrome and Safari.C,
Would it be easy enough to have a multi-level select, where the main options would also have sub-options branching off from the right of the main options? Might be useful way of organising a large drop-down menu. I’d be interested in buying that type of code.
Cheers
Gillies
Hmm. I would have to say yes but I have never attempted something like that.
Don’t know much about CSS and I need to find some code for my drop down menu site project using CSS for lighter loading instead of using javascript. And I stumbled in this blog thanks for the share…I really need this.
Doesn’t work in IE at all!
Most things don’t work in IE. Hence why you shouldn’t use IE.
That’s disappointing. According to my Google Analytics 80% of my visitors use IE. Any thoughts on an alternative I could use?
@Nicola You would have to use jQuery to create a select box out of a list.
This is pretty great! I have one small problem – if text is too long it overrides the dropdown arrow, did you find a solution for that?
You might have to increase the width in order to solve this issue or include a overflow style.
Bummber it doesn’t work in IE, so how many people can really use this code? Yes “YOU” should not be using IE, but fact is it’s still the majority browser for most sites (unfortunately). Guess it’s cool for non-IE users, otherwise it looks like something is broken for most users…
Works just fine for me in IE 8.
Works perfectly in IE 8
Thanks!
I prefer CSS over javascript for the drop down menu.Mainly because of the loading time and bulky coding in javascript.CSS is easy to code and also reduces the website load time.Yes there are certain issues in CSS like in IE sometimes it overlaps with the larger text but you can avoid this by taking care of the issue while coding.I hope we will soon find the solution to overcome this problem in the future but as of now I will still prefer CSS over javascript.
It works on IE 9, but the previus version of IE show just the select without the arrow.
If you solve it gimme a whistle
good luck
According to my Google Analytics 80% of my visitors use IE. Any thoughts on an alternative I could use?…thanks!!!
The only other alternative for IE users would be to use jQuery to create a similar functionality with a list instead of an actual select box.
I just wanted to say thanks, this is slick I have been building my own dropdowns with divs with all the ifs and timers and everything needed, and here you have a little slick easy solution. I was making a dropdown that’s white with a border, and to get it to look the same in IE I made some modifications, very minor. With this in Chrome and Safari the text will not overlap the arrow, in IE I was unable to fix then the chrome fix pushed the selects arrow back in. You will see I am using div borders to ‘close the box’ hope this helps anyone.
.styled-select select {
background: transparent;
-webkit-appearance: none;
width: 213px;
padding: 5px;
font-size: 13px;
border:1px solid #69A3D3;
height: 28px;
padding-right:55px
}
.styled-select {
width: 183px;
height: 29px;
overflow: hidden;
background:url(/images/20110809/dropArrow3.gif) no-repeat right #FFF;
border-right:1px solid #69A3D3
}
.styled-select select {
padding-right:0px;
vertical-align:top !important;
text-align:left;
line-height:10px;
height:auto;
}
.styled-select {
border-bottom:1px solid #69A3D3
}
just a note I noticed in my last post it stripped the conditional statement surrounding the second set of css which should be in an if < ! – - [if IE]
That idea really brilliant. Initially I did a simple style with pure css but had no effect on the drop arrow. I am looking for a solutions, but most of them using the jquery which makes the code longer. It turned out that your methods more simple ….. thank a lot………….
Opps…Sorry. It doesn’t work for IE. Any additional css code to overcome this?
IE is always a pain in the a$$ to work with since it never respects how every other browser works. This should work in IE8 (I think) but not in earlier versions.
Ignorante.
Complimenti per il tuo contributo costruttivo alla discussione… intelligentone!
thanx dear for help..
For Opera just use:
.styled-select select {
…
.styled-select select
…
}
enjoy
The only way I get this working on Opera (v.11) was to change
.styled-select select {background: transparent;…}
to
.styled-select select {background-color: rgba(0,0,0,0);…}
Mine is not working in IE as well but I guess I’d follow your advice to upgrade it to IE8. Thanks!
Please, how to disable arrow (right) ? Tom
You can just remove the arrow I added by not including that part of the CSS that sets the background image.
This is great – but if you have to accommodate for clients and support more than 3 browsers it’s not a viable solution. Boo.
Thanks A loot *!!!!
I just wanted to say thanks, this is slick I have been building my own dropdowns with divs with all the ifs and timers and everything needed, and here you have a little slick easy solution. I was making a dropdown that’s white with a border, and to get it to look the same in IE I made some modifications, very minor. With this in Chrome and Safari the text will not overlap the arrow, in IE I was unable to fix then the chrome fix pushed the selects arrow back in. You will see I am using div borders to ‘close the box’ hope this helps anyone.
.styled-select select {
background: transparent;
-webkit-appearance: none;
width: 213px;
padding: 5px;
font-size: 13px;
border:1px solid #69A3D3;
height: 28px;
padding-right:55px
}
.styled-select {
width: 183px;
height: 29px;
overflow: hidden;
background:url(/images/20110809/dropArrow3.gif) no-repeat right #FFF;
border-right:1px solid #69A3D3
}
.styled-select select {
padding-right:0px;
vertical-align:top !important;
text-align:left;
line-height:10px;
height:auto;
}
.styled-select {
border-bottom:1px solid #69A3D3
}
How do I make text in option of select align center in Chrome?
I did:
select option{
text-align: center;
}
It work well with FF and IE but doesn’t work with Chrome.