10 releases

new 0.1.3 Jan 12, 2025
0.1.1 Jan 11, 2025
0.0.7 Jan 8, 2025

#882 in Parser implementations

Download history 547/week @ 2025-01-05

547 downloads per month
Used in win-color

MIT/Apache

84KB
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
~132K SLoC