CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

CSS Hue Rotate


The CSS filter property applies graphical effects like blurring or color shifting to an element. The hue-rotate() function specifically rotates the hues of the colors in an element around the color wheel, measured in degrees or turns. This allows you to change the entire color scheme of an element without altering the original image file or using complex image editing software.


Example 1: Basic Image Hue Rotation

/* Selects the image with the class 'sunset' */
.sunset {
  /* Rotates the hue of the image by 90 degrees */
  filter: hue-rotate(90deg);
}

Explanation

This code targets an image and applies a 90deg rotation to its hues. Colors are shifted around the color wheel; for instance, yellows might become greens, and blues could turn into purples, creating a completely different mood for the image.


Example 2: Interactive Button on Hover

/* Styling for a basic button */
.color-shift-button {
  background-color: #3498db; /* Initial blue color */
  color: white;
  padding: 15px;
  border: none;
  transition: filter 0.4s ease; /* Smooth transition for the filter effect */
}

/* Applies hue-rotate when the mouse is over the button */
.color-shift-button:hover {
  filter: hue-rotate(180deg);
}

Explanation

This example demonstrates an interactive effect on a button. When a user hovers over it, the hue-rotate() function shifts the element's colors by 180deg, changing the original blue background to an orange hue, providing clear visual feedback.


Example 3: Using Negative Degree Values

/* Selects the element with the class 'card' */
.card {
  background-color: #e74c3c; /* A red color */
  /* Applies a negative hue rotation */
  filter: hue-rotate(-60deg);
}

Explanation

The hue-rotate() function also accepts negative values. A rotation of -60deg shifts the hue in the opposite direction on the color wheel, which is equivalent to a 300deg positive rotation, transforming the red background into a magenta color.


Example 4: Creating a Pulsing Animation

/* Defines a keyframe animation named 'pulse-color' */
@keyframes pulse-color {
  0% {
    filter: hue-rotate(0deg); /* Starts with the original color */
  }
  100% {
    filter: hue-rotate(360deg); /* Completes a full circle back to the original color */
  }
}

/* Applies the animation to the element */
.animated-orb {
  width: 100px;
  height: 100px;
  background: linear-gradient(45deg, #f06, #09f);
  border-radius: 50%;
  /* The animation runs infinitely, taking 5 seconds per cycle */
  animation: pulse-color 5s infinite linear;
}

Explanation

This code uses CSS animations to create a continuously changing color effect. The hue-rotate() value animates from 0deg to 360deg repeatedly, causing the element to cycle through every possible hue, resulting in a vibrant, eye-catching effect.


Example 5: Combining Multiple Filters

/* Targets an image with the class 'vibrant-nature' */
.vibrant-nature {
  /* Applies two filter functions at once */
  filter: hue-rotate(45deg) saturate(2);
}

Explanation

You can combine hue-rotate() with other filter functions for more complex effects. In this snippet, the image's hue is first rotated by 45deg, and then its color saturation is doubled, making the new colors appear much more vivid and intense.


Example 6: Using 'turn' Units

/* Selects the text block with the class 'promo-text' */
.promo-text {
  background-color: #2ecc71; /* A green color */
  /* Rotates the hue by half a turn on the color wheel */
  filter: hue-rotate(0.5turn);
}

Explanation

Besides deg, you can use turn as a unit for rotation. One full turn is equivalent to 360deg, so 0.5turn is the same as a 180deg rotation. This code changes the green background to a purple hue.


Example 7: Applying a Filter to a Video

/* Selects a video element */
video {
  /* Changes the color scheme of the video content */
  filter: hue-rotate(240deg);
  width: 100%;
}

Explanation

The filter property is not limited to static elements; it can also be applied directly to media like videos. This CSS applies a 240deg hue rotation to a playing video, shifting all its colors in real-time for a stylized, artistic effect.