A utility-first CSS framework for rapidly building custom designs
<button class="btn btn-primary">Primary</button>
<button class="btn btn-secondary">Secondary</button>
<button class="btn btn-success">Success</button>
The result: pre-styled buttons!
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
.card .card-body .card-title {
color: red !important;
}
Small pre-existing CSS classes to be used directly in your HTML.
.mobile-only to add display: none
<button class="text-white bg-blue-500 underline rounded-lg px-4 py-2">Primary</button>
Result:
<button style="
color: white;
background-color: #4299e1;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
">Primary</button>
<button class="
text-white
font-bold
uppercase
text-right
bg-green-500
underline
rounded-lg
w-full
px-4
py-2
animate-pulse
">Primary</button>
More to come!
<button class="text-white bg-blue-500 px-4 py-2 rounded-lg">Primary</button>
<button class="text-white bg-gray-500 px-4 py-2 rounded-lg">Secondary</button>
<button class="text-white bg-green-500 px-4 py-2 rounded-lg">Success</button>
<button class="text-white bg-red-500 px-4 py-2 rounded-lg">Danger</button>
<button class="text-gray-700 bg-yellow-500 px-4 py-2 rounded-lg">Warning</button>
<button class="text-white bg-teal-600 px-4 py-2 rounded-lg">Info</button>
<button class="text-gray-700 bg-gray-200 px-4 py-2 rounded-lg">Light</button>
<button class="text-white bg-gray-800 px-4 py-2 rounded-lg">Dark</button>
<button class="text-blue-700 bg-transparent px-4 py-2 rounded-lg">Link</button>
Example: you have the same button styling multiple times
<!-- some HTML-->
<button class="text-white bg-gray-500 px-4 py-2 rounded-lg">Secondary</button>
<!-- some more HTML-->
<button class="text-white bg-gray-500 px-4 py-2 rounded-lg">Secondary</button>
SecondaryButton.vue:
<template>
<button class="text-white bg-gray-500 px-4 py-2 rounded-lg"><slot /></button>
</template>
<script>
export default {
// your button functionality here
}
</script>
For example when you like .btn-secondary
<button class="text-white bg-gray-500 px-4 py-2 rounded-lg">Secondary</button>
<button class="btn-secondary">Secondary</button>
<style>
.btn-secondary {
@apply text-white bg-gray-500 px-4 py-2 rounded-lg;
}
</style>
<button class="text-white bg-blue-500 px-4 py-2 rounded-lg">Primary</button>
โช Utility classes = no hardcoded values, customisable!
<button style="
color: white;
background-color: #4299e1;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
">Primary</button>
โช What if we want a different shade of blue?
โช A different padding?
โช A different border-radius?
tailwind.css + configuration file
โฌ via TailwindCLI โฌ
custom.css
npx tailwindcss build tailwind.css -o custom.css
const { colors } = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
extend: {
colors: {
blue: {
...colors.blue,
'500': '#1e3656',
}
}
}
}
}
With .bg-blue-500 utility: vs.
4 breakpoints defined:
Prefix your utilities with sm:, md:, lg:, xl:
<button class="
text-blue-500
md:text-white
bg-white
md:bg-blue-500
lg:bg-purple-500
md:underline
lg:no-underline
lg:uppercase
rounded-lg
px-4 py-2
">Primary</button>
Try it out with the CDN:
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
npx tailwindcss build tailwind.css -o custom.css
Still sceptical? https://adamwathan.me/css-utility-classes-and-separation-of-concerns/
More info: https://tailwindcss.com/
Good luck sailor with TailwindCSS!