A style attribute on a <select> tag assigns a unique style to the dropdown.
Its value is CSS that defines the appearance of the dropdown control.
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>
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.
<select style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
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>
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.
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 |
Back to <select>