Tailwind CSS Backdrop Hue Rotate
Backdrop Hue Rotate applies a hue rotation filter to the backdrop of an element. This transforms the color spectrum of the backdrop, enabling unique visual effects. Tailwind CSS provides a set of utilities to simplify the implementation of backdrop hue rotation.
In this guide, we will learn how to use Tailwind CSS backdrop-hue-rotate
utilities, explore conditional modifiers, and define custom values to build aesthetic user interfaces.
Class | Properties | Example |
---|---|---|
backdrop-hue-rotate-0 | backdrop-filter: hue-rotate(0deg); | <div className="backdrop-hue-rotate-0"></div> |
backdrop-hue-rotate-15 | backdrop-filter: hue-rotate(15deg); | <div className="backdrop-hue-rotate-15"></div> |
backdrop-hue-rotate-30 | backdrop-filter: hue-rotate(30deg); | <div className="backdrop-hue-rotate-30"></div> |
backdrop-hue-rotate-60 | backdrop-filter: hue-rotate(60deg); | <div className="backdrop-hue-rotate-60"></div> |
backdrop-hue-rotate-90 | backdrop-filter: hue-rotate(90deg); | <div className="backdrop-hue-rotate-90"></div> |
backdrop-hue-rotate-180 | backdrop-filter: hue-rotate(180deg); | <div className="backdrop-hue-rotate-180"></div> |
Overview of Backdrop Hue Rotate
Adding the Backdrop Hue Rotate
To rotate the hue of the backdrop, use Tailwind's backdrop-hue-rotate-*
utilities, like, backdrop-hue-rotate-60
, backdrop-hue-rotate-90
, etc. on elements where a backdrop-filter
effect exists.
export default function BackdropHueRotateDemo() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> {/* Semi-transparent overlay with hue rotate backdrop effect */} <div className="backdrop-hue-rotate-90 bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg">90° Backdrop Hue Rotate</p> </div> </div> ); }
Adding Negative Values
Sometimes, rather than shifting hues forward, you might need to adjust them backward using negative values. To add negative values, prepend -
to the backdrop utilities, e.g.,-backdrop-hue-rotate-60
, -backdrop-hue-rotate-90
, etc.
export default function NegativeHueRotate() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> {/* Semi-transparent overlay with negative hue rotate backdrop effect */} <div className="-backdrop-hue-rotate-90 bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg">Negative 90° Backdrop Hue Rotate</p> </div> </div> ); }
Resetting Backdrop Filters
If you want to eliminate the hue rotation effect completely, use the backdrop-hue-rotate-0
utility. To remove all the backdrop filters, use the backdrop-filter-none
utility.
export default function ResetBackdropFilters() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> {/* Semi-transparent overlay with no backdrop effects */} <div className="backdrop-filter-none backdrop-hue-rotate-90 backdrop-blur-sm bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg">No Backdrop Filters</p> </div> </div> ); }
States and Responsive Modifiers
Sometimes, applying backdrop hue rotation conditionally on specific states and breakpoints allows for more intentional designs. Tailwind provides state and responsive modifier to achieve this.
Hover and Focus States
By applying hue rotation dynamically under states like hover or focus, you can ensure that your designs look interactive and responsive to user action. Use Tailwind’s state modifiers like- hover
, focus
, etc. to apply the utility only when these states are active.
export default function HoverStateHueRotate() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> <div className="hover:backdrop-hue-rotate-90 bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg">Hover to add backdrop hue rotate</p> </div> </div> ); }
Breakpoint Modifiers
You can also adjust the hue rotation based on screen size breakpoints, creating adaptive designs across devices. Use Tailwind’s breakpoint modifiers like- sm
, md
, etc. to apply the utility only on these breakpoints and above.
export default function BreakpointBackdropHueRotate() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> <div className="sm:backdrop-hue-rotate-30 md:backdrop-hue-rotate-60 lg:backdrop-hue-rotate-90 bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg text-center px-10">Backdrop hue rotate progresses based on the breakpoint</p> </div> </div> ); }
Custom Backdrop Hue Rotate
Out-of-the-box utilities in Tailwind are powerful, but in some cases, you may need to add custom values for finer control over the hue rotation. Tailwind allows you to configure the default theme to achieve this.
Extending the Theme
By modifying the Tailwind CSS configuration file (tailwind.config.js
), you can add new utilities to support custom hue rotation values.
In the below example, we have defined a backdrop-hue-rotate-270
utility.
import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; export default function CustomHueRotate() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> <div className="backdrop-hue-rotate-270 bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg text-center px-10">Custom 270° backdrop hue rotate</p> </div> </div> ); }
Using Arbitrary Values
Tailwind also allows defining arbitrary values directly in your classes for one-off use cases. Just use the square bracket syntax [value]
wherever you need it, e.g., backdrop-hue-rotate-[50deg]
.
export default function ArbitraryHueRotate() { return ( <div className="relative h-screen w-screen"> {/* Background content */} <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" alt="Backdrop content" className="h-full w-full object-cover" /> <div className="backdrop-hue-rotate-[50deg] bg-white/30 absolute inset-0 flex items-center justify-center"> <p className="text-lg text-center px-10">Arbitrary 50° backdrop hue rotate</p> </div> </div> ); }
Real World Examples
Product Card Grid
This example shows a grid of product cards where each card's background image gets a hue rotation effect on hover, creating an engaging shopping experience.
export default function ProductGrid() { const products = [ { id: 1, name: "Premium Leather Backpack", price: "$149.99", src: "https://images.unsplash.com/photo-1622560480605-d83c853bc5c3", alt: "Brown leather backpack" }, { id: 2, name: "Minimalist Watch", price: "$89.99", src: "https://images.unsplash.com/photo-1524592094714-0f0654e20314", alt: "Silver analog watch" }, { id: 3, name: "Wireless Headphones", price: "$199.99", src: "https://images.unsplash.com/photo-1505740420928-5e560c06d30e", alt: "Black wireless headphones" }, { id: 4, name: "Smart Speaker", price: "$129.99", src: "https://images.unsplash.com/photo-1589492477829-5e65395b66cc", alt: "Smart home speaker" }, { id: 5, name: "Mechanical Keyboard", price: "$169.99", src: "https://images.unsplash.com/photo-1618384887929-16ec33fab9ef", alt: "RGB mechanical keyboard" }, { id: 6, name: "Wireless Mouse", price: "$79.99", src: "https://images.unsplash.com/photo-1527814050087-3793815479db", alt: "Ergonomic wireless mouse" } ]; return ( <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-6"> {products.map((product) => ( <div key={product.id} className="group relative overflow-hidden rounded-lg shadow-lg hover:shadow-xl transition-all duration-300" > <div className="relative h-64"> {/* Image */} <img src={product.src} alt={product.alt} className="w-full h-full object-cover transition-all duration-300" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-60"></div> </div> <div className="p-4 bg-white"> <h3 className="text-lg font-semibold">{product.name}</h3> <p className="text-blue-600 font-bold">{product.price}</p> </div> </div> ))} </div> ); }
Team Member Gallery
This example displays team members in a gallery format with a smooth hue rotation effect when hovering over each member's photo.
export default function TeamGallery() { const team = [ { id: 1, name: "Sarah Johnson", role: "CEO", src: "https://images.unsplash.com/photo-1494790108377-be9c29b29330", alt: "Sarah Johnson CEO" }, { id: 2, name: "Michael Chen", role: "CTO", src: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e", alt: "Michael Chen CTO" }, { id: 3, name: "Emma Williams", role: "Design Director", src: "https://images.unsplash.com/photo-1438761681033-6461ffad8d80", alt: "Emma Williams Design Director" }, { id: 4, name: "James Rodriguez", role: "Lead Developer", src: "https://images.unsplash.com/photo-1500648767791-00dcc994a43e", alt: "James Rodriguez Lead Developer" }, { id: 5, name: "Lisa Thompson", role: "Marketing Head", src: "https://images.unsplash.com/photo-1487412720507-e7ab37603c6f", alt: "Lisa Thompson Marketing Head" }, { id: 6, name: "David Kim", role: "Product Manager", src: "https://images.unsplash.com/photo-1519345182560-3f2917c472ef", alt: "David Kim Product Manager" } ]; return ( <div className="bg-gray-100 p-8"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8"> {team.map((member) => ( <div key={member.id} className="relative group overflow-hidden rounded-lg"> {/* Image */} <img src={member.src} alt={member.alt} className="w-full h-80 object-cover transition-all duration-500" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-90"></div> {/* Text Content */} <div className="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-6"> <h3 className="text-white text-xl font-bold">{member.name}</h3> <p className="text-gray-200">{member.role}</p> </div> </div> ))} </div> </div> ); }
Travel Destination Showcase
This example presents travel destinations with a mood-changing hue rotation effect that enhances the visual appeal of each location.
export default function TravelShowcase() { const destinations = [ { id: 1, name: "Kyoto, Japan", description: "Traditional temples and cherry blossoms", src: "https://images.unsplash.com/photo-1493976040374-85c8e12f0c0e", alt: "Japanese temple during spring" }, { id: 2, name: "Machu Picchu, Peru", description: "Ancient Incan citadel in the mountains", src: "https://images.unsplash.com/photo-1526392060635-9d6019884377", alt: "Machu Picchu ruins" }, { id: 3, name: "Venice, Italy", description: "Romantic canals and historic architecture", src: "https://images.unsplash.com/photo-1514890547357-a9ee288728e0", alt: "Venice canal with gondolas" }, { id: 4, name: "Bali, Indonesia", description: "Tropical paradise with rice terraces", src: "https://images.unsplash.com/photo-1537996194471-e657df975ab4", alt: "Bali rice terraces" }, { id: 5, name: "Reykjavik, Iceland", description: "Northern lights and dramatic landscapes", src: "https://images.unsplash.com/photo-1504893524553-b855bce32c67", alt: "Iceland northern lights" } ]; return ( <div className="max-w-7xl mx-auto p-8"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10"> {destinations.map((destination) => ( <div key={destination.id} className="group cursor-pointer relative overflow-hidden rounded-2xl"> {/* Image */} <img src={destination.src} alt={destination.alt} className="w-full h-96 object-cover transition-transform duration-700 group-hover:scale-105" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-90"></div> {/* Gradient and Text */} <div className="absolute inset-0 bg-gradient-to-b from-transparent to-black/60 group-hover:opacity-90 transition-opacity"> <div className="absolute bottom-6 left-6 right-6"> <h3 className="text-white text-2xl font-bold mb-2">{destination.name}</h3> <p className="text-gray-200 text-sm">{destination.description}</p> </div> </div> </div> ))} </div> </div> ); }
Art Gallery Exhibition
This example showcases artwork with an artistic hue rotation effect that adds a dynamic dimension to the viewing experience.
export default function ArtGallery() { const artworks = [ { id: 1, title: "Urban Dreams", artist: "Marcus Chen", src: "https://images.unsplash.com/photo-1547826039-bfc35e0f1ea8", alt: "Contemporary urban art piece" }, { id: 2, title: "Nature's Dance", artist: "Sophie Laurent", src: "https://images.unsplash.com/photo-1579783902614-a3fb3927b6a5", alt: "Nature-inspired artwork" }, { id: 3, title: "Color Symphony", artist: "Jean Michel", src: "https://images.unsplash.com/photo-1578926288207-a90a5366759d", alt: "Colorful abstract composition" } ]; return ( <div className="bg-black min-h-screen p-8"> <div className="max-w-6xl mx-auto"> <div className="grid grid-cols-1 md:grid-cols-2 gap-8"> {artworks.map((artwork) => ( <div key={artwork.id} className="group relative overflow-hidden rounded-lg"> {/* Image */} <img src={artwork.src} alt={artwork.alt} className="w-full h-[500px] object-cover transition-all duration-1000" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-700 group-hover:backdrop-hue-rotate-180"></div> {/* Title and Artist */} <div className="absolute bottom-0 left-0 right-0 p-6 bg-gradient-to-t from-black via-black/50 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"> <h3 className="text-white text-2xl font-bold mb-2">{artwork.title}</h3> <p className="text-gray-300">by {artwork.artist}</p> </div> </div> ))} </div> </div> </div> ); }
Music Album Showcase
This example displays music albums with a creative hue rotation effect that responds to user interaction.
export default function AlbumShowcase() { const albums = [ { id: 1, title: "Midnight Dreams", artist: "The Lunar Collective", genre: "Electronic", src: "https://images.unsplash.com/photo-1526478806334-5fd488fcaabc", alt: "Electronic album cover art" }, { id: 2, title: "Urban Soul", artist: "Metro Beats", genre: "Hip Hop", src: "https://images.unsplash.com/photo-1514525253161-7a46d19cd819", alt: "Hip hop album artwork" }, { id: 3, title: "Acoustic Journey", artist: "Forest Echo", genre: "Folk", src: "https://images.unsplash.com/photo-1511735111819-9a3f7709049c", alt: "Folk music album cover" }, { id: 4, title: "Electric Sky", artist: "Neon Pulse", genre: "Synthwave", src: "https://images.unsplash.com/photo-1518609878373-06d740f60d8b", alt: "Synthwave album artwork" }, { id: 5, title: "Jazz Nights", artist: "Blue Note Quartet", genre: "Jazz", src: "https://images.unsplash.com/photo-1511735111819-9a3f7709049c", alt: "Jazz album cover" }, { id: 6, title: "Digital Sunset", artist: "Virtual Horizon", genre: "Ambient", src: "https://images.unsplash.com/photo-1515405295579-ba7b45403062", alt: "Ambient music artwork" } ]; return ( <div className="bg-gradient-to-br from-purple-900 to-black min-h-screen p-8"> <div className="max-w-7xl mx-auto"> <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-3 gap-6"> {albums.map((album) => ( <div key={album.id} className="group relative overflow-hidden rounded-lg"> {/* Album Cover */} <img src={album.src} alt={album.alt} className="w-full h-full object-cover transition-all duration-500 group-hover:scale-110" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-90"></div> {/* Details & Genre Badge */} <div className="absolute top-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent opacity-0 group-hover:opacity-100 transition-all duration-300 flex flex-col justify-end p-6"> <h3 className="text-white text-xl font-bold">{album.title}</h3> <p className="text-gray-300">{album.artist}</p> <span className="inline-block mt-2 px-3 py-1 bg-white/20 rounded-full text-white text-sm"> {album.genre} </span> </div> </div> ))} </div> </div> </div> ); }
Customization Examples
Interactive Profile Card
This example demonstrates a profile card with a hover effect that changes the backdrop hue-rotate value, creating an engaging color transformation effect.
// App.js import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; export default function ProfileCard() { return ( <div className="flex h-screen items-center justify-center bg-gray-900"> <div className="relative group rounded-lg overflow-hidden"> {/* Profile Image */} <img src="https://images.unsplash.com/photo-1519345182560-3f2917c472ef" alt="Profile" className="w-80 h-96 object-cover opacity-80 transition-all duration-500" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-125 transition-all duration-500 group-hover:backdrop-hue-rotate-125"></div> {/* Text Content */} <div className="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 via-black/50 to-transparent p-6 text-white"> <h2 className="text-2xl font-bold">John Developer</h2> <p className="text-sm mt-2">Senior Frontend Engineer</p> </div> </div> </div> ); }
Image Gallery
This example shows how to create an image gallery with custom backdrop hue-rotate
changes on hover.
// App.js import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; export default function ImageGallery() { return ( <div className="flex items-center justify-center bg-gray-900 py-4"> <div className="grid grid-cols-2 gap-6 p-8"> {[ "https://images.unsplash.com/photo-1501854140801-50d01698950b", "https://images.unsplash.com/photo-1426604966848-d7adac402bff", "https://images.unsplash.com/photo-1472214103451-9374bd1c798e", "https://images.unsplash.com/photo-1469474968028-56623f02e42e" ].map((src, index) => ( <div key={index} className="relative group overflow-hidden rounded-lg"> {/* Image */} <img src={src} alt={`Nature ${index + 1}`} className="w-full h-64 object-cover transition-all duration-500 group-hover:scale-110" /> {/* Overlay with Backdrop Hue Rotate Effect */} <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-270"></div> </div> ))} </div> </div> ); }
Music Genre Showcase
This example shows a music genre showcase with custom backdrop-hue-rotate
values.
// App.js import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; import { useState } from "react"; export default function MusicGenreShowcase() { const [hueIndex, setHueIndex] = useState(0); const hueClasses = ["backdrop-hue-rotate-0", "backdrop-hue-rotate-30", "backdrop-hue-rotate-60", "backdrop-hue-rotate-90"]; const handleMouseMove = (e) => { const { clientX, clientY, currentTarget } = e; const { width, height, left, top } = currentTarget.getBoundingClientRect(); const xPercent = ((clientX - left) / width) * 3; // Scale between 0 and 3 const yPercent = ((clientY - top) / height) * 3; const index = Math.round((xPercent + yPercent) / 2); // Get index between 0-3 setHueIndex(index); }; const genres = [ { id: 1, name: "Rock", image: "https://images.unsplash.com/photo-1549646075-f533f4622ef7" }, { id: 2, name: "Jazz", image: "https://images.unsplash.com/flagged/photo-1569231290150-9c6200705c5b" }, { id: 3, name: "Hip Hop", image: "https://images.unsplash.com/photo-1601128092089-35891312a94f" }, { id: 4, name: "Electronic", image: "https://images.unsplash.com/photo-1599423424751-54e0c1187a02" }, { id: 5, name: "Classical", image: "https://images.unsplash.com/photo-1485688809171-248861015a63" }, { id: 6, name: "Pop", image: "https://images.unsplash.com/photo-1510731491328-7363eecd7b2d" }, ]; return ( <div className={`flex items-center justify-center bg-black transition-all duration-500 ${hueClasses[hueIndex]}`} onMouseMove={handleMouseMove} > <div className="relative w-full max-w-6xl p-8 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 rounded-xl backdrop-blur-xl" > {genres.map((genre) => ( <div key={genre.id} className="relative group overflow-hidden rounded-lg shadow-lg"> <img src={genre.image} alt={genre.name} className="w-full h-64 object-cover transition-all duration-500 group-hover:scale-110" /> <div className="absolute inset-0 bg-white/10 backdrop-hue-rotate-0 transition-all duration-500 group-hover:backdrop-hue-rotate-190"></div> <div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/50 to-transparent p-6 flex items-end"> <h3 className="text-white text-2xl font-bold">{genre.name}</h3> </div> </div> ))} </div> </div> ); }
Best Practices
Maintain Design Consistency
A consistent design language ensures that hue rotations applied to backgrounds and overlays blend seamlessly with other UI elements. It is crucial to define a standard set of hues and rotations that align with your brand's color scheme, preventing visual inconsistencies.
For example, if a design system incorporates soft blues and purples, applying a subtle backdrop-hue-rotate-60
can maintain a unified aesthetic across the project.
Additionally, setting clear guidelines for when and where hue rotations should be used helps prevent overuse, which can lead to an unpolished or chaotic appearance.
Leverage Utility Combinations
Combining backdrop-hue-rotate
with other backdrop utilities can create unique and modern design effects. Pairing it with backdrop-blur
, backdrop-brightness
, and backdrop-opacity
helps add depth and smooth transitions, making UI elements feel more polished. This technique works well for glassmorphism effects, modal backgrounds, and hover interactions.
For example, using backdrop-hue-rotate-60 backdrop-blur-lg backdrop-opacity-50
on a floating card can give it a soft tinted transparency while keeping the content clear. This is especially useful for interactive elements, like hover effects and expanding panels, where smooth color shifts can enhance the user experience.
Accessibility Considerations
Enhance Readability and Navigability
Using backdrop hue rotate can significantly impact readability, especially when applied to background elements. If the hue shift results in poor contrast between text and its background, users may struggle to read content effectively. To maintain readability, always test hue-rotated elements with text overlays under various conditions.
A good practice is to also use contrast-enhancing utilities such as backdrop-brightness
or backdrop-contrast
when hue rotation is applied. This ensures that text remains legible even when color shifts are introduced.
Support Accessible Interactive Elements
Interactive components, such as buttons or hover effects, should remain perceivable when backdrop-hue-rotate
is applied. Users who rely on high-contrast mode or have color vision deficiencies may struggle to recognize interactive elements if hue rotations blend them too much with the background.
A good practice is to reinforce interactive elements with distinct borders, shadows, or hover state changes. Instead of relying solely on color shifts, adding outline-*
, border-*
, or shadow-*
ensures buttons remain distinguishable.
This approach helps users perceive interactive elements more clearly, making navigation more intuitive for all users, including those with visual impairments.