Tailwind CSS Background Repeat
The bg-{repeat} utility class in Tailwind CSS allows you to control the repetition behavior of background images applied to elements. With Tailwind background repeat class, you can easily adjust how background images are repeated to achieve the desired visual effect.
Tailwind Background Repeat
The bg-{repeat}
utility class in Tailwind CSS allows you to control the repetition behavior of background images applied to elements. With Tailwind background repeat class, you can easily adjust how background images are repeated to achieve the desired visual effect.
How to apply Tailwind Background Repeat
To apply a specific tailwind background repeat behavior to an element, you can use the bg-{repeat}
utility class, where {repeat}
represents the desired background repeat behavior. Here are some common values you can use:
bg-repeat
: The background image is repeated both horizontally and vertically.bg-no-repeat
: The background image is not repeated, appearing only once.bg-repeat-x
: The background image is repeated horizontally but not vertically.bg-repeat-y
: The background image is repeated vertically but not horizontally.
<div class="w-full bg-repeat bg-[url('https://images.unsplash.com/photo-1623697899813-cf12fa9bc1c3?q=80&w=553&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]"></div>
Preview
Example bg-no-repeat
<div class="p-4"> <div class="bg-no-repeat w-full h-80 bg-center rounded-md bg-[url('https://images.unsplash.com/photo-1623697899813-cf12fa9bc1c3?q=80&w=553&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]" ></div></div>
Preview
Use bg-no-repeat when you want the image to appear only once, like a logo or icon
Example bg-repeat-x
<div class="p-4"> <div class="bg-repeat-x w-full h-80 bg-center rounded-md bg-[url('https://images.unsplash.com/photo-1623697899813-cf12fa9bc1c3?q=80&w=553&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]" ></div></div>
Preview
Example bg-repeat-y
<div class="p-4"> <div class="bg-repeat-y w-full h-300 bg-center rounded-md bg-[url('https://images.unsplash.com/photo-1623697899813-cf12fa9bc1c3?q=80&w=553&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]" ></div></div>
Preview
Responsive Tailwind Background Repeat
Tailwind CSS allows you to apply background repeat classes responsively at different breakpoints. To use responsive tailwind background repeat classes, you can append the breakpoint prefix to the utility class. For example, md:bg-no-repeat
sets the background to not repeat starting from the medium breakpoint and above.
<div class="p-4"> <div class="bg-repeat md:bg-no-repeat w-full h-100 bg-center rounded-md bg-[url('https://images.unsplash.com/photo-1623697899813-cf12fa9bc1c3?q=80&w=553&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')]" ></div></div>
Preview
In the above example, the tailwind background repeat behavior of the <div>
element is set to not repeat by default (bg-no-repeat)
, but starting from the medium breakpoint and above, it changes to repeat both horizontally and vertically (md:bg-repeat)
.
Tailwind Background Repeat Class Table
Class | Properties |
---|---|
bg-repeat | background-repeat: repeat; |
bg-no-repeat | background-repeat: no-repeat; |
bg-repeat-x | background-repeat: repeat-x; |
bg-repeat-y | background-repeat: repeat-y; |
bg-repeat-round | background-repeat: round; |
bg-repeat-space | background-repeat: space; |
✨ What's Next?
Now that you’ve mastered Tailwind Background Repeat, try experimenting with:
Windframe Tailwind blocks
Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs
Start building stunning tailwind UIs!
