Web browsers are capable of displaying colors on the screen that are written in our HTML document.
Better color combinations of texts and backgrounds can enhance the overall look and feel of the web page.
In HTML, the simplest way to specify a color in our code is to write it with its name.
There are other options, too, for specifying colors. We can define them with RGB, HEX, HSL, RGBA, or HSLA values.
Let's do an in-depth discussion on HTML colors with examples.
As we said earlier in the chapter, colors in HTML can be specified with predefined names.
Modern browsers can identify a total of 140 colors by their names.
The list of all 140 HTML colors can be found here.
Below are some famous colors with their names.
Let's view these HTML colors in examples.
The default color of the text can be changed by specifying the color name in the style attribute.
HTML elements' border color can be changed by using the style attribute.
The name of the color is specified in the value of the CSS
property.See the example below. Always check the result of the code by clicking on the 'Result on Editor' button.
The background color of an HTML element can be defined in the style attribute with the CSS property as '
' and value as 'color name'.RGB values, HEX values, HSL values, RGBA values and HSLA values can also define a color in an HTML document.
For example, DeepSkyBlue color has RGB value rgb(0, 191, 255), hex value #00BFFF and HSL value hsl(195, 100%, 50%).
Adding an alpha channel to RGB and HSL, which is for transparency can provide RGBA and HSLA value.
So to add 50% transparency in DeepSkyBlue color, we will have RGBA value rgba(0, 191, 255,0.5) and hsla(195, 100%, 50%,0.5).
In the upcoming chapters, we will learn these color concepts in more detail.
1. HTML Tutorial |
2. Introduction to HTML |
3. Basic HTML Page |
4. HTML Editors |
5. Web Browser |
6. HTML History |
7. Basic HTML Tags |
8. HTML Elements |
9. HTML Attributes |
10. HTML Headings |
11. HTML Paragraphs |
12. HTML Text Formatting |
13. HTML Styles |
14. HTML Comment |
15. HTML Quotation |
16. HTML Colors |
17. HTML RGB Colors |
18. HTML HEX Colors |
19. HTML HSL Color |
20. HTML CSS |
21. HTML Links |
22. HTML Link Colors |
23. Link within Page |
24. HTML Images |
25. HTML Background Image |
26. HTML Image Map |
27. HTML Picture Element |
28. HTML Favicon |
29. HTML Table |
30. HTML Table Border |
31. HTML Table Size |