CSS Function - hue-rotate()



CSS hue-rotate() function rotates the hue of an element's colors. It is used with the CSS filter property. The function takes an angle as a parameter, which determines the degree of hue rotation applied to the element.

Syntax

The syntax for the CSS hue-rotate() function is as follows:

filter: hue-rotate(angle);

Parameter

CSS hue-rotate() function accepts a single parameter (angle) that specifies the rotation of hues in degrees (deg). A value of 0deg leaves the image unchanged, while 360deg completes a full-color cycle.

Examples of CSS hue-rotate() Function

The following examples illustrate the use of the CSS hue-rotate() function. It is used to change the color tones of an image.

Applying Hue Rotation to an Image

In this example, we apply different hue rotation values to an image.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CSS hue-rotate() Function</title>
    <style>
        .container {
            width: 400px;
            border: 2px solid #04af2f;
            padding: 20px;
            margin: 10px;
            display: inline-block;
        }
        .img1 {
            filter: hue-rotate(0deg);
        }
        .img2 {
            filter: hue-rotate(90deg);
        }
        .img3 {
            filter: hue-rotate(180deg);
        }
        .img4 {
            filter: hue-rotate(270deg);
        }
    </style>
</head>
<body>
    <h2>CSS hue-rotate() Function</h2>
    <div class="container">
        <h3>Image at hue-rotate(0deg): </h3>
        <img class="img1" src="/html/images/test.png" alt="logo">
    </div>
    <div class="container">
        <h3>Image at hue-rotate(90deg): </h3>
        <img class="img2" src="/html/images/test.png" alt="logo">
    </div>
    <div class="container">
        <h3>Image at hue-rotate(180deg): </h3>
        <img class="img3" src="/html/images/test.png" alt="logo">
    </div>
    <div class="container">
        <h3>Image at hue-rotate(270deg): </h3>
        <img class="img4" src="/html/images/test.png" alt="logo">
    </div>
</body>
</html>

Applying Hue Rotation on Hover

In this example, the hue of an image is changed when hovered over it.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CSS hue-rotate() Function</title>
    <style>
        img:hover {
            filter: hue-rotate(180deg);
        }
    </style>
</head>
<body>
    <h2>CSS hue-rotate() Function</h2>
    <p>
        <strong>Hover over this image to change its hue.</strong>
    </p>
    <img src="/html/images/test.png" alt="logo">
</body>
</html>

Supported Browsers

Function Chrome Edge Firefox Safari Opera
hue-rotate() 18 12 35 6 15
Advertisements