HTML <select> style Attribute

The style attribute on a <select> tag assigns a unique style to the dropdown control (select element). A style contains one or more CSS property/value pairs that define the appearance of the dropdown control.

Example

#

A style attribute on a <select> element.

<select style="padding: 10px; background:#edf2ff; border:none;">
  <option value="">-- Select city -- </option>
  <option value="paris">Paris</option>
  <option value="london">London</option>
  <option value="athens">Athens</option>
  <option value="madrid">Madrid</option>
</select>

Using style

The style attribute specifies the style, i.e. look and feel, of the <section> element.

A style contains any number of CSS property/value pairs, separated by semicolons (;).

The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.

This inline styling affects the current <section> element only.


Syntax

<select style="CSS-styles">

Values

#

Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on a <select> element.
Clicking the button toggles the background color.



<select id="myselect" 
        style="padding: 10px; background-color:paleturquoise; border:none;">
  <option value="">-- Select city -- </option>
  <option value="paris">Paris</option>
  <option value="london">London</option>
  <option value="athens">Athens</option>
  <option value="madrid">Madrid</option>
</select>

<br /><br />
<button onclick="toggle();">Toggle style</button>

<script>
  let toggle = () => {
     let element = document.getElementById("myselect");

     if (element.style.backgroundColor === "cornsilk") {
        element.style.backgroundColor = "paleturquoise";
     } else {
        element.style.backgroundColor = "cornsilk";
     }
  }
</script>

Code explanation

The style attribute assigns a background color to the <select> element.

Clicking the button calls JavaScript which toggles background to another color.

Note: All the <option> element inside will inherit the style of the <select> element.


Browser support

Here is when style support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <select>
Guides