[html] How do I style a <select> dropdown with only CSS?

In modern browsers it's relatively painless to style the <select> in CSS. With appearance: none the only tricky part is replacing the arrow (if that's what you want). Here's a solution that uses an inline data: URI with plain-text SVG:

_x000D_
_x000D_
select {_x000D_
  -moz-appearance: none;_x000D_
  -webkit-appearance: none;_x000D_
  appearance: none;_x000D_
  _x000D_
  background-repeat: no-repeat;_x000D_
  background-size: 0.5em auto;_x000D_
  background-position: right 0.25em center;_x000D_
  padding-right: 1em;_x000D_
  _x000D_
  background-image: url("data:image/svg+xml;charset=utf-8, \_x000D_
    <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'> \_x000D_
      <polygon points='0,0 60,0 30,40' style='fill:black;'/> \_x000D_
    </svg>");_x000D_
}
_x000D_
<select>_x000D_
  <option>Option 1</option>_x000D_
  <option>Option 2</option>_x000D_
</select>_x000D_
_x000D_
<select style="font-size: 2rem;">_x000D_
  <option>Option 1</option>_x000D_
  <option>Option 2</option>_x000D_
</select>
_x000D_
_x000D_
_x000D_

The rest of the styling (borders, padding, colors, etc.) is fairly straightforward.

This works in all the browsers I just tried (Firefox 50, Chrome 55, Edge 38, and Safari 10). One note about Firefox is that if you want to use the # character in the data URI (e.g. fill: #000) you need to escape it (fill: %23000).

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to combobox

How to set combobox default value? PHP code to get selected text of a combo box How to add items to a combobox in a form in excel VBA? How add items(Text & Value) to ComboBox & read them in SelectedIndexChanged (SelectedValue = null) Get Selected value of a Combobox jQuery "on create" event for dynamically-created elements How to get the selected item of a combo box to a string variable in c# HTML combo box with option to type an entry twitter bootstrap autocomplete dropdown / combobox with Knockoutjs C# winforms combobox dynamic autocomplete

Examples related to cross-browser

Show datalist labels but submit the actual value Stupid error: Failed to load resource: net::ERR_CACHE_MISS Click to call html How to Detect Browser Back Button event - Cross Browser How can I make window.showmodaldialog work in chrome 37? Cross-browser custom styling for file upload button Flexbox and Internet Explorer 11 (display:flex in <html>?) browser sessionStorage. share between tabs? How to know whether refresh button or browser back button is clicked in Firefox CSS Custom Dropdown Select that works across all browsers IE7+ FF Webkit

Examples related to skinning

How do I style a <select> dropdown with only CSS?