Channel Read/Write
All channel methods act as a getter when called without arguments (returning the current value) and as a setter when called with an argument (setting the value and returning this).
RGB Channels
red(value?)
Read or write the red channel. Range 0–255.
Alias: r()
xcolor('#3b82f6').red() // 59
xcolor('#3b82f6').red(200) // set red to 200, returns thisgreen(value?)
Read or write the green channel. Range 0–255.
Alias: g()
xcolor('#3b82f6').green() // 130blue(value?)
Read or write the blue channel. Range 0–255.
Alias: b()
xcolor('#3b82f6').blue() // 246alpha(value?)
Read or write the opacity. Range 0–1.
Alias: a(), opacity()
xcolor('#ff0000').alpha() // 1
xcolor('#ff0000').alpha(0.5) // set to semi-transparentHSL Channels
hue(value?)
Read or write the hue. Range 0–360.
Alias: h()
xcolor('#ff0000').hue() // 0
xcolor('#ff0000').hue(120) // becomes greensaturation(value?)
Read or write HSL saturation. Range 0–100.
Alias: s()
xcolor('#ff0000').saturation() // 100
xcolor('#ff0000').saturation(50) // reduce saturationlightness(value?)
Read or write HSL lightness. Range 0–100.
Alias: l()
xcolor('#ff0000').lightness() // 50
xcolor('#ff0000').lightness(80) // lightenCompound Read/Write
rgb(r?, g?, b?)
Without arguments, returns a { r, g, b, a } object. With arguments, sets all three RGB channels at once.
xcolor('#ff0000').rgb() // { r: 255, g: 0, b: 0, a: 1 }
xcolor('#ff0000').rgb(0, 128, 255) // set three channelshsl(h?, s?, l?)
Without arguments, returns a { h, s, l, a } object. With arguments, sets all three HSL channels at once.
xcolor('#ff0000').hsl() // { h: 0, s: 100, l: 50, a: 1 }
xcolor('#ff0000').hsl(210, 80, 60) // set to a blue tonehex(value?)
Without arguments, returns a hex string: 6 digits when fully opaque, 8 digits when alpha < 1. With an argument, sets the color from a hex string.
The setter accepts strings recognized by the active color parsers. A successful call marks the instance valid. A parse failure throws and marks it invalid while retaining its channels.
xcolor('#ff0000').hex() // '#ff0000'
xcolor('#ff0000').hex('#00ff00') // becomes green