Back to Tailwindcss

Filter Brightness

src/docs/filter-brightness.mdx

latest4.4 KB
Original Source

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

export const title = "filter: brightness()"; export const description = "Utilities for applying brightness filters to an element.";

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

Examples

Basic example

Use utilities like brightness-50 and brightness-100 to control an element's brightness:

<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"> brightness-50 </p> <div className="relative brightness-50">
          <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">
          brightness-100
        </p>
        <div className="relative brightness-100">
          
          <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">
          brightness-125
        </p>
        <div className="relative brightness-125">
          
          <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">
          brightness-200
        </p>
        <div className="relative brightness-200">
          
          <div className="absolute inset-0 rounded-lg ring-1 ring-black/10 ring-inset"></div>
        </div>
      </div>
    </div>
  </div>
</Example>

}

</Figure>
html
<!-- [!code classes:brightness-50,brightness-100,brightness-125,brightness-200] -->




Using a custom value

<UsingACustomValue element="img" elementAttributes={{ src: "/img/mountains.jpg" }} utility="brightness" value="1.75" />

Responsive design

<ResponsiveDesign element="img" elementAttributes={{ src: "/img/mountains.jpg" }} property="filter: brightness()" defaultClass="brightness-110" featuredClass="brightness-150" />