Skip to main content

Change the Select Box Option Background Color

Published: Asked By 2 Answers Answered

I created a Dropdown with 3 options. I want to set separate colors for separate options. How to do this?

    <select name="cars" id="cars">
      <option value="One">One</option>
      <option value="Two">Two</option>
      <option value="Three">Three</option>
    </select>
Share:

2 Answers

L
LAZIO LEO Community Contributor Answered on

To set separate colors for each option in a dropdown menu, you can use CSS to style the option elements individually. However, please note that the styling of option elements is limited and may not be supported consistently across all browsers.

.option-one {
   color: blue;
 }

.option-two {
  color: green;
}

.option-three {
  color: red;
}
 

A
Ameen Community Contributor Answered on

Method 1:

We can add a class for the elements and assign desired colors to the desired elements

Method 2:

Use a custom drop-down to get a full styling control. For that, use the following Libraries like

  • Bootstrap Select
    Select2
    Choices.js

 

Your Answer

Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certifications

Earn certifications to enhance your resume.