Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

hue-rotate() — hue rotation of a buffer

`hue-rotate()` rotates the colors of a rendered image by the supplied angle using a filter matrix.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

hue-rotate( [ <angle> | <zero> ]? )

hue-rotate() rotates the colors of a rendered image by the supplied angle using a filter matrix.

The example retains red pixel 255,0,0 for both hue-rotate(0deg) and hue-rotate(). hue-rotate(120deg) yields 0,113,0, and hue-rotate(480deg) yields the same 0,113,0, demonstrating the periodic visual effect of a full turn.

Grammar: hue-rotate( [ <angle> | <zero> ]? ).

An omitted argument means zero, but implementations must not normalize the stored value modulo 360deg, because larger angles are needed for animation. The function operates in a filter list on the rendered buffer, so filter order changes the result. It is an RGB matrix rotation, not an edit to the hue component of hsl(); saturation and luminance can shift or clip.

Examples

const sample=async filter=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><foreignObject width="4" height="4"><div xmlns="http://www.w3.org/1999/xhtml" style="width:4px;height:4px;background:rgb(255 0 0);filter:'+filter+'"></div></foreignObject></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=4;const context=canvas.getContext('2d');context.drawImage(image,0,0);return [...context.getImageData(2,2,1,1).data].slice(0,3).join(',')};
const zero=await sample('hue-rotate(0deg)');
const omitted=await sample('hue-rotate()');
const turn120=await sample('hue-rotate(120deg)');
const turn480=await sample('hue-rotate(480deg)');
console.log('zero='+zero+'; omitted='+omitted+'; turn-120='+turn120+'; turn-480='+turn480);

Result

zero=255,0,0; omitted=255,0,0; turn-120=0,113,0; turn-480=0,113,0

`hue-rotate()` rotates the colors of a rendered image by the supplied angle using a filter matrix.

Sources