Table of contents
Background
Tailwind CSS provides a wide variety of background utility classes that can be used to set the background color, image, and other properties of an element. Here are some of the most commonly used background classes in Tailwind:
bg-{color}
: Sets the background color of an element. Replace{color}
with a color name or hexadecimal value, for examplebg-red-500
orbg-gray-200
.bg-opacity-{value}
: Sets the opacity of the background color. Replace{value}
with a number from 0 to 100, for examplebg-opacity-50
.bg-gradient-{direction}-{color1}-{color2}
: Sets a gradient background on an element. Replace{direction}
with the gradient direction (to-{direction}
), for exampleto-b
for a bottom-to-top gradient. Replace{color1}
and{color2}
with the gradient colors, for examplefrom-red-500
andto-yellow-500
.bg-fixed
: Sets the background image as fixed to the viewport so that it doesn't scroll with the rest of the content.bg-cover
: Sets the background image to cover the entire element, without stretching or distorting the image.bg-contain
: Sets the background image to be contained within the element, so that the entire image is visible without cropping or stretching.bg-repeat-{option}
: Sets how the background image should repeat if it doesn't cover the entire element. Replace{option}
withrepeat
to repeat the image in both directions,repeat-x
to repeat the image only horizontally, orrepeat-y
to repeat the image only vertically.bg-gradient-to-{direction}
: Sets a gradient background on an element that fades from one color to another in a specified direction. Replace{direction}
witht
for top,b
for bottom,l
for left, orr
for right.bg-blur-{value}
: Applies a blur effect to the element's background. Replace{value}
with the blur value, for examplebg-blur-sm
.
These are just a few examples of the background classes available in Tailwind CSS. You can find the full list of background utility classes in the official Tailwind CSS documentation.