Grouping multiple classes into a single custom class
This is useful when you have a set of classes that you use together frequently and you wanna use Tailwind's breakpoints like md:something, lg:something-else, etc.
your-global-css-file.css
1@layer utilities {
2 .global-spacing {
3 @apply global-x-spacing global-y-spacing;
4 }
5
6 .global-y-spacing {
7 @apply py-4;
8 }
9
10 .global-x-spacing {
11 @apply px-4;
12 }
13}
Customizing
Colors
We can create a custom palette and use them as if they were made by Tailwind itself.
tailwind.config.ts
1const config: Config = {
2 content: [....],
3 theme: {
4 extend: {
5 colors: {
6 primary: "#dbd1d1",
7 secondary: "#dbd1d1",
8 }
9 }
10 },
11 },
12 },
13 plugins: [],
14};
If we wanna use CSS Variables
// TODO
Fonts
Add a font to the project
!If you're hosting the font:
your-global-css-file.css
1@tailwind base;
2@tailwind components;
3@tailwind utilities;
4
5@layer base {
6 @font-face {
7 font-family: "Roboto";
8 font-style: normal;
9 font-weight: 400;
10 font-display: swap;
11 src: url(/fonts/Roboto.woff2) format("woff2");
12 }
13}
If you're using from Google Fonts
If you're using Next JS
Add the font to layout.tsx file at the root level
Add the font to the tailwind.config.js file
1module.exports = {
2 theme: {
3 extend: {
4 fontFamily: {
5 serif: ["var(--font-cormorant)", "serif"],
6 sans: ["var(--font-open-sans)", "sans-serif"],
7 },
8 },
9 },
10};
Use the font in the project
Breakppoints
Changing Default breakpoints values, not their names