Parsing CSS colors (csscolor.parse)

Parsing color values.

csscolor.parse.color(color_string)

Parse colors conforming to the CSS 3 color specification.

The CSS 3 Color module supports the following formats:

  • papayawhip
  • #369
  • #336699
  • rgb(153, 102, 51)
  • rgba(153, 102, 51, 0.5)
  • rgb(60%, 40%, 20%)
  • rgba(60%, 40%, 20%, 0.5)
  • hsl(128, 128, 102)
  • hsla(128, 128, 102, 0.5)
  • hsl(50%, 50%, 40%)
  • hsla(50%, 50%, 40%, 0.5)

The following additional formats are supported:

  • 0x336699 # Python style hex values
  • rgb(0.6, 0.4, 0.2)
  • rgba(0.6, 0.4, 0.2, 0.5)
  • hsl(0.5, 0.5, 0.4)
  • hsla(0.5, 0.5, 0.4, 0.5)

where the decimal is required, so

  • rgb(1.0, 1.0, 1.0) # white
  • rgb(1, 1, 1) # almost black