Tailwind CSS can be used to style websites in the fastest and easiest way.Tailwind CSS is basically a utility-first CSS framework for rapidly building custom user interfaces. It is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override
Why Tailwind CSS?
Faster UI building process
It is a utility-first CSS framework which means we can use utility classes to build custom
designs without writing CSS as in the traditional approach.
Advantages of Tailwind CSS:
No more silly names for CSS classes and Id’s.
Minimum lines of Code in CSS file.
We can customize the designs to make the components.
Makes the website responsive.
Makes the changes in the desired manner.
CSS is global in nature and if make changes in the file the property is changed in all the
HTML files linked to it. But with the help of Tailwind CSS we can use utility classes and
make local changes.
npm install -D tailwindcss
npx tailwindcss init
Add the paths to all of your template files(tailwind.config.js)
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
}
Add the Tailwind directives to your CSS(src/input.css
)
@tailwind base;
@tailwind components;
@tailwind utilities;
Start the Tailwind CLI build process
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
Start using Tailwind in your HTML (src/index.html)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/dist/output.css" rel="stylesheet">
</head>
<body>
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
</body>
</html>
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
Add Tailwind to your PostCSS configuration( postcss.config.js)
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}
Configure your template paths (tailwind.config.js
)
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
}
Add the Tailwind directives to your CSS (main.css)
@tailwind base;
@tailwind components;
@tailwind utilities;
Start your build process
npm run dev
Start using Tailwind in your HTML
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/dist/main.css" rel="stylesheet">
</head>
<body>
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
</body>
</html>
npx create-next-app@latest my-project --typescript --eslint
cd my-project
Install Tailwind CSS
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Configure your template paths (tailwind.config.js)
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx}",
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
// Or if using `src` directory:
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Add the Tailwind directives to your CSS (globals.css)
@tailwind base;
@tailwind components;
@tailwind utilities;
Start your build process
npm run dev
Start using Tailwind in your project (index.tsx
)
export default function Home() {
return (
<h1 className="text-3xl font-bold underline">
Hello world!
</h1>
)
}
<script src="https://cdn.tailwindcss.com"></script>
mx-auto
To add padding the container
px-{size}
| Breakpoint | min-width |
| sm | 640px |
| md | 768px |
| lg | 1024px |
| xl | 1280px |
| 2xl | 1536px |
box-border
In this mode, the width and height class include only the content.
box-content
<blockquote> </blockquote>
<q> </q>
<cite> </cite>
<bdo> </bdo>
<address> </address>
<code> </code>
The most widely used attribute is core attributes. There are 4 types of core attributes:
There are three types of internationalization attributes i.e. dir, lang, xml:lang
Generic attributes include various attributes which are mostly used. Some common generic
attributes are:
HTML Link uses two attributes
< href= "Your specified path" > </a>
HTML Comments
<!-- Single line Comment -->
<!--
This is a multiline comment.
You can add as many as lines you want.
-->
To represent HTML pages beautifully and to explain content, we use images for that. Our
ability to comprehend complex things is aided by visual representations to do that we use
images.
<img> tag uses the height or width
attribute to set the height or width of an image. Values for height or width attribute must
be in pixel or percentage and value should be placed in double quotes otherwise we can see
an error.
<img src="images/profile_pic" alt="Testing Image" />
Our day-to-day lives revolve around lists. For example, We purchase items while shopping. A
list of all our items is included on the bill we receive from the shopkeeper. Similarly, web
developers use lists to display the data.
HTML lists are used to display the data in an ordered and unordered form. List contains
one or more list elements. The HTML list is of three types:
<ul>
<li>Pen</li>
</ul>
<ol>
<li>Pen</li>
</ol>
<dl>
<dt>//definition term</dt>
<dd>//describing term</dd>
</dl>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Harry</td>
<td>100</td>
</tr>
</table>