In this article, you will learn how to create colors in RGB notation with values in hexadecimal, the most common way to express a color in the HTML language. We explain the correct use of colors in HTML.
In the composition of websites, colors play a very important role. Using a defined color palette usually helps the consistency of a design and convey certain sensations to the user. As part of our learning HTML we have to stop to understand how colors are expressed in the language.
HTML uses a specific notation to specify a color, made up of three “RGB” values: Red, Green, Blue. Red, Green and Blue. In other words, to get any color we will mix quantities of each of those colors. RGB is the model used to create colors for monitors and televisions, so it’s a great way to express color on a digital medium like the web.
RBG values in HTML are given in hexadecimal numbering, base 16. (The digits can grow up to 16. Since there aren’t that many numeric digits, the letters A through F are used.)
To get a color, we’ll mix values by assigning two digits to each RBG value. Like this: “#RRGGBB”
As you’ve noticed, we also put a hash “#” at the beginning, to indicate that that string is a color value in hexadecimal.
Later in the article we will see examples in a large palette, with its values in RGB. However examples could be #000000 for black, #FFFFFF for white, #660000 would be a dark red or #FF0000 would be a bright red.
Note: You will have been able to observe on some occasion that colors can also be expressed with some words, in fact in the article about it we already discussed it. However, it is much more common to write in RGB, because it is more versatile and we can more easily achieve any desired hue.
Color attributes in HTML tags
In HTML there are numerous tags that support color attributes. So that you have a first reference, this is how the font would be changed to write in red:
Red
As you can see, we give the color attribute an RGB value in hexadecimal format. The # character is placed at the beginning of the string.
Note: Again we have to warn about the need to express everything that is styled by . In HTML we must focus on what it is to write the content and in CSS on applying the style. Of course, color is more styling than content, so it should go in the CSS. This is why the entire FONT tag has been deprecated, because it only served us to apply styling. For your peace of mind, in CSS colors can be expressed in the same way as in HTML, so you won’t have to learn anything new.
To give another example, the TABLE tag allows the background color of the table to be expressed. We’ll cover it later, but you get it with the bgcolor attribute.