The RGB code for red color is written as. Setting text color in CSS
In the first part of the book, we already demonstrated in some examples how to set the text color in CSS. There is nothing complicated here: you will need the color property and the value of the color you want to color the text with.
P ( color: #211C18; )
In our example, the value #211C18 represents the hexadecimal color code. If you are already familiar with the hexadecimal number system, you can skip reading the next paragraph. We will also talk further about other ways to represent colors on the web - using color models (RGB, HSL) and keywords. This information will be useful for beginners and is recommended reading.
Hexadecimal colors (hex)
Hexadecimal number system ( hexadecimal, hex) is based on the number 16. To write a hexadecimal value, 16 characters are used: Arabic numerals from 0 to 9 and the first letters of the Latin alphabet (A, B, C, D, E, F). Color in hexadecimal format is written as three two-digit numbers from 00 to FF (they must be preceded by a hash symbol #), which corresponds to three components: Red, Green, Blue (RGB color model). In other words, a color entry can be represented as #RRGGBB, where the first pair of characters determines the red level, the second - the green level, and the third - the blue level. The resulting color is a combination of these three colors.
Shorthand notation for hex colors
Some hexadecimal color values can be written in abbreviations. To do this, turn the entry like #RRGGBB into #RGB. This can be done when the hex number contains three pairs of identical characters.
The abbreviated form of notation is quite common, and for your reference we will provide several examples of abbreviations. By the way, hex color values are not case sensitive - you can use both uppercase and lowercase letters, it all depends on your desire and taste.
Examples of abbreviated notation for hex colors:
HEX code | Shorthand notation |
---|---|
#FFDD66 | #FD6 |
#8833FF | #83F |
#333333 | #333 |
#cccccc | #ccc |
RGB color model
The second way to specify colors in CSS is to use decimal RGB values (Red, Blue, Green). To do this, you need to write the keyword rgb after the color property, and then in parentheses and separated by commas - three numbers in the range from 0 to 255, each of which means the intensity of red, green and blue colors (r, g, b). The higher the number, the more intense the color. For example, to get a bright green color, you need to write:
P ( color: rgb(0, 255, 0); )
But the yellowish-mustard tint has the following meaning:
Color: rgb(94, 81, 3); /* below is the same color, written in hexadecimal: */ color: #5E5103;
The value for black is written as (0, 0, 0) and for white as (255, 255, 255) . It is also possible to indicate these values as percentages. So, the number 255 corresponds to 100%, therefore, White color can be set as follows:
Color: rgb(100%, 100%, 100%);
Where to look for color meanings
Perhaps you have a question: where do you get all these color meanings? There are many graphic editors and online services with which you can select colors and build color schemes. One of the most popular programs in which you can select a suitable color and get its RGB, hex value and more - Adobe Photoshop. As an alternative, there are special sites where you can easily choose not only a color, but also an entire color scheme. A great example is the Adobe Color CC service.
RGBA color model
You can set a color in RGBA format in much the same way as in RGB. The difference between RGBA and RGB is the presence of an alpha channel, which is responsible for the transparency of the color. Transparency is set using a number in the range from 0 to 1, where 0 means full transparency, and 1, on the contrary, means completely opaque. Intermediate values like 0.5 allow you to set a translucent appearance (shorthand notation is allowed, without a zero, but with a dot – .5). For example, to make the text colored and slightly transparent, you need to write the rgba keyword and the color value after the color property:
P ( color: rgba(94, 81, 3, .9); )
The disadvantage of RGBA is that it does not support Internet browser Explorer versions 8 and earlier. Especially for IE8, you can apply the following solution:
P ( color: rgb(94, 81, 3); color: rgba(94, 81, 3, .9); )
The first property in the example is intended for the IE8 browser, which will display the text in the desired color, but without transparency. And those browsers that understand RGBA will apply the second property to the element, with transparency.
HSL (HSLA) color models
You can also set color in CSS using the coordinates of the HSL color model (Hue, Saturation, Lightness). It is written like this:
P ( color: hsl(165, 100%, 50%); )
The first number in brackets means hue and is given in degrees (number range from 0 to 359). It will be easy to understand why degrees are used if you remember what the color wheel looks like:
The second and third numbers in brackets mean saturation and lightness, respectively. Their values are set in percentages from 0 to 100. The lower the saturation value, the more muted the color becomes. A saturation value of zero will result in a gray color, no matter what the hue value is. The lightness value allows you to specify the brightness of the color. Low values result in dark shades of color, high values result in light shades. A value of 100% for lightness means white, 0% means black.
The HSLA color model works almost the same as HSL, but, similar to RGBA, it has an alpha channel with which you can set the transparency of the color, specifying the desired value in the range from 0 to 1:
P ( color: hsla(165, 100%, 50%, .6); )
HSL and HSLA are supported by all browsers except Internet Explorer versions 8 and earlier.
Standard HTML Colors
Another way to represent colors on the web is through keywords, which can be used to specify a color for an element. Example:
P(color:black;)
There are 16 standard colors that can be written in the value of the color property:
Color Keyword | HEX code | RGB |
---|---|---|
red | #FF0000 | 255, 0, 0 |
maroon | #800000 | 128, 0, 0 |
yellow | #FFFF00 | 255, 255, 0 |
olive | #808000 | 128, 128, 0 |
lime | #00FF00 | 0, 255, 0 |
green | #008000 | 0, 128, 0 |
aqua | #00FFFF | 0, 255, 255 |
teal | #008080 | 0, 128, 128 |
blue | #0000FF | 0, 0, 255 |
navy | #000080 | 0, 0, 128 |
fuchsia | #FF00FF | 255, 0, 255 |
purple | #800080 | 128, 0, 128 |
white | #FFFFFF | 255, 255, 255 |
silver | #C0C0C0 | 192, 192, 192 |
gray | #808080 | 128, 128, 128 |
black | #000000 | 0, 0, 0 |
These colors are supported by all browsers. In addition to these, there are about 130 additional keywords for different shades of colors. A complete table of these colors can be seen in the W3C reference book.
The use of such keywords is acceptable, but there is a risk that some word will not be accepted by the browser. Therefore, it is recommended to write down the hexadecimal color code instead of keywords.
Results
In CSS, the color of text is specified using the color property, and its value can be written in several ways - in hexadecimal (hex) format, in RGB or HSL format, or by specifying a keyword. To avoid incorrect display of a color specified using a keyword, it is better to specify its hex value.
It is also possible to set the element's transparency using an alpha channel (RGBA and HSLA formats). It should be borne in mind that the IE8 browser and its early versions do not support RGBA, HSL and HSLA formats.
In this article we will get acquainted with the capabilities of HTML and CSS to change the color of text on website pages. Several options will be considered. For each individual case, its own specific method is convenient.
To begin with, we note that all colors can be specified in three formats:
- Color name (red, blue, green, etc.)
- Hexadecimal format (#104A00, #0F0, etc.)
- rgba format (rgba(0,0,0,0.5), etc.)
Our website presents the full palette and names of html colors for the site, where you can choose the appropriate color.
Method 1. Via html tag
The most in a simple way change text color in html is using tag . It allows you to change the color, size and style of the text. To do this, it has three attributes. Syntax:
Let's give an example
Regular font Blue font Larger red font
The page converts to the following
Regular font. Blue font. And this is a larger red font
The new version of the HTML5 standard does not support it. But all modern browsers understand and will apparently continue to understand for a long time. font tag widely distributed on websites. Which, however, is easy to explain by its accessibility and simplicity.
Method 2. Through the style attribute
There is a second similar method for changing the font color. There is a style attribute for this, which can be applied to any html tags (
, , , , , , Let's give an example Blue text color Blue text color Green text color If the text does not change its color, then you can try using the!important declaration Blue text color It is also worth clearing your browser cache after each change to the stylesheet.css files. Most The best way Changing the color of text on a website means taking advantage of the capabilities of CSS tables. They can be connected to the site, and then you can change the values in one place and the changes made will be displayed on the entire site at once. In HTML, color can be specified in three ways: Some colors can be specified by their name, using the color name on the English language. The most common keywords: black, white, red, green, blue, etc.:
Text color – red The most popular colors of the Consortium standard World Wide Web(English World Wide Web Consortium, W3C): Example of using different color names: When displaying different colors on a monitor, the RGB palette is used as a basis. Any color is obtained by mixing three basic ones: R - red, G - green, B - blue. The brightness of each color is given by one byte and can therefore take values from 0 to 255. For example, RGB(255,0,0) is displayed as red since red is set to its highest value (255) and the rest are set to 0 You can also set the color as a percentage. Each parameter indicates the brightness level of the corresponding color. For example: the values rgb(127, 255, 127) and rgb(50%, 100%, 50%) will set the same medium green color:
Values R
G
B can also be specified using hexadecimal (HEX) color values in the form: #RRGGBB where RR (red), GG (green) and BB (blue) are hexadecimal values from 00 to FF (same as decimal 0-255) . The hexadecimal system, unlike the decimal system, is based, as its name suggests, on the number 16. The hexadecimal system uses the following signs: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Here the numbers from 10 to 15 are replaced by Latin letters. Numbers greater than 15 in the hexadecimal system are represented by combining two characters into one value. For example, the highest number 255 in decimal corresponds to the highest FF value in hexadecimal. Unlike the decimal system, a hexadecimal number is preceded by a hash symbol. #
, for example, #FF0000 is shown as red because red is set to its highest value (FF) and the rest of the colors are set to their minimum value (00). Signs after the hash symbol #
You can type in both uppercase and lowercase. The hexadecimal system allows you to use the abbreviated form #rgb, where each character is equivalent to double. Thus, the entry #f7O should be regarded as #ff7700. List of common colors (name, HEX and RGB): Color codes (background) by saturation and hue. In this tutorial we will look at the last tag attribute , which sets the color of the text. By default, the text is black, which is displayed on a white background. In order to change text color in html, you need to apply the color attribute of the tag : To set a color, just specify its name, for example: red, green, blue. Let's look at a small example:
Green text Red text Purple text Let's see the result in the browser: The text in the first paragraph turned green, the second paragraph turned red, and the third paragraph turned purple. In total there are 16 names of primary colors and 130 additional ones. Full list colors you can see in the html color table. This way of indicating color is very simple, but very limited. Therefore, in order to change the color in HTML code, they often use a hexadecimal number preceded by a hash sign (#), for example: Using this designation you can get more than 16 million colors and their shades! You can get the color code using the color code, which is available on the site, or using the color palette in Photoshop. Let's look at an example and write the following code:
Green text Red text Purple text Let's save the file and look at the result: As you can see, we set the text to the same colors as in the first example, only here we used the hexadecimal number system, or in other words, we set the color in HEX format. Now you have learned how to change the text color in html and at the end of the lesson I suggest repeating all the tag attributes , and set several parameters to the text at once, namely: font, size and color. Write down an example:
Set the text font, size and color Set the text font, size and color The CSS color module details values that allow authors to define the colors and opacity of html elements, as well as the values of the color property. The property sets the font color using various systems color rendition. The property describes the color of the element's text content. Additionally, it is used to provide a potential indirect value (currentColor) for any other properties that accept color values. The property is inherited. The list of main keywords includes the following meanings: Color names are not case sensitive. Syntax Color: teal; The hexadecimal format of an RGB value is a # sign followed immediately by three or six hexadecimal characters. The three-digit RGB notation #rgb is converted to the six-digit form #rrggbb by copying the digits rather than adding zeros. For example, #fb0 expands to #ffbb00 . This ensures that white #ffffff can be specified in the short #fff entry, and removes any dependencies on display color depth. The format of an RGB value in functional notation is rgb(, followed by a comma-separated list of three numeric values (either three integer values or three percentage values), followed by the symbol) . The integer value 255 corresponds to 100% and F or FF in hexadecimal notation: Rgb(255,255,255) = rgb(100%, 100%, 100%) = #FFF Space characters are allowed around numeric values.,
,
Method 3. Through CSS styles
Setting a color in HTML by its name
Color Name Color Name Color Name Color Name
Black
Gray
Silver
White
Yellow
Lime
Aqua
Fuchsia
Red
Green
Blue
Purple
Maroon
Olive
Navy
Teal
Example: specifying a color by its name
Header on red background
Header on orange background
Heading on lime background
White text on blue background
Header on red background
Header on orange background
Heading on lime background
White text on blue background
Specifying Color Using RGB
Example: Specifying Color Using RGB
rgb(127, 255, 127)
rgb(50%, 100%, 50%)
rgb(127, 255, 127)
rgb(50%, 100%, 50%)
Set color by hexadecimal value
Example: HEX Color
red: #FF0000
green: #00FF00
blue: #0000FF
red: #FF0000
green: #00FF00
blue: #0000FF
red+green=yellow: #FFFF00
red+blue=purple: #FF00FF
green+blue=cyan: #00FFFF
English name
Russian name
Sample
HEX
RGB
Amaranth
Amaranth
#E52B50
229
43
80
Amber
Amber
#FFBF00
255
191
0
Aqua
Blue-green
#00FFFF
0
255
255
Azure
Azure
#007FFF
0
127
255
Black
Black
#000000
0
0
0
Blue
Blue
#0000FF
0
0
255
Bondi Blue
Bondi beach water
#0095B6
0
149
182
Brass
Brass
#B5A642
181
166
66
Brown
Brown
#964B00
150
75
0
Cerulean
Azure
#007BA7
0
123
167
Dark spring green
Dark spring green
#177245
23
114
69
Emerald
Emerald
#50C878
80
200
120
Eggplant
Eggplant
#990066
153
0
102
Fuchsia
Fuchsia
#FF00FF
255
0
255
Gold
Gold
#FFD700
250
215
0
Gray
Grey
#808080
128
128
128
Green
Green
#00FF00
0
255
0
Indigo
Indigo
#4B0082
75
0
130
Jade
Jade
#00A86B
0
168
107
Lime
Lime
#CCFF00
204
255
0
Malachite
Malachite
#0BDA51
11
218
81
Navy
Dark blue
#000080
0
0
128
Ochre
Ocher
#CC7722
204
119
34
Olive
Olive
#808000
128
128
0
Orange
Orange
#FFA500
255
165
0
Peach
Peach
#FFE5B4
255
229
180
Pumpkin
Pumpkin
#FF7518
255
117
24
Purple
Violet
#800080
128
0
128
Red
Red
#FF0000
255
0
0
Saffron
Saffron
#F4C430
244
196
48
Sea Green
Green sea
#2E8B57
46
139
87
Swamp green
Bolotny
#ACB78E
172
183
142
Teal
Blue-green
#008080
0
128
128
Ultramarine
Ultramarine
#120A8F
18
10
143
Violet
Violet
#8B00FF
139
0
255
Yellow
Yellow
#FFFF00
255
255
0
color property
1. Priority colors: color property
2. Color values
2.1. Main Keywords
Name
HEX
RGB
Color
black
#000000
0,0,0
silver
#C0C0C0
192,192,192
gray
#808080
128,128,128
white
#FFFFFF
255,255,255
maroon
#800000
128,0,0
red
#FF0000
255,0,0
purple
#800080
128,0,128
fuchsia
#FF00FF
255,0,255
green
#008000
0,128,0
lime
#00FF00
0,255,0
olive
#808000
128,128,0
yellow
#FFFF00
255,255,0
navy
#000080
0,0,128
blue
#0000FF
0,0,255
teal
#008080
0,128,128
aqua
#00FFFF
0,255,255
2.2. Numeric color values
2.2.1. RGB model colors