Kombai Logo

Tailwind CSS Brightness

Brightness in CSS refers to the adjustment of how light or dark an element, particularly an image or visual component, appears. This feature modifies the intensity of an element's colors, ranging from completely dark (black) to fully bright (white). It enables developers to control the visual tone of their design effectively, adding depth or emphasis to specific components. In CSS, the filter property includes brightness as one of its values, making it suitable for creating dynamic UI adjustments.

Tailwind CSS, as a utility-first framework, provides a range of pre-defined classes for controlling brightness using the brightness-{value} utility. These utilities remove the hassle of writing custom CSS for such adjustments, significantly speeding up the development process. With Tailwind, you can modify brightness dynamically based on screen states, breakpoints, or custom values.

ClassPropertiesExample
brightness-0filter: brightness(0);<div className="brightness-0"></div>
brightness-50filter: brightness(.5);<div className="brightness-50"></div>
brightness-75filter: brightness(.75);<div className="brightness-75"></div>
brightness-90filter: brightness(.9);<div className="brightness-90"></div>
brightness-95filter: brightness(.95);<div className="brightness-95"></div>
brightness-100filter: brightness(1);<div className="brightness-100"></div>
brightness-105filter: brightness(1.05);<div className="brightness-105"></div>
brightness-110filter: brightness(1.1);<div className="brightness-110"></div>
brightness-125filter: brightness(1.25);<div className="brightness-125"></div>
brightness-150filter: brightness(1.5);<div className="brightness-150"></div>
brightness-200filter: brightness(2);<div className="brightness-200"></div>

Overview of Brightness

Adding the Brightness

To modify brightness, simply apply one of Tailwind's brightness-{value} classes to an element. The value ranges from 0 (completely dark) to 100 (default brightness). You can also go beyond 100, with values such as 150 to emphasize visual elements.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

In this code snippet, the brightness-75 utility reduces the brightness to 75%. Use any other Tailwind brightness utility to achieve a desired visual effect.

Disabling Brightness Filters

You might encounter scenarios where you want to completely remove the brightness filter applied to an element. Tailwind makes this easy with brightness-100, which resets the brightness to its default setting. You can also use filter-none to remove all filters at once.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Apply the brightness-100 utility when you need to completely remove brightness customizations.

States and Responsiveness

Tailwind lets you apply brightness utilities conditionally, whether for states like hover and focus, or across various screen sizes using responsive modifiers.

Hover and Focus States

The utility classes in Tailwind can work dynamically with pseudo-classes like hover or focus. This means you can alter brightness levels interactively.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

By assigning hover:brightness-125, the brightness increases when a user hovers over the image. The transition class adds a smooth animation.

Breakpoint Modifiers

Using Tailwind’s responsive design utilities, you can conditionally apply brightness adjustments for different screen sizes.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Responsive utilities like md:brightness-75 or lg:brightness-100 ensure you can adapt the brightness to the current viewport size.

Custom Brightness

Beyond the built-in utilities, Tailwind offers flexibility for defining or using custom brightness values.

Extending the Theme

Custom brightness values can be added to your Tailwind configuration file, enabling you to create project-specific designs.

Once defined, these custom values are available as classes (e.g., brightness-110).

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Using Arbitrary Values

If you want to avoid adding to the configuration file, leverage arbitrary values for brightness. By defining brightness as brightness-[value], you can avoid modifying Tailwind’s configuration for one-off cases.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Real World Examples

Product Showcase with Hover Brightness Effect

This component displays a grid of product cards that become brighter when hovered over, creating an engaging user experience for an e-commerce website.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

This component showcases team members with a dimming effect when not hovered, drawing attention to the selected member.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Featured Article Cards with Brightness Transition

This component displays featured articles with a brightness transition effect when interacting with the cards.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

This component creates a portfolio gallery with different brightness states for active and inactive items.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

This component creates an image gallery where brightness increases progressively on hover.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Customization Examples

Product Image Hover Effect with Custom Brightness

This example demonstrates how to create a product card with a custom brightness hover effect that makes the image pop when users interact with it.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Dynamic Weather Widget with Brightness Adjustment

This example shows how to create a weather widget that adjusts brightness based on the time of day using custom brightness values.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

This example creates an interactive image gallery with different brightness levels for active, hover, and disabled states.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Best Practices

Maintain Design Consistency

When working with brightness utilities in Tailwind CSS, you should aim to maintain a consistent design language across your application. Start by establishing a standardized set of brightness values through your Tailwind configuration file. For instance, you could define a consistent brightness scale that aligns with your branding or visual identity. Using these predefined values ensures uniformity, helping you avoid clashing visual styles.

Organize your project's components so elements with similar contexts use the same brightness utilities. For example, a hover effect for images in a product gallery should align with other hover-enabled elements. This way, the user interface feels predictable and cohesive. Mixing unrelated brightness values across pages can confuse users and dilute the quality of your design.

Lastly, consider implementing a design system or component library that leverages reusable classes for brightness and related properties. By creating reusable React components styled with Tailwind classes, you’ll promote visual and functional consistency without the risk of deviating from your chosen theme.

Leverage Utility Combinations

Combining brightness with additional Tailwind utilities unlocks the potential for more complex and visually appealing designs. Whether you're enhancing hover animations or layering multiple filters, thoughtful combinations make your components stand out. For example, combining brightness-110 with shadow-xl and hover:scale-105 can give images or cards a pristine, interactive look.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

By integrating responsive modifiers like sm: or lg:, you can scale brightness effects depending on the viewport. Layer utilities carefully to balance simplicity and functionality without overwhelming your codebase.

Accessibility Considerations

Enhance Readability and Navigability

Adjusting brightness can directly impact the readability of text and navigability of interface elements—essential for accessibility. Avoid overly dimmed imagery or backgrounds when layering text on top, as insufficient contrast degrades readability for all users, especially those with visual impairments.

Pair brightness classes with opacity utilities or Tailwind's bg-gradient-to classes to highlight foreground text without over-dimming the background. For lengthy or informational content, confirm that the brightness filter balances well with text color and size. Tools like browser contrast-checking extensions can help you determine appropriate ratios.

Interactive elements—such as call-to-action buttons—should leverage hover brightness utilities judiciously. Moderate increases in brightness (hover:brightness-110) signal interactivity without obstructing the flow of content navigation.

Focus on High Contrast

To achieve a high level of contrast, you’ll want to consider pairing darkened brightness values (brightness-50 or lower) with vibrant, high-contrast text or UI overlays. For low vision users, contrast levels defined above WCAG-compliant minimums enhance both usability and inclusion.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Respect high-contrast design principles by using color simulators during testing to assess content clarity for audiences requiring additional support.