RGB Color Values - HTML CSS CSS

HTML CSS examples for CSS:Color

Introduction

You can use RGB (red-green-blue) color model to define color values in CSS.

Hexadecimal Notation

The RGB value in hexadecimal notation is specified with a '#' character followed by either three or six hexadecimal characters (0-9, a-f).

When six-digit notation (#rrggbb) is used,

  • rr represents the red value
  • gg represents the green value
  • bb represents the blue value.

The three-digit hexadecimal notation (#rgb) can be converted into six-digit form (#rrggbb) by replicating digits.

For example, #03f can be expanded to #0033ff, but both values represent the same color.

Example

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
 <head>
  <title>CSS Hexadecimal Notation</title>
  <style type="text/css">
    h1 {<!--from w w w . j av  a 2  s .com-->
        color: #f80;
    }
    p {
        background-color: #ff8800;
    }
</style>
 </head>
 <body>
  <h1>This is a heading</h1>
  <p>This is a paragraph.</p>
 </body>
</html>

Related Tutorials