CodesCompiler
🔍
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact 🚀 Get Started Free

HTML - HEX Colors

HTML - HEX Colors

Hexadecimal (Hex) colors

Hexadecimal (Hex) colors are specified by combining the hexadecimal values ( #RRGGBB ) of red ( RR ), green ( GG ), and blue ( BB ) colors, with each value ranging from 00 to FF , where 00 represents the lowest intensity and FF represents the highest intensity of each color.

HEX Color Values

Each HEX color value starts with a hash sign ( # ) and includes six digits ( #RRGGBB ). The first two digits ( RR ) specify the red component, the next two ( GG ) specify the green component, and the final two ( BB ) specify the blue component. This method allows precise color customization for web design.

Example

Here is the example to create Red, Green, and Blue colors using the hex values:

Preview

Using Hex Colors in HTML

To use hex colors in HTML, we can either assign them directly to an element using the style attribute , or define them in a style tag or sheet using the color property .

Example 1: Using style Attribute

Here is an example to assign a hex color to an HTML element using the style attribute:

Preview

Example 2: Using a style Tag

Here is an example to assign a hex color to an HTML element using the style tag:

Preview

Hex Color Codes for Common Colors

The following table has a few colors represented using hexadecimal color codes:

ColorColor HEX
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF

Examples of Hex Colors

Here are some examples that show how to use hexadecimal colors in HTML:

Setting Background Color for Body

In the following example, we are defining the background color of the HTML page using the hex color code:

Preview

Setting Color on Table Cells

In the following example, we are defining the background color of the H2 and table:

Preview

Selecting the right colors for designing a webpage is difficult. Even if you have a color in your mind, you need to make a computer understand the hexadecimal value of the color. To make your job easier, we suggest using our HTML color picker tool .