💡 Tip: Login now to track your course progress and unlock your downloadable certificates instantly!

CSS HEX Colors

HEX (Hexadecimal) colors are a popular way to define colors in CSS using a 6-digit combination of numbers and letters.

A HEX color starts with a hash (#) followed by values representing Red, Green, and Blue (RGB).

Each pair controls the intensity of a color:

  • #RRGGBB

For example:

  • #FF0000 → Red
  • #00FF00 → Green
  • #0000FF → Blue
Syntax
selector {
    color: #RRGGBB;
}
Example
p {
color: #ff0000;
}

👉 This sets the text color to red using HEX value.

Attributes

PropertyDescriptionExample
colorSets text colorcolor: #0000ff;
background-colorSets background colorbackground-color: #f0f0f0;
border-colorSets border colorborder-color: #ff0000;
outline-colorSets outline coloroutline-color: #00ff00;

Example

CSS Hex Colors Complete Example
<!DOCTYPE html>
<html>
<head>
    <title>CSS HEX Colors</title>
    <style>
        body {
            background-color: #f2f2f2;
        }

        h1 {
            color: #0000ff;
        }

        p {
            color: #008000;
        }

        div {
            border: 2px solid #ff0000;
            padding: 10px;
        }
    </style>
</head>
<body>

    <h1>HEX Color Example</h1>

    <p>This paragraph uses HEX color.</p>

    <div>This box has a red border using HEX.</div>

</body>
</html>

Output

Browser Output

The page will have a light gray background
The heading will appear in blue (#0000ff)
The paragraph will appear in green (#008000)
The box will have a red border (#ff0000)

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

Notes

  • HEX values range from 00 to FF (0–255 in decimal)
  • You can use shorthand HEX values like #fff (for #ffffff)
  • HEX is widely used in web design for precise color control
  • Case-insensitive (#FF0000 = #ff0000)
  • Easy to copy and reuse across projects

Conclusion

HEX colors provide a precise and widely accepted way to define colors in CSS. They are essential for consistent and professional web design, allowing developers to control colors accurately across different elements.

Sign In Form

Use your email and password to sign in

Provide your email and we will send you a password reset link.

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend