https://github.com/mazznoer/csscolorparser
Go (Golang) CSS color parser library
https://github.com/mazznoer/csscolorparser
color colour css graphic parser
Last synced: 3 days ago
JSON representation
Go (Golang) CSS color parser library
- Host: GitHub
- URL: https://github.com/mazznoer/csscolorparser
- Owner: mazznoer
- License: mit
- Created: 2020-11-25T15:11:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2025-05-20T17:15:54.000Z (9 months ago)
- Last Synced: 2025-09-19T06:37:58.780Z (5 months ago)
- Topics: color, colour, css, graphic, parser
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 31
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Go Language CSS Color Parser Library
[](https://pkg.go.dev/github.com/mazznoer/csscolorparser)

[](https://goreportcard.com/report/github.com/mazznoer/csscolorparser)
[Go](https://www.golang.org/) library for parsing CSS color string as defined in the W3C's [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/).
## Supported Color Format
* [Named colors](https://www.w3.org/TR/css-color-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`
* `rgb()` and `rgba()`
* `hsl()` and `hsla()`
* `hwb()`
* `lab()`
* `lch()`
* `oklab()`
* `oklch()`
* `hwba()`, `hsv()`, `hsva()` - not in CSS standard.
## Usage Examples
```go
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)
```
## Try It Online
* [Playground 1](https://play.golang.org/p/8KMIc1TLQB0)
* [Playground 2](https://play.golang.org/p/7kb62KSARwa)
## Similar Projects
* [csscolorparser](https://github.com/mazznoer/csscolorparser-rs) (Rust)
* [csscolorparser](https://github.com/deanm/css-color-parser-js) (Javascript)