CSS color

CSS color refers to the specification and application of color in web design using Cascading Style Sheets (CSS). CSS allows you to set the color of text, backgrounds, borders, and other elements on a webpage. There are several ways to define colors in CSS:

Named Colors

CSS includes a set of named colors that can be used directly. For example:


color: red;

Hexadecimal Colors

Colors can be defined using hexadecimal (hex) values, which start with a # followed by six hexadecimal digits. The first two digits represent the red component, the next two represent green, and the last two represent blue. For example:


color: #ff0000; /* red */

RGB and RGBA Colors

Colors can be specified using the rgb() or rgba() functions. The rgb() function takes three parameters (red, green, and blue), each ranging from 0 to 255. The rgba() function includes an additional parameter for alpha (opacity) which ranges from 0 (completely transparent) to 1 (completely opaque). For example:


color: rgb(255, 0, 0); /* red */

HSL and HSLA Colors

Colors can also be defined using the hsl() or hsla() functions. The hsl() function takes three parameters: hue (0-360), saturation (0%-100%), and lightness (0%-100%). The hsla() function adds an alpha parameter for opacity. For example:


color: hsl(0, 100%, 50%); /* red */

CSS color – Interview Questions

Q 1: How can colors be applied in CSS?
Ans: Using color names, HEX, RGB, RGBA, HSL.
Q 2: What is HEX color format?
Ans: A six-digit color code starting with #.
Q 3: What is RGB?
Ans: Red, Green, Blue color model.
Q 4: What is RGBA used for?
Ans: To add transparency using alpha value.
Q 5: Which property is used to set text color?
Ans: color

CSS color – Objective Questions (MCQs)

Q1. Which property is used to change text color in CSS?






Q2. Which of the following is a valid HEX color code?






Q3. Which color model uses Red, Green, Blue?






Q4. How do you apply a transparent color in CSS?






Q5. Which value represents pure white?






Related CSS color Topics