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
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
1const cormorant = Cormorant({
2 subsets: ["latin"],
3 weight: ["300", "400", "500", "600", "700"],
4 variable: "--font-cormorant",
5});
6
7const openSans = Open_Sans({
8 subsets: ["latin"],
9 weight: ["300", "400", "500", "600", "700"],
10 variable: "--font-open-sans",
11});
12
13export const metadata: Metadata = {
14 title: "Digital Garden - Mario Brusarosco",
15 description: "Digital Garden - Mario Brusarosco",