Backgrounds

Background Clip

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

Quick 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;

Basic usage

Setting the background clip

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-6 bg-violet-600 border-4 border-violet-300 border-dashed"></div>
  2. <div class="bg-clip-padding p-6 bg-violet-600 border-4 border-violet-300 border-dashed"></div>
  3. <div class="bg-clip-content p-6 bg-violet-600 border-4 border-violet-300 border-dashed"></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-5xl font-extrabold ...">
  2. <span class="bg-clip-text text-transparent bg-gradient-to-r from-pink-500 to-violet-500">
  3. Hello world
  4. </span>
  5. </div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:bg-clip-padding to only apply the bg-clip-padding utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:bg-clip-padding to apply the bg-clip-padding utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.