
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
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:
<!DOCTYPE html> <html> <head> <title>Example Hex Color Values</title> </head> <body> <!-- Red color --> <div style="background-color: #FF0000; width: 100px; height: 100px;"> RED Color </div> <!-- Green color --> <div style="background-color: #00FF00; width: 100px; height: 100px;"> GREEN Color </div> <!-- Blue color --> <div style="background-color: #0000FF; width: 100px; height: 100px;"> BLUE Color </div> </body> </html>
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:
<body> <p style="color: #FF0000;">This text is red.</p> </body>
Example 2: Using a style Tag
Here is an example to assign a hex color to an HTML element using the style
tag:
<head> <style> p { color: #FF0000; } </style> </head> <body> <p>This text is red.</p> </body>
Hex Color Codes for Common Colors
The following table has a few colors represented using hexadecimal color codes:
Color | Color 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:
<!DOCTYPE html> <html> <head> <title> HTML Colors by HEX code </title> </head> <body style="background-color: #00FF00;"> <p> Use different color code for body and table and see the result. </p> <p style="color: #FFFFFF;"> This text will appear white on black background. </p> </body> </html>
Setting Color on Table Cells
In the following example, we are defining the background color of the H2
and table:
<!DOCTYPE html> <html> <head> <title> HTML HEX Color code </title> </head> <body style="width:300px; height:100px;"> <h2 style="background-color: #FF6666;"> Setting the Background using HEX Code </h2> <table style="background-color: #FF3335;"> <tr> <td style="color: #FFFFFF;"> The text color of the paragraph is styled using HEX code. </td> </tr> </table> </body> </html>
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.