How to add tailwind CSS colors and Fonts to your project
Sampson Ovuoba
Posted on October 10, 2021
Adding Tailwind CSS colors and fonts to your project is easy and only takes a few classes. Colors and fonts make our designs more appealing and give a better user experience.
We are going to look at common tailwind CSS colors and fonts you can add to your project and how to use the custom own without removing the original color
Table of content
⦁ Fonts and colors available in tailwind CSS
⦁ Making custom fonts
⦁ Making custom colors
⦁ Conclusion
Fonts and colors available in tailwind CSS
There are different default Tailwind CSS colors and fonts available but there are very limited. You can check out some of them in the Tailwind CSS docs.
Making custom fonts
There are three ways you can add fonts to your Tailwind CSS. We are going to look at the ways you can do this here.
Step 1: among the three ways we will explore how to add fonts to your Tailwind CSS project, the first step is always to load your web font into your <head >
tag of your page.
Code :
<link href="https://fonts.googleapis.com/css?family=Nunito:400,700&display=swap" rel="stylesheet">
or
<style>
@import url('https://fonts.googleapis.com/css?family=Nunito:400,700&display=swap');
</style>
Step 2: use the extend
functionality to add to the existing font utilities.
After installing Tailwind CSS in our project and configuring the postcss file, we can go ahead to generate a tailwind.config.js
file. We can add a theme.extend.fontfamily section to the tailwind.config.js file just as follows.
Code:
Tailwind.config.js file.
module.exports = {
theme: {
// Some useful comment
extend: {
fontFamily: {
'nunito': ['nunito', 'sans-serif']
},
},
},
variants: {
// Some useful comment
},
plugins: [
// Some useful comment
]
}
In the code above, you are simply extending the default configuration. These adds new font family to your already existing Tailwind CSS fonts utility classes.
To generate this file, you need to compile and build the styles by running the following command
Code:
npx tailwindcss build styles.css –o styles/tailwind.css
Code:
/* Generated by Tailwind CSS in your css file */
.font-sans {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
"Segoe UI Symbol", "Noto Color Emoji";
}
.font-serif {
font-family: Georgia, Cambria, "Times New Roman", Times, serif;
}
.font-mono {
font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.font-nunito {
font-family: nunito, sans-serif;
}
In order
/* In your tailwind.config.js */
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
// Some useful comment
fontFamily: {
'sans': ['nunito', ...defaultTheme.fontFamily.sans],
'serif': [...defaultTheme.fontFamily.serif],
'mono': [...defaultTheme.fontFamily.mono]
},
},
variants: {
// Some useful comment
},
plugins: [
// Some useful comment
]
}
In the file above, the generated CSS will not only have the new fonts included but will retain the default fonts too. You can now go ahead to include it on your project.
Making custom colors
To generate your own custom color, you must already have the Tailwind CSS installed on your project. You can check out how to do this in our post here.
Step 2. You generate a tailwind CSS configuration file by running the following code
Code:
npx tailwindcss init.
The code above allowed us to generate a file named tailwind.config.js file
Step 3. Configure your tailwind.config.js file
We can go ahead and customize our own color in our tailwind.config.js file
Code:
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
colors: {
primary: {
blue: 'hsl(237, 63%, 64%)',
'very-light': 'hsl(240,78%, 98%)',
light: 'hsl(234, 14%,74%)',
normal: 'hsl(23, 13%, 33%)',
dark: 'hsl(232,13%,33%)'
}
},
},
},
variants: {
extend: {},
},
plugins: [],
}
Step 4
After this, we can now proceed to compile and build the styles. This will generate a unique set of Tailwind CSS styles including our custom styles. we can do this by running the following command on the terminal.
Code:
npx tailwindcss build styles.css –o styles/tailwind.css.
next, we are going to build a color project to show our custom color.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>colors </title>
<link href="styles/styles.css" rel="stylesheet">
</head>
<body class="text-center ">
<div class="flex justify-center">
<img src="images/devwares-logo.png" alt="" class="w-24">
</div>
<b>Tailwind CSS Customize colors</b>
<div class="h-60 w-25 m-5 bg-primary-blue">
DEVWARES.
</div>
</body>
Our webpage should look like the image below
Conclusion
In our tailwind CSS tutorial, we learned how to customize tailwind CSS colors and fonts. We also used customized colors to build a project. I hope you enjoyed the tutorial.
Design and code tailwind css websites 3x faster
We created a tool to visually build tailwind css components, prototypes, websites, and webapps. Ship projects faster using an intuitive tailwind builder and editor.Try Windframe out for free.
Resources
Tailwind grid-How to use tailwind CSS grid templates in your project
How to create a Beautiful Responsive Navigation bar Using Tailwind CSS
Tailwind form-How to create and style a Responsive Form using Tailwind CSS
How to use tailwind CSS padding, margin and border in your project
How to create a beautiful React Bootstrap select with icons.
How to create a Beautiful Responsive Navigation bar Using Tailwind CSS
Tailwind Modal-How to create a React Modal using Tailwind CSS.
How to Implement a React Step Progress Bar Using Tailwind CSS
Posted on October 10, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.