Tailwind CSS v3.0 is here โ bringing incredible performance gains, huge workflow improvements, and a seriously ridiculous number of new features>
Today we will have a look at how we can set up TAILWIND CSS
and start writing css inside HTML
instead of writing it in a separate CSS
file.
Tailwind CSS works by scanning all of your HTML files, JavaScript components, and any other templates for class names, generating the corresponding styles, and then writing them to a static CSS file. It's fast, flexible, and reliable โ with zero runtime.
tailwind cli
- to install tailwind with help of cli you need to have node js installed in your local system. you can download it from nodejs.org/en/download/
- after downloading node js you can start with
tailwind
setup - to download
tailwind
we need to run the commandnpm install -D tailwindcss
- now let's create a folder
tailwind-cli-setup
using the commandmkdir tailwind-cli-setup
- let's go into the folder using
cd tailwind-cli-setup
- now we need to set up the
tailwind.config.js
file in this folder - for setting up
tailwind.config.js
run commandnpx tailwindcss init
- this will create a file named
tailwind.config.js
in the root directory
module.exports = {
content: [""],
theme: {
extend: {},
},
plugins: [],
}
- now we will add the path to our files in
content
- as of now we will put a
./index.html
in content which is the path to ourhtml
file - you can also include
*
incontent
if you want to target all the files but make surenode_modules
don't get scanned - you can check more about this on content-configuration
- this is how our
tailwind.config.js
looks
module.exports = {
content: ["./index.html"],
theme: {
extend: {},
},
plugins: [],
}
- let's create an
input.css
file which will be our maincss
file - in this file, we need to add
tailwind directives
@tailwind base;
@tailwind components;
@tailwind utilities;
- now we will run a command which will build an
output.css
file for us - run
npx tailwindcss -i ./input.css -o ./output.css --watch
- now we need to link
output.css
inindex.html
<link rel="stylesheet" href="./output.css">
- let's try adding
tailwind
classes now !!
<body >
<p class="text-center text-6xl font-bold text-cyan-700 m-4">Styled using TAILWIND</p>
</body>
- and this is what our page looks like !!
- you can also refer to
tailwind
docs for installation !!
Thanks for reading !!
ย