csscolor

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package csscolor parses CSS color values shared by the html and svg packages: named colors, hex, rgb()/rgba(), hsl()/hsla(), and cmyk()/device-cmyk(). It has no opinion on the caller-specific keywords "none", "currentcolor", "transparent", "inherit", or "initial" — those stay in the calling package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNames

func AllNames() []string

AllNames returns every recognized CSS named-color keyword. Used by tests that verify table completeness against legacy callers.

func Lookup

func Lookup(name string) (r, g, b float64, ok bool)

Lookup returns the RGB components (each 0-1, full float64 precision) of a CSS named color. Callers must lowercase name first. ok is false for unknown names.

Types

type Color

type Color struct {
	R, G, B, A float64
	CMYK       *[4]float64
}

Color is a parsed CSS color. R, G, B, and A are in [0, 1]. CMYK is non-nil only when the input was a cmyk()/device-cmyk() function; callers that don't support CMYK should treat a non-nil CMYK as unsupported.

func Parse

func Parse(s string) (Color, bool)

Parse parses a CSS color value. Supports named colors, #RGB, #RGBA, #RRGGBB, #RRGGBBAA, rgb()/rgba() (comma and CSS Color 4 space-separated forms), hsl()/hsla() (comma and space forms), and cmyk()/device-cmyk(). Alpha defaults to 1.0 for formats that don't include it.

type RGB8

type RGB8 struct {
	R, G, B uint8
}

RGB8 is an 8-bit sRGB triple, matching the CSS Color Level 4 keyword definitions exactly (no rounding loss from decimal literals).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL