Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7829

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T07:29:11+00:00 2024-11-28T07:29:11+00:00

How to use Tailwind CSS 3 with Headless UI In React

  • 60k

In this section we will install tailwind v3 headless ui react. Headless UI is a set of completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS. it is also provide dropdown menu, lightbox, Switch (Toggle), Dialog (Modal), Popover, Radio Group, Transition, Tabs. So you can easily copy and paste code in you project.

Tool Use

Tailwind CSS 3.x
Headless UI
React JS

Install Tailwind CSS v3 In React

Create react project

npx create-react-app react-headlessui  
Enter fullscreen mode Exit fullscreen mode

move to project folder & run.

cd react-headlessui npm start 
Enter fullscreen mode Exit fullscreen mode

Install tailwind v3.

npm install -D tailwindcss postcss autoprefixer 
Enter fullscreen mode Exit fullscreen mode

Create tailwind config file.

npx tailwindcss init 
Enter fullscreen mode Exit fullscreen mode

Next, you need to set tailwind config path.

tailwind.config.js

module.exports = {  content: [   "./src/**/*.{js,jsx,ts,tsx}",  ],  theme: {   extend: {},  },  plugins: [], } 
Enter fullscreen mode Exit fullscreen mode

Add the @tailwind directives for each of Tailwind’s layers to your ./src/index.css file.
index.css

@tailwind base; @tailwind components; @tailwind utilities; 
Enter fullscreen mode Exit fullscreen mode

App.js

function App() {   return (     <div className="container mx-auto mt-4">       <h1 className="text-xl font-bold ">         Setup Tailwind CSS 3 with{' '}         <span className="text-transparent bg-clip-text bg-gradient-to-r from-green-400 via-blue-500 to-purple-600">           Headless UI In React         </span>       </h1>     </div>   ); }   export default App; 
Enter fullscreen mode Exit fullscreen mode

tailwind react
Install headless ui
To get started, install Headless UI via npm or yarn:

# npm npm install @headlessui/react  # Yarn yarn add @headlessui/react 
Enter fullscreen mode Exit fullscreen mode

Now lets test headless ui toggle code.

App.js

import { useState } from 'react' import { Switch } from '@headlessui/react'  export default function App() {   const [enabled, setEnabled] = useState(false)    return (     <div className="container mx-auto mt-20">       <h1 className="text-xl font-bold ">         Tailwind Headless UI {' '}         <span className="text-transparent bg-clip-text bg-gradient-to-r from-green-400 via-blue-500 to-purple-600">           Switch (Toggle)         </span>       </h1>       <div className="ml-28">         <Switch           checked={enabled}           onChange={setEnabled}           className={`${enabled ? 'bg-teal-900' : 'bg-teal-700'}           relative inline-flex flex-shrink-0 h-[38px] w-[74px] border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus-visible:ring-2  focus-visible:ring-white focus-visible:ring-opacity-75`}         >           <span className="sr-only">Use setting</span>           <span             aria-hidden="true"             className={`${enabled ? 'translate-x-9' : 'translate-x-0'}             pointer-events-none inline-block h-[34px] w-[34px] rounded-full bg-white shadow-lg transform ring-0 transition ease-in-out duration-200`}           />         </Switch>       </div>     </div>   ) } 
Enter fullscreen mode Exit fullscreen mode

tailwind react headless toggle

run project via npm or yarn.

# npm npm start  # Yarn yarn start 
Enter fullscreen mode Exit fullscreen mode

You can use more tailwind headless components in doc.

Buy Me A laptop

Read Also

👉 Tailwind CSS Halloween Buttons Tutorial Example

👉 Tailwind CSS List Style Marker Example

👉 Create a Google Clone UI using Tailwind CSS

👉 Tailwind CSS Use Custom Fonts Example

👉 Tailwind CSS Line Chart Example

👉 Tailwind CSS Gradient Button Example

👉 Tailwind CSS Text Gradient Example

👉 Tailwind CSS Simple POST CRUD UI Example

👉 Tailwind CSS Thank You Page Example

👉 Tailwind CSS 3 Breadcrumb Example

👉 Tailwind CSS 3D Button Example

👉 How to Use Custom Colors in Tailwind CSS

👉 How to Use Strike Tag (cut text) in Tailwind CSS

👉 Tailwind CSS Headings Typography Examples

👉 Tailwind CSS Product List Example

👉 How to Center a Div in Tailwind CSS

headlessuireacttailwindcsswebdev
  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.