Skip to content

<color>

The <color> CSS type represents a color.

Warning

Not to be confused with the color CSS rule to set text color.

Syntax

A <color> should be in one of the formats explained in this section. A bullet point summary of the formats available follows:

  • a recognised named color (e.g., red);
  • a 3 or 6 hexadecimal digit number representing the RGB values of the color (e.g., #F35573);
  • a 4 or 8 hexadecimal digit number representing the RGBA values of the color (e.g., #F35573A0);
  • a color description in the RGB system, with or without opacity (e.g., rgb(23, 78, 200));
  • a color description in the HSL system, with or without opacity (e.g., hsl(290, 70%, 80%));

Textual's default themes also provide many CSS variables with colors that can be used out of the box.

Named colors

A named color is a <name> that Textual recognises. Below, you can find a (collapsed) list of all of the named colors that Textual recognises, along with their hexadecimal values, their RGB values, and a visual sample.

All named colors available. colors ┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓ Name                  hex    RGB               Color                ┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩ "aliceblue"#F0F8FFrgb(240248255) "ansi_black"#000000rgb(000) "ansi_blue"#000080rgb(00128) "ansi_bright_black"#808080rgb(128128128) "ansi_bright_blue"#0000FFrgb(00255) "ansi_bright_cyan"#00FFFFrgb(0255255) "ansi_bright_green"#00FF00rgb(02550) "ansi_bright_magenta"#FF00FFrgb(2550255) "ansi_bright_red"#FF0000rgb(25500) "ansi_bright_white"#FFFFFFrgb(255255255) "ansi_bright_yellow"#FFFF00rgb(2552550) "ansi_cyan"#008080rgb(0128128) "ansi_green"#008000rgb(01280) "ansi_magenta"#800080rgb(1280128) "ansi_red"#800000rgb(12800) "ansi_white"#C0C0C0rgb(192192192) "ansi_yellow"#808000rgb(1281280) "antiquewhite"#FAEBD7rgb(250235215) "aqua"#00FFFFrgb(0255255) "aquamarine"#7FFFD4rgb(127255212) "azure"#F0FFFFrgb(240255255) "beige"#F5F5DCrgb(245245220) "bisque"#FFE4C4rgb(255228196) "black"#000000rgb(000) "blanchedalmond"#FFEBCDrgb(255235205) "blue"#0000FFrgb(00255) "blueviolet"#8A2BE2rgb(13843226) "brown"#A52A2Argb(1654242) "burlywood"#DEB887rgb(222184135) "cadetblue"#5F9EA0rgb(95158160) "chartreuse"#7FFF00rgb(1272550) "chocolate"#D2691Ergb(21010530) "coral"#FF7F50rgb(25512780) "cornflowerblue"#6495EDrgb(100149237) "cornsilk"#FFF8DCrgb(255248220) "crimson"#DC143Crgb(2202060) "cyan"#00FFFFrgb(0255255) "darkblue"#00008Brgb(00139) "darkcyan"#008B8Brgb(0139139) "darkgoldenrod"#B8860Brgb(18413411) "darkgray"#A9A9A9rgb(169169169) "darkgreen"#006400rgb(01000) "darkgrey"#A9A9A9rgb(169169169) "darkkhaki"#BDB76Brgb(189183107) "darkmagenta"#8B008Brgb(1390139) "darkolivegreen"#556B2Frgb(8510747) "darkorange"#FF8C00rgb(2551400) "darkorchid"#9932CCrgb(15350204) "darkred"#8B0000rgb(13900) "darksalmon"#E9967Argb(233150122) "darkseagreen"#8FBC8Frgb(143188143) "darkslateblue"#483D8Brgb(7261139) "darkslategray"#2F4F4Frgb(477979) "darkslategrey"#2F4F4Frgb(477979) "darkturquoise"#00CED1rgb(0206209) "darkviolet"#9400D3rgb(1480211) "deeppink"#FF1493rgb(25520147) "deepskyblue"#00BFFFrgb(0191255) "dimgray"#696969rgb(105105105) "dimgrey"#696969rgb(105105105) "dodgerblue"#1E90FFrgb(30144255) "firebrick"#B22222rgb(1783434) "floralwhite"#FFFAF0rgb(255250240) "forestgreen"#228B22rgb(3413934) "fuchsia"#FF00FFrgb(2550255) "gainsboro"#DCDCDCrgb(220220220) "ghostwhite"#F8F8FFrgb(248248255) "gold"#FFD700rgb(2552150) "goldenrod"#DAA520rgb(21816532) "gray"#808080rgb(128128128) "green"#008000rgb(01280) "greenyellow"#ADFF2Frgb(17325547) "grey"#808080rgb(128128128) "honeydew"#F0FFF0rgb(240255240) "hotpink"#FF69B4rgb(255105180) "indianred"#CD5C5Crgb(2059292) "indigo"#4B0082rgb(750130) "ivory"#FFFFF0rgb(255255240) "khaki"#F0E68Crgb(240230140) "lavender"#E6E6FArgb(230230250) "lavenderblush"#FFF0F5rgb(255240245) "lawngreen"#7CFC00rgb(1242520) "lemonchiffon"#FFFACDrgb(255250205) "lightblue"#ADD8E6rgb(173216230) "lightcoral"#F08080rgb(240128128) "lightcyan"#E0FFFFrgb(224255255) "lightgoldenrodyellow"#FAFAD2rgb(250250210) "lightgray"#D3D3D3rgb(211211211) "lightgreen"#90EE90rgb(144238144) "lightgrey"#D3D3D3rgb(211211211) "lightpink"#FFB6C1rgb(255182193) "lightsalmon"#FFA07Argb(255160122) "lightseagreen"#20B2AArgb(32178170) "lightskyblue"#87CEFArgb(135206250) "lightslategray"#778899rgb(119136153) "lightslategrey"#778899rgb(119136153) "lightsteelblue"#B0C4DErgb(176196222) "lightyellow"#FFFFE0rgb(255255224) "lime"#00FF00rgb(02550) "limegreen"#32CD32rgb(5020550) "linen"#FAF0E6rgb(250240230) "magenta"#FF00FFrgb(2550255) "maroon"#800000rgb(12800) "mediumaquamarine"#66CDAArgb(102205170) "mediumblue"#0000CDrgb(00205) "mediumorchid"#BA55D3rgb(18685211) "mediumpurple"#9370DBrgb(147112219) "mediumseagreen"#3CB371rgb(60179113) "mediumslateblue"#7B68EErgb(123104238) "mediumspringgreen"#00FA9Argb(0250154) "mediumturquoise"#48D1CCrgb(72209204) "mediumvioletred"#C71585rgb(19921133) "midnightblue"#191970rgb(2525112) "mintcream"#F5FFFArgb(245255250) "mistyrose"#FFE4E1rgb(255228225) "moccasin"#FFE4B5rgb(255228181) "navajowhite"#FFDEADrgb(255222173) "navy"#000080rgb(00128) "oldlace"#FDF5E6rgb(253245230) "olive"#808000rgb(1281280) "olivedrab"#6B8E23rgb(10714235) "orange"#FFA500rgb(2551650) "orangered"#FF4500rgb(255690) "orchid"#DA70D6rgb(218112214) "palegoldenrod"#EEE8AArgb(238232170) "palegreen"#98FB98rgb(152251152) "paleturquoise"#AFEEEErgb(175238238) "palevioletred"#DB7093rgb(219112147) "papayawhip"#FFEFD5rgb(255239213) "peachpuff"#FFDAB9rgb(255218185) "peru"#CD853Frgb(20513363) "pink"#FFC0CBrgb(255192203) "plum"#DDA0DDrgb(221160221) "powderblue"#B0E0E6rgb(176224230) "purple"#800080rgb(1280128) "rebeccapurple"#663399rgb(10251153) "red"#FF0000rgb(25500) "rosybrown"#BC8F8Frgb(188143143) "royalblue"#4169E1rgb(65105225) "saddlebrown"#8B4513rgb(1396919) "salmon"#FA8072rgb(250128114) "sandybrown"#F4A460rgb(24416496) "seagreen"#2E8B57rgb(4613987) "seashell"#FFF5EErgb(255245238) "sienna"#A0522Drgb(1608245) "silver"#C0C0C0rgb(192192192) "skyblue"#87CEEBrgb(135206235) "slateblue"#6A5ACDrgb(10690205) "slategray"#708090rgb(112128144) "slategrey"#708090rgb(112128144) "snow"#FFFAFArgb(255250250) "springgreen"#00FF7Frgb(0255127) "steelblue"#4682B4rgb(70130180) "tan"#D2B48Crgb(210180140) "teal"#008080rgb(0128128) "thistle"#D8BFD8rgb(216191216) "tomato"#FF6347rgb(2559971) "turquoise"#40E0D0rgb(64224208) "violet"#EE82EErgb(238130238) "wheat"#F5DEB3rgb(245222179) "white"#FFFFFFrgb(255255255) "whitesmoke"#F5F5F5rgb(245245245) "yellow"#FFFF00rgb(2552550) "yellowgreen"#9ACD32rgb(15420550) └────────────────────────┴─────────┴────────────────────┴──────────────────────┘

Hex RGB value

The hexadecimal RGB format starts with an octothorpe # and is then followed by 3 or 6 hexadecimal digits: 0123456789ABCDEF. Casing is ignored.

  • If 6 digits are used, the format is #RRGGBB:
  • RR represents the red channel;
  • GG represents the green channel; and
  • BB represents the blue channel.
  • If 3 digits are used, the format is #RGB.

In a 3 digit color, each channel is represented by a single digit which is duplicated when converting to the 6 digit format. For example, the color #A2F is the same as #AA22FF.

Hex RGBA value

This is the same as the hex RGB value, but with an extra channel for the alpha component (that sets opacity).

  • If 8 digits are used, the format is #RRGGBBAA, equivalent to the format #RRGGBB with two extra digits for opacity.
  • If 4 digits are used, the format is #RGBA, equivalent to the format #RGB with an extra digit for opacity.

rgb description

The rgb format description is a functional description of a color in the RGB color space. This description follows the format rgb(red, green, blue), where red, green, and blue are decimal integers between 0 and 255. They represent the value of the channel with the same name.

For example, rgb(0, 255, 32) is equivalent to #00FF20.

rgba description

The rgba format description is the same as the rgb with an extra parameter for opacity, which should be a value between 0 and 1.

For example, rgba(0, 255, 32, 0.5) is the color rgb(0, 255, 32) with 50% opacity.

hsl description

The hsl format description is a functional description of a color in the HSL color space. This description follows the format hsl(hue, saturation, lightness), where

  • hue is a float between 0 and 360;
  • saturation is a percentage between 0% and 100%; and
  • lightness is a percentage between 0% and 100%.

For example, the color #00FF20 would be represented as hsl(128, 100%, 50%) in the HSL color space.

hsla description

The hsla format description is the same as the hsl with an extra parameter for opacity, which should be a value between 0 and 1.

For example, hsla(128, 100%, 50%, 0.5) is the color hsl(128, 100%, 50%) with 50% opacity.

Examples

CSS

Header {
    background: red;           /* Color name */
}

.accent {
    color: $accent;            /* Textual variable */
}

#footer {
    tint: hsl(300, 20%, 70%);  /* HSL description */
}

Python

In Python, rules that expect a <color> can also accept an instance of the type Color.

# Mimicking the CSS syntax
widget.styles.background = "red"           # Color name
widget.styles.color = "$accent"            # Textual variable
widget.styles.tint = "hsl(300, 20%, 70%)"  # HSL description

from textual.color import Color
# Using a Color object directly...
color = Color(16, 200, 45)
# ... which can also parse the CSS syntax
color = Color.parse("#A8F")