Add Tailwind CSS to Angular 14 apps

In this post, we will demonstrate how you can integrate Tailwind CSS into your Angular 14 application by providing you with step-by-step instructions.
Tailwind CSS is a utility-first CSS framework that makes it simple to develop attractive design systems. Tailwind's focus is on code readability and maintainability. It is predicated on the concept that you may achieve practically any goal using CSS by adding a large number of utility classes directly in your HTML document. On the other hand, Angular is a platform that enables developers to develop high-end enterprise applications. When Angular and Tailwind CSS are combined, you have the ideal stack for developing high-quality web applications.
Open a new command-line interface and run the following command:
ng new tailwinddemo --routing --style=css
We choose CSS since we don't need a preprocessor for using Tailwind CSS. Next, navigate inside your project's folder and run the following commands to install the required dependencies:
npm install postcss --save-dev
npm install tailwindcss
Next, we need to generate the tailwind.config.js
file, which includes your customized Tailwind CSS setup where you'll be able to make adjustments to your design system and configure Tailwind plugins. Simply run the following command:
npx tailwind init
When you actually need Tailwind utility classes in your code, they will be automatically produced for you on request. Therefore, you will need to instruct Tailwind where inside your project to look for the aforementioned utilities. Open the tailwind.config.js
file open, and replace the existing content with the following:
module.exports = {
content: ['./src/**/*.{html,ts}', './projects/**/*.{html,ts}'],
theme: {
extend: {},
},
plugins: [],
};
The settings above informs Tailwind CSS that the HTML and TypeScript files that it needs to consider can be found within the src/
and projects/
directories:
After that, open the src/style.css
file and add the following content:
@tailwind base;
@tailwind components;
@tailwind utilities;
The @tailwind
directives will be processed by Tailwind, which will then inject its base, components, and utilities' classes.
That's all, you can now start using Tailwind classes to style your Angular 14 application!
- Author: Ahmed Bouchefra Follow @ahmedbouchefra
-
Date:
Related posts
How to send authorization header in Angular 14 Angular 14 Tutorial By Example: REST API & HttpClient GET Angular 14 route title and custom strategy Angular 14 inject example: reactive decorator Angular 14 inject How to enable CORS in Angular 14 Angular v14 tutorial Add Tailwind CSS to Angular 14 apps Import standalone components in Angular 14 Generate standalone components in Angular 14 Add Bootstrap to Angular 14 example Upgrade to Angular 14 Angular 14 standalone component Angular CLI 14 Render HTML with Angular and innerHtmlHands-on Angular eBook
Subscribe to our Angular newsletter and get our hands-on Angular book for free!
