Open In App

How to setup Tailwind CSS in AngularJS ?

In this article, we will see how to set up the Tailwind CSS in AngularJS & will understand the different ways for implementation through the examples.

Tailwind CSS is a utility-first CSS framework for rapidly building custom user interfaces. It is a cool way to write inline styling and achieve an awesome interface without writing a single line of your own CSS.



Angular is a platform and framework for building single-page client applications using HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your applications.

So, let’s start with creating a new angular project and setting up Tailwind CSS in the angular project.



Setting up new Angular Project:

ng new project-name

Let them finish the above process.

ng serve --open

Angular setup is done & let’s move to install the Tailwind CSS in the angular.

Installing Tailwind CSS in the Angular Project: There are 2 ways to add tailwind CSS in the Angular Project.

Using CDN:

<script src="https://cdn.tailwindcss.com"></script>

It will include all the libraries of the tailwind in the project using the internet. It is an easy way to include the tailwind.

Note: It requires internet. If the internet is not available then it will not work.

Example 1: This example describes the basic implementation of the Tailwind CSS in AngularJS by using the CDN link.




<!DOCTYPE html>
<html>
  
<head>
    <title>Tailwind-AngularJS Example</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0" />
    <script src="https://cdn.tailwindcss.com"></script>
</head>
  
<body>
    <div class="font-sans text-center">
        <h1 class="text-green-800 text-5xl p-7">
            GeeksforGeeks
        </h1>
        <p class="text-indigo-700 text-3xl">
            A Computer Science Portal for Geeks
        </p>
  
    </div>
</body>
  
</html>

Output:

 

Using PostCSS:

npm install tailwindcss postcss autoprefixer

tailwind.config.js:

module.exports = {
    purge: [],
    darkMode: false, // or 'media' or 'class'
    theme: {
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [],
}

postcss.config.js:

module.exports = {
    plugins: {
        tailwindcss: {},
        autoprefixer: {},
    },
};

Now you can use tailwind inline CSS and make more hands dirty you can refer to the tailwind website.

Example 2: This example describes the basic implementation of the Tailwind CSS in AngularJS by installing the tailwind CSS using npm.




<div class="font-serif text-center">
    <h1 class="text-green-800 text-5xl p-7">
        GeeksforGeeks
    </h1>
    <p class="text-indigo-700 text-3xl">
        A Computer Science Portal for Geeks
    </p>
  
</div>




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent{}




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
  
import { AppComponent } from './app.component';
  
@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule{}

Output:

 

Reference: https://tailwindcss.com/ 


Article Tags :