How to apply background image from Unsplash with Tailwind CSS
Malik
Posted on March 10, 2022
Install via your favorite package Manager:
NPM
npm install -D tailwindcss-unsplash
Yarn
yarn add -D tailwindcss-unsplash
PNPM
pnpm add -D tailwindcss-unsplash
Register the plugin into the Tailwind CSS config file
plugins: [require('tailwindcss-unsplash')],
Add unsplashImages utility by register a name and the unsplash ID
unsplashImages: {
apple: 'wAygsCk20h8',
stars: '4dpAqfTbvKA',
yourName: 'sF4RV2lDtW0',
},
eg: apple: 'wAygsCk20h8'
Add unsplashResolutions utility to set resolution parameter
unsplashResolutions: {
default: null,
xs: 480,
sm: 720,
md: 1280,
lg: 1920,
xl: 3840,
'2xl': 7680,
},
And finally add the css class to your HTML tag
<div class="bg-unsplash-[juJQdVYml78] w-96 h-96" />
<div class="bg-unsplash-[YMi66afAE3I/lg]" />
<div class="bg-unsplash-[YMi66afAE3I/1920]" />
The plugin generates the following utilities
🔗 Sources
GitHub Repo
https://github.com/shorwood/tailwindcss-unsplash…
Unsplash
https://unsplash.com
Code Screenshot made with http://kod.so
Example Project on Tailwind CSS Play
https://play.tailwindcss.com/i0kWe5MaWs?file=config
💖 💪 🙅 🚩
Malik
Posted on March 10, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.