How to Change Background Color of an input Field using CSS?

To change the background color of an input field we can simply use the background-color property.

The background-color property accepts the color value in various CSS color formats such as a color name, HEX, RGB, HSL, etc. You can choose any of the color formats whichever best suits you.

In the following example, we have selected all text input fields using the attribute selector and changed their background color to cyan:

Example:

input[type="text"]{
    background-color: cyan;
    padding: 10px 15px;
    border-radius: 3px;
}

If you want to change the background color of a specific input field only without affecting the others, you can do it by simply adding a class or id attribute to it.

In the following example, we have changed the background color of a single text input only by specifying an id #coloredInput:

Example:

#coloredInput{
    background-color: cyan;
    padding: 10px 15px;
    border-radius: 3px;
}

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts