Back to Tailwindcss

Backdrop Filter

src/docs/backdrop-filter.mdx

latest4.7 KB
Original Source

import { ApiTable } from "@/components/api-table.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { ResponsiveDesign, TargetingSpecificStates, UsingACustomValue } from "@/components/content.tsx";

export const title = "backdrop-filter"; export const description = "Utilities for applying backdrop filters to an element.";

<ApiTable rows={[ ["backdrop-filter-none", "backdrop-filter: none;"], ["backdrop-filter-(<custom-property>)", "backdrop-filter: var(<custom-property>);"], ["backdrop-filter-[<value>]", "backdrop-filter: <value>;"], ]} />

Examples

Basic example

Use utilities like backdrop-blur-xs and backdrop-grayscale to apply filters to an element's backdrop:

<Figure> <Example padding={false}> { <div className="flex scroll-p-8 justify-start overflow-scroll sm:block sm:overflow-visible"> <div className="flex shrink-0 items-center justify-around gap-6 p-8 font-mono font-bold sm:gap-4"> <div className="flex shrink-0 flex-col items-center"> <p className="mb-3 text-center font-mono text-xs font-medium text-gray-500 dark:text-gray-400"> backdrop-blur-xs </p> <div className="relative"> <div className="absolute inset-6 size-20 bg-white/30 backdrop-blur-xs"></div>
        <div className="absolute inset-0 rounded-lg ring-1 ring-black/10 ring-inset"></div>
      </div>
    </div>
    <div className="flex shrink-0 flex-col items-center">
      <p className="mb-3 text-center font-mono text-xs font-medium text-gray-500 dark:text-gray-400">
        backdrop-grayscale
      </p>
      <div className="relative">
        <div className="absolute inset-6 size-20 bg-white/30 backdrop-grayscale"></div>
        
        <div className="absolute inset-0 rounded-lg ring-1 ring-black/10 ring-inset"></div>
      </div>
    </div>
    <div className="flex shrink-0 flex-col items-center">
      <p className="mb-3 text-center font-mono text-xs font-medium text-gray-500 italic dark:text-gray-400">
        combined
      </p>
      <div className="relative">
        <div className="absolute inset-6 size-20 bg-white/30 backdrop-blur-xs backdrop-grayscale"></div>
        
        <div className="absolute inset-0 rounded-lg ring-1 ring-black/10 ring-inset"></div>
      </div>
    </div>
  </div>
</div>

} </Example>

html
<!-- [!code classes:backdrop-blur-xs,backdrop-grayscale] -->
<div class="bg-[url(/img/mountains.jpg)] ...">
  <div class="backdrop-blur-xs ..."></div>
</div>
<div class="bg-[url(/img/mountains.jpg)] ...">
  <div class="backdrop-grayscale ..."></div>
</div>
<div class="bg-[url(/img/mountains.jpg)] ...">
  <div class="backdrop-blur-xs backdrop-grayscale ..."></div>
</div>
</Figure>

You can combine the following backdrop filter utilities: blur, brightness, contrast, grayscale, hue-rotate, invert, opacity, saturate, and sepia.

Removing filters

Use the backdrop-filter-none utility to remove all of the backdrop filters applied to an element:

html
<!-- [!code classes:md:backdrop-filter-none] -->
<div class="backdrop-blur-md backdrop-brightness-150 md:backdrop-filter-none"></div>

Using a custom value

<UsingACustomValue utility="backdrop-filter" value="url('filters.svg#filter-id')" name="backdrop filter" />

Applying on hover

<TargetingSpecificStates property="backdrop-filter" defaultClass="backdrop-blur-sm" featuredClass="backdrop-filter-none" />

Responsive design

<ResponsiveDesign property="backdrop-filter" defaultClass="backdrop-blur-sm" featuredClass="backdrop-filter-none" />