This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The hue-rotate() CSS function rotates the hue of an element and its contents. Its result is a <filter-function>.
Note: hue-rotate() is specified as a matrix operation on the RGB color. It does not actually convert the color to the HSL model, which is a non-linear operation. Therefore, it may not preserve the saturation or lightness of the original color, especially for saturated colors.
filter: hue-rotate(0);
filter: hue-rotate(90deg);
filter: hue-rotate(-0.25turn);
filter: hue-rotate(3.142rad);
<section id="default-example">
<img
class="transition-all"
id="example-element"
src="/shared-assets/images/examples/firefox-logo.svg"
width="200" />
</section>
hue-rotate(angle)
angle OptionalThe relative change in hue of the input sample, specified as an <angle>. A value of 0deg leaves the input unchanged. A positive hue rotation increases the hue value, while a negative rotation decreases the hue value. The initial value for interpolation is 0. There is no minimum or maximum value. The effect of values above 360deg are, given hue-rotate(Ndeg), evaluates to N modulo 360. The default value is 0deg.
The <angle> CSS data type represents an angle value expressed in degrees, gradians, radians, or turns. The following are equivalent:
hue-rotate(-180deg) hue-rotate(540deg) hue-rotate(200grad) hue-rotate(3.14159rad) hue-rotate(0.5turn)
<hue-rotate()> =
hue-rotate( [ <angle> | <zero> ]? )
This example applies a hue-rotate() filter via the backdrop-filter CSS property to the paragraph, color shifting to the area behind the <p>.
.container {
background: url("/shared-assets/images/examples/listen_to_black_women.jpg")
no-repeat left / contain #011296;
}
p {
backdrop-filter: hue-rotate(240deg);
text-shadow: 2px 2px #011296;
}
This example applies a hue-rotate() filter via the filter CSS property adding the color shift to the entire element, including content, border, and background image.
p {
filter: hue-rotate(-60deg);
text-shadow: 2px 2px blue;
background-color: magenta;
color: goldenrod;
border: 1em solid rebeccapurple;
box-shadow:
inset -5px -5px red,
5px 5px yellow;
}
The SVG <filter> element is used to define custom filter effects that can then be referenced by id. The <filter>'s <feColorMatrix> primitive hueRotate type provides the same effect. Given the following:
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 220 220"
color-interpolation-filters="sRGB"
height="220"
width="220">
<filter id="hue-rotate">
<feColorMatrix type="hueRotate" values="90" />
</filter>
</svg>
These values produce the same results:
filter: hue-rotate(90deg); /* 90deg rotation */
filter: url("#hue-rotate"); /* with embedded SVG */
filter: url("folder/fileName.svg#hue-rotate"); /* external svg filter definition */
This example shows three images: the image with a hue-rotate() filter function applied, the image with an equivalent url() filter applied, and the original images for comparison:
The diagram below compares two color gradients starting with red: the first is generated using hue-rotate(), and the second uses actual HSL color values. Note how the hue-rotate() gradient shows obvious differences in saturation and lightness in the middle.
<div> <p>Using <code>hue-rotate()</code></p> <div id="hue-rotate"></div> </div> <div> <p>Using <code>hsl()</code></p> <div id="hsl"></div> </div>
const hueRotate = document.getElementById("hue-rotate");
const hsl = document.getElementById("hsl");
for (let i = 0; i < 360; i++) {
const div1 = document.createElement("div");
div1.style.backgroundColor = `hsl(${i}, 100%, 50%)`;
hsl.appendChild(div1);
const div2 = document.createElement("div");
div2.style.backgroundColor = "red";
div2.style.filter = `hue-rotate(${i}deg)`;
hueRotate.appendChild(div2);
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
hue-rotate |
18 | 12 | 35 | 15 | 6 | 53 | 35 | 14 | 6 | 6.0 | 4.4 | 6 |
<filter-function> functions available to be used in values of the filter and backdrop-filter properties include:
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/hue-rotate