How to setup Tailwind CSS in AngularJS ?
Last Updated :
06 Sep, 2022
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:
- Open CMD (Window) or Terminal (Linux) and write the command.
ng new project-name
- After running the above command, it asks some questions as shown below, related to CSS which is basically the CSS type you want to use in your angular project. Let’s select CSS for this project.
- It also asks for routing let enables it by saying yes.
Let them finish the above process.
- Once the process is completed, there is a project folder. Get into the folder using the change directory command of CMD or Terminal and run the following command.
ng serve --open
- It will open the default page of angular in the browser.
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
- Using PostCSS and command line configuration
Using CDN:
- Open the project in your favorite Code Editor.
- Browse the index.html of the angular project.
- Just paste the below line in the head section.
<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.
HTML
<!DOCTYPE html>
< html >
< head >
< title >Tailwind-AngularJS Example</ title >
< meta charset = "UTF-8" />
< meta name = "viewport" content =
"width=device-width, initial-scale=1.0" />
</ 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:
- Open the project directory in the cmd or terminal and run the following command.
npm install tailwindcss postcss autoprefixer
- The above command install requires a library for a tailwind to run. Let’s config the tailwind CSS and postcss. For that, we can create a file with the names tailwind.config.js and postcss.config.js in the project file.
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 tailwind CSS is ready to use in your Angular project and it is successfully set up in the project.
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.
app.component.html
< 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 >
|
app.component.ts
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
styleUrls: [ './app.component.scss' ]
})
export class AppComponent{}
|
app.module.ts
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/
Similar Reads
How to Add New Colors in Tailwind CSS ?
Tailwind CSS is a popular utility-first CSS framework that offers a wide range of pre-designed styles and classes to simplify the process of styling web applications. However, the default set of colors provided by Tailwind may not always meet the requirements of your project. In such cases, you may
4 min read
How to Skew a Button in Tailwind CSS?
Skewed buttons can add a dynamic and modern look to your website, Tailwind CSS provides utility classes to easily apply 2D transformations like tilt, rotation, and scaling, we'll explain how to tilt, buttons using Tailwind CSS and create a simple project to demonstrate this. Approach To Skew A Butto
2 min read
How to change svg icon colors with Tailwind CSS ?
SVG stands for Scalable Vector Graphics and is an XML-based ( can be edited ) vector image format. SVG is commonly used for icons, animations, interactive charts, graphs, and other dynamic graphics in the browser. As it is XML-based, you can easily edit or change the SVG icon colors with Tailwind. A
3 min read
How to use calc() in Tailwind CSS?
The calc() function in CSS allows you to perform calculations for property values dynamically. While Tailwind CSS doesnât directly support calc(), you can use it inline or with custom utilities. 1. Using Inline StylesYou can use calc() directly within the style attribute for dynamic property values.
2 min read
How to Style Checkboxes in Tailwind CSS ?
In Tailwind CSS, you can style checkboxes using utility classes to customize their appearance. You can use utility classes like appearance-none to remove the default browser styles from checkboxes. ApproachBegin with the basic HTML structure, including the <!DOCTYPE html> declaration, <html
3 min read
How to Set Text Color in RGBA in Tailwind CSS ?
In this article, we will change the color of text to rgba(0, 0, 0, 0.54) which is an RGB color format with an added parameter alpha that tells the opacity of the color. In this article, we are going to learn how we can achieve the text color of rgba(0, 0, 0, 0.54) in Tailwind CSS and hence, change t
3 min read
How to Style Lists in Tailwind CSS ?
Styling lists in Tailwind CSS enhances the visual appeal and usability of web pages by making lists more attractive and easier to navigate. By customizing the appearance of lists, you can improve the overall user experience on your website. These are the following approaches to Style the list in Tai
4 min read
How to make a Split Navigation Bar in Tailwind CSS ?
Split Navigation Bars in Tailwind CSS implement the different classes that help to distribute the content across the header of a webpage, providing a visually balanced layout. By separating navigation items into distinct sections, it becomes easier for users to identify and access different parts of
3 min read
How to Add Text Shadow in Tailwind CSS?
Adding a text shadow in Tailwind CSS is useful for making text for creating visual effects like glows and embossed or debossed effects. Tailwind CSS does not provide text shadow utilities out of the box but it allows you to easily extend its functionality to add custom utilities. In this article, we
3 min read
How to Control the Background Size in Tailwind CSS ?
To control background-size in Tailwind CSS, use the bg-{size} utility classes. These classes allow you to adjust the background size, providing options like bg-cover for covering the entire element, bg-contain for fitting the content within, and custom sizes such as bg-auto or bg-50%. Tailwind simpl
2 min read