HTML colors are CSS color values you apply to text, backgrounds, and borders. Specify them with a color name, a HEX code, RGB/RGBA, or HSL/HSLA.
Where do colors go in HTML?
Colors are not a separate HTML language—they are CSS values. Set them with the style attribute, a <style> block, or an external stylesheet. Prefer CSS over obsolete presentational attributes such as bgcolor.
What can you color?
Common properties: color (text), background-color, and border-color (or the shorthand border).
When should you use each format?
Names are quick for demos. HEX is common in design tools. RGB/RGBA suit channel math and transparency. HSL/HSLA shine when you tweak hue or lightness while keeping a related palette.
Prefer CSS.
Keep color rules in a stylesheet (or a <style> block) so HTML stays about structure. Use inline style for tiny demos only.
140 named colors.
Names like Tomato, DodgerBlue, and MediumSeaGreen work in every modern browser.
Contrast matters.
Light gray on white may look fine on your monitor but fail accessibility checks. Aim for readable contrast.
Syntax
HTML Color Syntax
Apply a CSS color value through the style attribute (or better, a stylesheet):
With alpha (transparency): rgba(255, 99, 71, 0.5) and hsla(9, 100%, 64%, 0.5). HEX is written as #RRGGBB (or short #RGB). RGB channels are integers from 0 to 255. HSL uses hue 0–360, saturation and lightness as percentages.
Reference
Core HTML Concepts
Formats and where to put them:
Format
Example
Notes
Color name
Tomato
140 standard names
HEX
#ff6347
Common in design tools; case-insensitive
RGB
rgb(255, 99, 71)
Red, green, blue 0–255
RGBA
rgba(255, 99, 71, 0.5)
Adds alpha 0–1 (or %)
HSL
hsl(9, 100%, 64%)
Hue, saturation, lightness
HSLA
hsla(9, 100%, 64%, 0.5)
HSL plus alpha
Property vs value
Property
What it colors
color
Text (foreground)
background-color
Element background
border-color
Border (needs a border width/style)
Approach
How to Use Colors in HTML
Practical habits for readable, maintainable color.
Pick a primary palette (1–3 brand colors) before styling every element.
Put shared colors in a stylesheet (or CSS variables) instead of repeating inline styles.
Use names for quick prototypes; switch to HEX/RGB/HSL for production precision.
Check text/background contrast for accessibility.
Use RGBA/HSLA when you need translucent overlays—not for hiding important text.
Avoid obsolete HTML attributes like bgcolor and <font color>.
Readable demos — names are easy to remember while learning.
Same property works with HEX, RGB, or HSL later.
Example 2 — HEX Colors
HTML
<p style="background-color:#ff6347;color:#ffffff;padding:8px;">
Background #ff6347 with white text
</p>
<p style="color:#1e90ff;">Dodger-blue text with HEX</p>
Next step move rules to an external file — see Add CSS to HTML.
Edge Cases & Pitfalls
Color bugs are usually obsolete attributes, low contrast, or invalid values.
obsolete
bgcolor and font color
Do not use presentational HTML attributes. Use CSS background-color and color.
contrast
Low-contrast text
Pale text on pale backgrounds fails accessibility. Test foreground against background.
typo
Invalid color strings
A missing #, wrong RGB range, or misspelled name makes the declaration invalid—styles may fall back.
inline
Too many inline styles
Hard to maintain. Prefer classes in a stylesheet for real pages.
alpha
Transparent text
Low alpha on color can make copy unreadable. Prefer opaque text on translucent backgrounds.
print
Backgrounds in print
Some browsers omit backgrounds when printing unless the user enables them.
Compatibility
Browser Support
CSS color names, HEX, RGB/RGBA, and HSL/HSLA are supported in all modern browsers.
✓ Baseline · Widely available
HTML / CSS colors
Every current browser understands named colors and the common CSS color functions used from HTML.
100%color formats
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
CSS colors in HTMLUniversal
Bottom line: Use modern CSS color values freely—skip obsolete HTML color attributes.
Remember
Key Takeaways
Colors are CSS values applied with style sheets or the style attribute.
Names, HEX, RGB, HSL (plus alpha variants) all work.
Prefer stylesheets for real projects over inline-only styling.
Contrast beats fancy color—keep text readable.
One line: Set color / background-color with names, HEX, RGB, or HSL—and keep the rules in CSS when you can.
Frequently Asked Questions
Use a CSS color value on a style property such as color or background-color. Prefer a stylesheet or a style element. You can also use the style attribute for quick demos.
Browsers accept named colors (like Tomato), HEX (#ff6347), RGB/RGBA, and HSL/HSLA. All of these are CSS color values used from HTML.
Modern browsers support 140 standard color names, including Tomato, DodgerBlue, MediumSeaGreen, and Gray.
No. Attributes like bgcolor and the font color attribute are obsolete. Use CSS properties instead: color, background-color, and border-color.
Both describe red, green, and blue. rgb(255, 99, 71) uses decimal 0–255 channels. #ff6347 uses the same channels in hexadecimal. They can represent the same color.
HSL is handy when you want to adjust hue, saturation, or lightness independently—for example lightening a brand color while keeping the same hue.