Go library for parsing CSS color string as defined in the W3C's CSS Color Module Level 4.
- Named colors
- RGB hexadecimal (with and without
#prefix)- Short format
#rgb - Short format with alpha
#rgba - Long format
#rrggbb - Long format with alpha
#rrggbbaa
- Short format
rgb()andrgba()hsl()andhsla()hwb()lab()lch()oklab()oklch()hwba(),hsv(),hsva()- not in CSS standard.
import "github.com/mazznoer/csscolorparser"
c, err := csscolorparser.Parse("gold")
if err != nil {
panic(err)
}
fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f", c.R, c.G, c.B, c.A) // R:1.000, G:0.843, B:0.000, A:1.000
fmt.Println(c.RGBA255()) // 255 215 0 255
fmt.Println(c.HexString()) // #ffd700
fmt.Println(c.RGBString()) // rgb(255,215,0)- csscolorparser (Rust)
- csscolorparser (Javascript)