Tailwind CSS Configuration
A guide to configuring and customizing your Tailwind installation.
Because Tailwind is a framework for building bespoke user interfaces, it has been designed from the ground up with customization in mind.
By default, Tailwind will look for an optional tailwind.config.js file at the root of your project where you can define any customizations.
Syntax
To configure and customize Tailwind CSS, you can create a tailwind.config.js
file in your project's root directory.
Example syntax:
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
Examples
Adding Custom Colors
module.exports = {
theme: {
extend: {
colors: {
primary: "#123456",
secondary: "#789abc"
}
}
}
};
Modifying Font Size
module.exports = {
theme: {
extend: {
fontSize: {
'7xl': '6rem',
},
},
},
};
Changing Default Breakpoints
module.exports = {
theme: {
screens: {
'sm': '640px',
'md': '768px',
'lg': '1024px',
'xl': '1280px',
'2xl': '1536px',
}
},
};
Output
After modifying the Tailwind CSS configuration, you'll need to run the build command npm run build
or yarn build
to generate a new CSS file.
Explanation
The tailwind.config.js
file contains various configuration options such as theme, variants, plugins, and purge.
purge
option is used for removing unused CSS from the final production build.darkMode
option is used for enabling dark mode.theme
option allows you to customize Tailwind CSS, modify existing values or add your own custom values.variants
option allows you to create new variants for existing utilities.plugins
option is used to add third-party plugins to your Tailwind CSS installation.
Use
You can use Tailwind CSS configuration to customize the default utility classes, add new utility classes, and remove unused classes to reduce the final CSS size.
By modifying the Tailwind CSS configuration, you can create a unique and custom design system for your web application.
Important Points
- Always use the default classes and modify them using the configuration options to ensure consistency.
- Minimize the CSS file size by removing unused classes using the
purge
option. - Use the
!important
modifier sparingly, and only when necessary.
Summary
In summary, Tailwind CSS configuration allows you to customize your design system and create unique designs without writing any CSS code. Modify the tailwind.config.js
file to add custom colors, adjust font sizes, modify breakpoints, and more. Use the configuration file to create a consistent design system and reduce the final CSS file size.