Color filters change or extract properties of CSS color strings. They are usually used together with color settings of the theme design.
colortorgb
Converts a CSS color string to the CSS rgb() format.
{{ '#7ab55c' | color_to_rgb }}
rgb(122, 181, 92)
If the input color has an alpha component, the output uses the CSS rgba() format.
{{ 'hsla(100, 38%, 54%, 0.5)' | color_to_rgb }}
rgba(122, 181, 92, 0.5)
colortohsl
Converts a CSS color string to the CSS hsl() format.
{{ '#7ab55c' | color_to_hsl }}
hsl(100, 38%, 54%)
If the input color has an alpha component, the output uses the CSS hsla() format.
{{ 'rgba(122, 181, 92, 0.5)' | color_to_hsl }}
hsla(100, 38%, 54%, 0.5)
colortohex
Converts a CSS color string to hex6 format.
{{ 'rgb(122, 181, 92)' | color_to_hex }}
#7ab55c
The output is always hex6. If the input color has an alpha channel, it is dropped in the output.
{{ 'rgba(122, 181, 92, 0.5)' | color_to_hex }}
#7ab55c
color_extract
Extracts a component from the color. Valid components are alpha, red, green, blue, hue, saturation and lightness.
{{ '#7ab55c' | color_extract: 'red' }}
122
color_brightness
Calculates the perceived brightness of the given color. Uses the W3C recommendations for calculating perceived brightness to ensure adequate contrast.
{{ '#7ab55c' | color_brightness }}
153.21
color_modify
Changes the given component of a color.
- Red, green and blue values must be a number between 0 and 255
- Alpha must be a decimal number between 0 and 1
- Hue must be between 0 and 360 degrees
- Saturation and lightness must be between 0 and 100 percent
{{ '#7ab55c' | color_modify: 'red', 255 }}
#ffb55c
The filter returns the color in the format that fits the change. For example, if you change the alpha channel, the filter returns rgba() even if the input was hex.
{{ '#7ab55c' | color_modify: 'alpha', 0.85 }}
rgba(122, 181, 92, 0.85)
color_lighten
Lightens the input color. Takes a value between 0 and 100 percent.
{{ '#7ab55c' | color_lighten: 30 }}
#d0e5c5
color_darken
Darkens the input color. Takes a value between 0 and 100 percent.
{{ '#7ab55c' | color_darken: 30 }}
#355325
color_saturate
Saturates the input color. Takes a value between 0 and 100 percent.
{{ '#7ab55c' | color_saturate: 30 }}
#6ed938
color_desaturate
Desaturates the input color. Takes a value between 0 and 100 percent.
{{ '#7ab55c' | color_desaturate: 30 }}
#869180
color_mix
Mixes two colors. The blend factor must be a value between 0 and 100 percent.
{{ '#7ab55c' | color_mix: '#ffc0cb', 50 }}
#bdbb94
If one input has an alpha component and the other does not, an alpha of 1 is assumed for the input without it.
{{ 'rgba(122, 181, 92, 0.75)' | color_mix: '#ffc0cb', 50 }}
rgba(189, 187, 148, 0.875)
color_contrast
Calculates the contrast ratio between two colors. Returns the numerator of the ratio, whose denominator is 1. For a contrast ratio of 3.5:1, the filter returns 3.5.
For accessibility, WCAG 2.0 level AA requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. Level AAA requires at least 7:1 for normal text and 4.5:1 for large text.
The order of the colors does not matter. The filter detects the lighter and darker color automatically.
{{ '#495859' | color_contrast: '#fffffb' }}
7.4
color_difference
Calculates the color difference or distance between two colors. For accessibility, the W3C suggests a color difference greater than 500.
{{ '#ff0000' | color_difference: '#abcdef' }}
528
brightness_difference
Calculates the perceived brightness difference between two colors. For accessibility, the W3C suggests a brightness difference greater than 125.
{{ '#fff00f' | brightness_difference: '#0b72ab' }}
129