Skip to main content

parse_css_color

Function parse_css_color 

Source
pub fn parse_css_color(input: &str) -> Option<Srgba>
Expand description

Parse a CSS color string into a straight-alpha Srgba. Supports:

  • hex: #rgb, #rgba, #rrggbb, #rrggbbaa (the leading # is optional);
  • the CSS named colors (case-insensitive) plus transparent;
  • functional notation rgb()/rgba(), hsl()/hsla(), hwb(), oklab(), oklch() — accepting both the legacy comma form (rgb(255, 0, 0)) and the modern space form with an optional / alpha (rgb(255 0 0 / 50%)).

Returns None if the string matches none of these.