Background Clip

Tailwind CSS version

v1.7.0+

Utilities for controlling the bounding box of an element’s background.

Class reference

Class
Properties
.bg-clip-borderbackground-clip: border-box;
.bg-clip-paddingbackground-clip: padding-box;
.bg-clip-contentbackground-clip: content-box;
.bg-clip-textbackground-clip: text;

Usage

Use the bg-clip-{keyword} utilities to control the bounding box of an element’s background.

Background Clip - 图1

  1. <div class="bg-clip-border p-4 border-4 border-dashed border-purple-800 bg-purple-500"></div>
  2. <div class="bg-clip-padding p-4 border-4 border-dashed border-purple-800 bg-purple-500"></div>
  3. <div class="bg-clip-content p-4 border-4 border-dashed border-purple-800 bg-purple-500"></div>

Cropping to text

Use bg-clip-text to crop an element’s background to match the shape of the text. Useful for effects where you want a background image to be visible through the text.

Background Clip - 图2

  1. <div class="text-center text-5xl font-extrabold leading-none tracking-tight">
  2. <span class="bg-clip-text text-transparent bg-gradient-to-r from-teal-400 to-blue-500">
  3. Hello world
  4. </span>
  5. </div>

Responsive

To control the bounding box of an element’s background at a specific breakpoint, add a {screen}: prefix to any existing background clip utility. For example, adding the class md:bg-clip-padding to an element would apply the bg-clip-padding utility at medium screen sizes and above.

  1. <div class="bg-clip-padding md:bg-clip-border">
  2. <!-- ... -->
  3. </div>

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

Customizing

Responsive and pseudo-class variants

By default, only responsive variants are generated for background clip utilities.

You can control which variants are generated for the background clip utilities by modifying the backgroundClip property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - backgroundClip: ['responsive'],
  6. + backgroundClip: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

If you don’t plan to use the background clip utilities in your project, you can disable them entirely by setting the backgroundClip property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + backgroundClip: false,
  6. }
  7. }

← Background Attachment   Background Color →