Setting text color in CSS. Ways to represent colors

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:

<span>Lesson 6. Changing the text color</span>

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:

<span>Lesson 6. Changing the text color</span>

Green text

Red text

Purple text



Let's save the file and look at the result:

As you can see, we gave the text 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:

<span>We give the text several parameters</span>

Set the text font, size and color

Set the text font, size and color



In HTML, color can be specified in three ways:

Setting a color in HTML by its name

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):

ColorNameColorName ColorName ColorName
Black Gray Silver White
Yellow Lime Aqua Fuchsia
Red Green Blue Purple
Maroon Olive Navy Teal

Example of using different color names:

Example: specifying a color by its name

  • Try it yourself "

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

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:

Example: Specifying Color Using RGB

  • Try it yourself "

rgb(127, 255, 127)

rgb(50%, 100%, 50%)

rgb(127, 255, 127)

rgb(50%, 100%, 50%)

Set color by hexadecimal value

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, in contrast decimal system, is based, as its name suggests, on the number 16. The hexadecimal system uses the following characters: 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 largest number 255 in decimal corresponds to the highest FF value in hexadecimal. Unlike the decimal system, before hexadecimal number put 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 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.

Example: HEX Color

  • Try it yourself "

red: #FF0000

green: #00FF00

blue: #0000FF

red: #FF0000

green: #00FF00

blue: #0000FF

red+green=yellow: #FFFF00

red+blue=purple: #FF00FF

green+blue=cyan: #00FFFF

List of common colors (name, HEX and RGB):

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 codes (background) by saturation and hue.

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. The font tag is widely used 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 (

, , , , , ,