Just-in-Time: The Next Generation of Tailwind CSS
Tailwind CSS on GitHub

Filter

Tailwind CSS version
v2.1+

Utilities for enabling and disabling filters on an element.

Default class reference

Class
Properties
filterfilter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
filter-nonefilter: none;

Usage

Use the filter utility to enable filters (in combination with other filter utilities like blur or grayscale), and the filter-none utility to remove filters.

<div class="filter grayscale blur-md contrast-200 ...">
  <!-- ... -->
</div>

Responsive

To control filters at a specific breakpoint, add a {screen}: prefix to any existing filter utility. For example, use md:filter-none to apply the filter-none utility at only medium screen sizes and above.

<div class="filter blur-lg md:filter-none ...">
  <!-- ... -->
</div>

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Customizing

Variants

默认情况下, 针对 filter 功能类,只生成 responsive 变体。

您可以通过修改您的 tailwind.config.js 文件中的 variants 部分中的 filter 属性来控制为 filter 功能生成哪些变体。

例如,这个配置将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       filter: ['hover', 'focus'],
      }
    }
  }

Disabling

如果您不打算在您的项目中使用 filter 功能,您可以通过在配置文件的 corePlugins 部分将 filter 属性设置为 false 来完全禁用它们:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     filter: false,
    }
  }