{"id":57221,"date":"2023-04-30T13:00:08","date_gmt":"2023-04-30T07:30:08","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57221"},"modified":"2023-05-18T13:02:57","modified_gmt":"2023-05-18T07:32:57","slug":"tailwind-css-setup-tailwind-with-react","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/tailwind-css-setup-tailwind-with-react\/","title":{"rendered":"Tailwind CSS: Setup Tailwind With React"},"content":{"rendered":"<h1>Setup tailwind with react<\/h1>\n<h3>1. create your project folder<\/h3>\n<p>Open the terminal and navigate your created project, and then run the below command<br \/>\nnpx create-react-app react-demo.<\/p>\n<p>Once reactdemo app has been created,<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57214 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo-1024x142.png\" alt=\"\" width=\"625\" height=\"87\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo-1024x142.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo-300x42.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo-768x107.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo-624x87.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo.png 1344w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>&gt;&gt; go to the react-demo folder<\/p>\n<p>&gt;&gt; run the &#8220;npm start&#8221; command<\/p>\n<h3><strong>2. Install Tailwind CSS and generate the configuration file<\/strong><\/h3>\n<p>&gt;&gt; npm install -D tailwindcss<br \/>\n&gt;&gt; npx tailwindcss init<\/p>\n<p><strong>Your folder and package.json file should look like this in your VSCode:\u200c<br \/>\n<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57215 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo1.png\" alt=\"\" width=\"406\" height=\"395\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo1.png 406w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo1-300x292.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo1-24x24.png 24w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo1-48x48.png 48w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57216 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo2.png\" alt=\"\" width=\"866\" height=\"533\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo2.png 866w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo2-300x185.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo2-768x473.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo2-624x384.png 624w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/p>\n<h3><strong>3. Configure your template paths<\/strong><\/h3>\n<p>Add the paths to all of your template files in your tailwind.config.js file.<\/p>\n<pre>\/** @type {import('tailwindcss').Config} *\/\r\nmodule.exports = {\r\ncontent: [\r\n\".\/src\/**\/*.{js,jsx,ts,tsx}\",\r\n],\r\ntheme: {\r\nextend: {},\r\n},\r\nplugins: [],\r\n}<\/pre>\n<p><strong>your file should now look like this:<br \/>\n<\/strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57217 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3-1024x304.png\" alt=\"\" width=\"625\" height=\"186\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3-1024x304.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3-300x89.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3-768x228.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3-624x185.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo3.png 1295w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<h3><strong>4. Add the Tailwind directives to your CSS<\/strong><\/h3>\n<p>Add the @tailwind directives for each of Tailwind\u2019s layers to your .\/src\/index.css file.<\/p>\n<p>@tailwind base;<br \/>\n@tailwind components;<br \/>\n@tailwind utilities;<\/p>\n<p><strong>your file should now look like this:<br \/>\n<\/strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57218 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4-1024x392.png\" alt=\"\" width=\"625\" height=\"239\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4-1024x392.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4-300x115.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4-768x294.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4-624x239.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo4.png 1290w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><strong>Writing CSS:\u00a0<\/strong><\/p>\n<p>You can start using Tailwind\u2019s utility classes to style your content. Navigate to your App.jsx file, where you should see this below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57219 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5-1024x372.png\" alt=\"\" width=\"625\" height=\"227\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5-1024x372.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5-300x109.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5-768x279.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5-624x227.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo5.png 1295w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>Output<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57220 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6-1024x517.png\" alt=\"\" width=\"625\" height=\"316\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6-1024x517.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6-300x152.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6-768x388.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6-624x315.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/react-demo6.png 1283w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><strong>Note:<\/strong> if your tailwind CSS property is not reflected on the application, restart your react app.<\/p>\n<h3>Conclusion:<\/h3>\n<p>Now you can develop your responsive application with react and tailwind CSS. For more exploration, you can go through <a href=\"https:\/\/tailwindcss.com\/docs\/installation\">here. <\/a>Thanks for reading this article; I hope you will find this helpful.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Setup tailwind with react 1. create your project folder Open the terminal and navigate your created project, and then run the below command npx create-react-app react-demo. Once reactdemo app has been created, &gt;&gt; go to the react-demo folder &gt;&gt; run the &#8220;npm start&#8221; command 2. Install Tailwind CSS and generate the configuration file &gt;&gt; npm [&hellip;]<\/p>\n","protected":false},"author":1546,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":13},"categories":[3602,3429,3038],"tags":[4862,4860,5199],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57221"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1546"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57221"}],"version-history":[{"count":3,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57221\/revisions"}],"predecessor-version":[{"id":57399,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57221\/revisions\/57399"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}