{"id":12102,"date":"2022-05-16T06:19:09","date_gmt":"2022-05-16T06:19:09","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=12102"},"modified":"2024-06-25T11:00:43","modified_gmt":"2024-06-25T11:00:43","slug":"introduction-to-tailwind-css-framework","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/introduction-to-tailwind-css-framework","title":{"rendered":"Introduction to Tailwind CSS Framework"},"content":{"rendered":"<table border=\"3\">\n<tbody>\n<tr>\n<td>\n<h3><span style=\"color: #000080;\"><strong>TABLE OF CONTENT<\/strong><\/span><\/h3>\n<\/td>\n<\/tr>\n<tr>\n<td><a href=\"#introduction\">1. Introduction to Tailwind CSS<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#stepbystepguide\">2. Step by Step Guide to Tailwind CSS Installation<br \/>\n<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#components\">3. Components with Tailwind CSS Button<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#youtubecard \">4. Build a YouTube card component with Tailwind CSS<br \/>\n<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#howdoescsswork\">5. How does CSS work?<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#advantages\">6. Advantages of using Tailwind CSS<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#conclusion\">7. Conclusion <\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#aboutcloudthat\">8. About CloudThat <\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#faqs\">9. FAQs<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"introduction\">1. Introduction to Tailwind CSS<\/h2>\n<p>Tailwind CSS is the most popular utility-first CSS framework for rapidly building custom user interfaces for the web. It is a highly customizable collection of low-level CSS utility classes written in PostCSS destined to be customized using JavaScript.<\/p>\n<p>The first release of Tailwind CSS happened on the 1st of November 2017 on GitHub as an open-source project. Initially, only a side project for Adam Wathan helped him with some of his projects. Still, it became a fully-fledged and popular CSS framework with a new utility-first methodology.<\/p>\n<h2 id=\"stepbystepguide\">2. Step by Step Guide to Tailwind CSS Installation<\/h2>\n<p><strong><u>Step 1:<\/u> Create a new project folder and go inside your directory by using the following command:<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">$ mkdir tailwind-sample-01<\/pre>\n<p><strong><u>Step 2:<\/u> Initialize a new project that will create a new package.json file by writing the following command:<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">$ npm init -y<\/pre>\n<p><strong><u>Step 3:<\/u> The first dependency which needs to be added to the project is the Tailwind CSS package. The following command is used for installation:<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true\">$ npm install tailwindcss<\/pre>\n<p>or<\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">$ yarn add tailwindcss<\/pre>\n<p><strong><u>Step 4:<\/u> The next step is to add Tailwind to the project&#8217;s CSS. Create a new file css\/styles.css and insert the @tailwind directive.<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \"> @tailwind base;\r\n@tailwind components;\r\n@tailwind utilities; \r\n<\/pre>\n<p><strong><u>Step 5:<\/u> Next step is to add a Tailwind configuration file by running the following command. The generated file will be present in your root directory (tailwindcss.config.js)<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">module.exports = {\r\n    theme: {\r\n       extend: {},\r\n    },\r\n\r\nvariants: {},\r\n     plugins: [],\r\n  }<\/pre>\n<p><strong><u>Step 6:<\/u><\/strong><strong> Tailwind CSS requires a build process that processes CSS files and makes sure that the Tailwind CSS code is inserted according to the directives used and the Tailwind configuration in place.<br \/>\n<\/strong><strong>In addition, we will also use a plugin which is called autoprefixer<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">$ npm install postcss-cli autoprefixer<\/pre>\n<p><strong><u>Step 7:<\/u><\/strong> <strong>With those packages installed let&#8217;s create a PostCSS configuration file in the project directory<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true \">touch postcss.config.js<\/pre>\n<p><strong><u>Step 8:<\/u><\/strong> <strong>Inside this file, we have to add the following code<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true\">module.exports = {\r\nplugins: [\r\nrequire('tailwindcss'),\r\nrequire('autoprefixer'),\r\n]\r\n}<\/pre>\n<p><strong><u>Step 9:<\/u> Finally, the last step is to add a script inside our package.json file<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true\">\"build\": \"postcss css\/styles.css -o build\/styles.css\"<\/pre>\n<p><strong><u>Step 10:<\/u><\/strong> <strong>To run this script inside your ide terminal run<\/strong><\/p>\n<pre class=\"theme:dark-terminal nums:false nums-toggle:false lang:default decode:true\">npm run build<\/pre>\n<p><strong>This script will ensure that whatever tailwind classes we are using, we are converting them into original CSS. So, now, inside our build folder, just create an index.html file and link our styles.css file with that. So, whenever we make any changes, those changes are reflected in the user.<\/strong><\/p>\n<p><strong>Finally, install a live server extension from the extension bar of your preferred<br \/>\nFinally, our project will start running on some ports using the live server application<\/strong><\/p>\n<h2 id=\"components\">3. Components with Tailwind CSS Button<\/h2>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12104\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css2.png\" alt=\"Tailwind CSS\" width=\"687\" height=\"468\" \/><\/a><\/p>\n<h2><strong>4. Build a YouTube card component with Tailwind CSS<\/strong><\/h2>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12105\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css3.png\" alt=\"Tailwind CSS\" width=\"580\" height=\"573\" \/><\/a><\/p>\n<h2 id=\"howdoescsswork\"><strong>5. How does CSS work?<\/strong><\/h2>\n<p>When a browser displays a document, it must combine its content with its style information. It processes the paper in two phases:<\/p>\n<ul>\n<li>The browser converts\u00a0HTML\u00a0and\u00a0CSS\u00a0into the\u00a0DOM<em> (<\/em>Document Object Model<em>)<\/em>. The DOM represents the document in the computer&#8217;s memory. It combines the document&#8217;s content with its style.<\/li>\n<\/ul>\n<p>The browser displays the contents of the DOM.<\/p>\n<h2 id=\"advantages\"><strong>6. Advantages of using Tailwind CSS<\/strong><\/h2>\n<ol>\n<li><strong>It is highly customizable:\u00a0<\/strong>Tailwind CSS is a highly customizable framework. Although it comes with a default configuration, overriding it with a\u00a0tailwind.config.js\u00a0file is simple.<\/li>\n<li><strong>It can be optimized using PurgeCSS:\u00a0<\/strong>A significant advantage of Tailwind CSS is that optimization can be performed using PurgeCSS. PurgeCSS can reduce the file size considerably by scanning the HTML and removing unused classes. It is easy to set up PurgeCSS combined with Tailwind CSS and is highly recommended to do so before deploying the site.<\/li>\n<\/ol>\n<h3 id=\"conclusion\"><strong>7. Conclusion<\/strong><\/h3>\n<p>I hope this blog helped you understand what Tailwind CSS is, how it works, and the advantages it can have over other CSS Frameworks when it comes to building user interfaces fast and efficiently.<\/p>\n<h3 id=\"aboutcloudthat\"><strong>8. About CloudThat<\/strong><\/h3>\n<p><strong>CloudThat<\/strong> is also the official \u00a0Microsoft Gold Partner, AWS Advanced Consulting Partner, and Training partner helping people develop knowledge of the cloud and help their businesses aim for higher goals using best in industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.<\/p>\n<h3 id=\"faqs\"><strong>9. FAQs <\/strong><\/h3>\n<ol>\n<li>\n<h4><strong>What is the difference between HTML and CSS?<\/strong><\/h4>\n<p><a href=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12103\" src=\"https:\/\/d1f7lmxeo98xps.cloudfront.net\/resources\/wp-content\/uploads\/2022\/11\/css1.png\" alt=\"Tailwind CSS\" width=\"437\" height=\"269\" \/><\/a><\/li>\n<li>\n<h4><strong>How to integrate CSS on a web page?<\/strong><\/h4>\n<p>Using three-way we can integrate CSS on a web page<\/p>\n<ul>\n<li>Inline: using the style attribute inside HTML<\/li>\n<li>internal: using style elements in the head section<\/li>\n<li>Linked\/Imported\/External: using a link element to link to the external CSS file<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"author":300,"featured_media":12157,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607],"user_email":"rupesh.y@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12102"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/300"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=12102"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12102\/revisions"}],"predecessor-version":[{"id":45643,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/12102\/revisions\/45643"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=12102"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=12102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}