12 releases

0.1.5 Jan 20, 2025
0.1.4 Jan 16, 2025
0.0.7 Jan 8, 2025

#1097 in Parser implementations

Download history 542/week @ 2025-01-05 314/week @ 2025-01-12 144/week @ 2025-01-19 1/week @ 2025-01-26 65/week @ 2025-02-02

649 downloads per month
Used in win-color

MIT/Apache

88KB
2K SLoC

colorparser-css


lib.rs:

Overview

Rust library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.

Supported Color Format

  • Named colors
  • RGB hexadecimal (with and without # prefix)
    • Short format #rgb
    • Short format with alpha #rgba
    • Long format #rrggbb
    • Long format with alpha #rrggbbaa
  • rgb() and rgba()
  • hsl() and hsla()
  • gradient()

Example Color Format

Click to expand!
transparent
gold
rebeccapurple
lime
accent
accent_inactive
#0f0
#0f0f
#00ff00
#00ff00ff
rgb(0,255,0)
rgb(0% 100% 0%)
rgb(0 255 0 / 100%)
rgba(0,255,0,1)
hsl(120,100%,50%)
hsl(120deg 100% 50%)
hsl(-240 100% 50%)
hsl(-240deg 100% 50%)
hsl(0.3333turn 100% 50%)
hsl(133.333grad 100% 50%)
hsl(2.0944rad 100% 50%)
hsla(120,100%,50%,100%)
gradient(rgb(0, 255, 0), #0f0, to right)

Usage

Add this to your Cargo.toml

colorparser_css = "0.1.0"

Default Feature

Optional Features

  • serde: Enables serializing (into HEX string) and deserializing (from any supported string color format) using serde framework.

Dependencies

~2–12MB
~137K SLoC