🌐
Smashing Magazine
smashingmagazine.com › 2020 › 05 › reusable-react-components-tailwind
Building Reusable React Components Using Tailwind — Smashing Magazine
May 25, 2020 - In this article, we looked at three ways that you can integrate Tailwind into a React application to build reusable components.
🌐
LogRocket
blog.logrocket.com › home › building reusable react components using tailwind css
Building reusable React components using Tailwind CSS - LogRocket Blog
June 4, 2024 - Create reusable React components with Tailwind CSS, an easy way to style apps without high-level mastery of CSS.
Discussions

Best way to create reusable class combos with Tailwind CSS in React?
As u/ORCANZ states, that would be a component you’d want tho extract. More on reddit.com
🌐 r/tailwindcss
13
6
September 26, 2024
reactjs - what is the best pracitse to make reusable react component with different styles using tailwind? - Stack Overflow
I have a react component with fairly complicated design, styled by tailwind and want to make it reusable with different styles depending on the value of its parameter which called variant. what is... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Simple way to reuse tailwind component in react - Stack Overflow
I'm using Tailwind CSS in react. I'd like to know how to reuse a tailwind button style in a simple way, and where to keep the component in the file. export default function App() { return ... More on stackoverflow.com
🌐 stackoverflow.com
Tailwind reusable component className override issues?
Specificity doesn’t work for class names the way it works for CSS rules. The overrides will come from where the class is declared in the compiled CSS file not where you place the class in the className prop. See what is overriding what in the chrome inspector. Ask yourself why you are overriding classes like this. Does that mean there are visual properties the component is owning that really its parent should be owning? Does it mean the variations should be a prop (eg light/dark Boolean) and you convert those props to the right classes within the component logic? Usually it’s a flag when you find yourself needing to override things like this in tailwind. Whenever I notice that, it makes me feel like I was using tailwind wrong or thinking about components wrong—and I can usually find a way better solution! But not always—don’t crucify me! Lol But I feel like generally the component should do the cooking and the parent just orders what it wants without having to know the recipe. It’s for the component to decide what Eg a darkMode prop should mean. Otherwise when that changes you’ll be in for a rough refactor someday where inheritance/ overrides are causing unexpected behaviors! If it’s not and you need to be able to override classes in this way, there are libraries that will merge them. Quick google! More on reddit.com
🌐 r/react
4
0
April 10, 2023
🌐
Vercel
react-twc.vercel.app
Create reusable Tailwind CSS + React components – TWC
With just one single line of code, you can create a reusable component with all these amazing features out-of-the-box: ⚡️ Lightweight — only 0.49kb · ✨ Autocompletion in all editors · 🎨 Adapt the style based on props · ♻️ Reuse classes with asChild prop · 🦄 Work with all components · 😎 Compatible with React Server Components · 🚀 First-class tailwind-merge and cva support ·
🌐
GitHub
github.com › weDevsOfficial › tail-react
GitHub - weDevsOfficial/tail-react: Collection of reusable React components styled with Tailwind CSS · GitHub
This repository contains a collection of reusable React components styled with Tailwind CSS.
Starred by 8 users
Forked by 4 users
Languages   TypeScript 87.7% | MDX 9.1% | CSS 2.8%
🌐
Lucky Media
luckymedia.dev › blog › small-and-reusable-tailwind-components-with-react
Build Reusable Tailwind Components in React - Lucky Media
August 4, 2022 - Create efficient, reusable Tailwind CSS components for React applications. Enhance your UI with our guide on crafting versatile design elements.
Call   +14696942442
Address   325 North St. Paul Street, 75201, Dallas
🌐
Stack Overflow
stackoverflow.com › questions › 76404833 › what-is-the-best-pracitse-to-make-reusable-react-component-with-different-styles
reactjs - what is the best pracitse to make reusable react component with different styles using tailwind? - Stack Overflow
import React from "react"; import { twMerge } from "tailwind-merge"; const baseClasses = ` min-w-[220px] px-8 py-4 text-base leading-5 font-semibold border-none rounded-md cursor-pointer disabled:opacity-50 `; const variationClasses = { "black-on-green": ` ${ baseClasses } text-zinc-700 bg-emerald-300 ` }; interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> { children: React.ReactNode; className?: string; variation: keyof typeof variationClasses; } const CustomButton = React.forwardRef<HTMLButtonElement, Props>(({ children, className, variation, ...rest }, ref) => { return( <button className={ twMerge(variationClasses[variation], className) } ref={ ref } type="submit" { ...rest }> { children } </button> ); }); CustomButton.displayName = "CustomButton"; export { CustomButton };
Find elsewhere
🌐
daily.dev
daily.dev › home › blog › tailwind css › create reusable tailwind css components with react and typescript
Create reusable Tailwind CSS components with React and TypeScript
May 6, 2021 - Inside the template literals, we use the good-old CSS syntax with some enhancements such as nesting, autoprefixer, etc. We can now use Button just like every React component. Place it everywhere you want. To create a new Tailwind CSS component in our React project, we have several methods:
🌐
DEV Community
dev.to › mhcrocky › creating-a-reusable-button-component-with-react-and-tailwind-css-4dh5
Creating a reusable Button component with React and Tailwind CSS - DEV Community
November 9, 2022 - You can check if tailwind is working correctly by rendering this button element. <button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"> Enable </button> If not working properly please refer to the documentation page. Let's create reusable button from the snippet earlier. I am using typescript for better prop validation. // Button.tsx import { forwardRef } from "react"; interface ButtonOptions {} type Ref = HTMLButtonElement; expor_t type ButtonProps = React.DetailedHTMLProps< React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement > & ButtonOptions;
Top answer
1 of 3
3

I'm sharing one of my implementations using TypeScript.

You can get ideas of how you can reuse any component with tailwind. The implementation, naming and pathing usually opinionated.

// src/components/atoms/Button.tsx
import {DefaultComponent} from '$types/common';
import {NoopFn, classNames} from '@utils';
import {ReactElement} from 'react';

type ButtonUse = `primary` | `secondary` | `destructive`;
type ButtonSize = `xs` | `sm` | `md`;
type ButtonType = `button` | `submit`;

type ButtonProps = DefaultComponent & {
  size?: ButtonSize;
  type?: ButtonType;
  use?: ButtonUse;
};

const BUTTON_SIZE: {[key in ButtonSize]: string} = {
  md: `text-base px-4 py-2`,
  sm: `text-sm px-3 py-2 leading-4`,
  xs: `text-xs px-2.5 py-1.5`,
};

const BUTTON_COLOR: {[key in ButtonUse]: string} = {
  destructive: `text-white bg-red-600 hover:bg-red-700`,
  primary: `text-white bg-indigo-600 hover:bg-indigo-700`,
  secondary: ``,
};

export const Button = (props: ButtonProps): ReactElement => {
  const {
    className = ``,
    children,
    use = `primary`,
    size = `xs`,
    type = `button`,
    onClick = NoopFn,
  } = props;
  return (
    <button
      {...{onClick, type}}
      className={classNames(
        `inline-flex items-center border border-transparent font-medium rounded shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 justify-center`,
        BUTTON_SIZE[size],
        BUTTON_COLOR[use],
        className,
      )}>
      {children}
    </button>
  );
};
2 of 3
2

You can use the @apply directive:

// do this in your CSS file

.my-btn {
  @apply py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75;
}

Then in your JSX code:

<button className="my-btn">Foo</button>

Also you can just create a simple component file:

// src/components/MyButton.jsx

const MyButton = ({ children }) => <button className="py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75">{children}</button>

export default MyButton

In your App file:

import MyButton from './components/MyButton'

// ...

<MyButton>foo</MyButton>
<MyButton>bar</MyButton>

You'll need to modify MyButton if you want to pass other props too. Though, I'ld recommend using a CSS-in-JS library like styled-components or Emotion instead. There are Tailwind specific alternatives too that may interest you: twin.macro, Twind, xwind.


Simplest way - just store the classes in a string.

const myBtn = "py-2 px-4 bg-green-500 text-white font-semibold rounded-lg shadow-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-75"

// ...

<button className={`${myBtn} some-other-class-specific-to-foo`}>Foo</button>
<button className={myBtn}>Bar</button>

You can also use libraries like classnames and clsx for composing the strings.

🌐
The Dev chronicles
ubah484.hashnode.dev › building-reusable-components-in-react-using-tailwind-and-cva
Build Reusable UI Components in React and Tailwind CSS
January 8, 2025 - In this article, we'll learn how to build reusable UI components in React and Tailwind CSS which can save us time and improve our workflow.
🌐
Tailwind CSS
tailwindcss.com › docs › reusing-styles
Reusing Styles - Tailwind CSS
July 19, 2023 - If you need to reuse some styles across multiple files, the best strategy is to create a component if you’re using a front-end framework like React, Svelte, or Vue, or a template partial if you’re using a templating language like Blade, ERB, Twig, or Nunjucks.
🌐
Tryhoverify
tryhoverify.com › blog › component-abstraction-writing-reusable-ui-with-tailwind-react
Component Abstraction: Writing Reusable UI with Tailwind + React | Hoverify
July 20, 2025 - Building on the foundational concepts ... utility-first approach of Tailwind CSS. Begin by crafting simple markup, and as you notice recurring patterns, extract them into reusable components....
🌐
Medium
medium.com › @gorkemkaramolla › react-tailwind-reuseable-and-customizable-components-with-cva-clsx-and-tailwindmerge-combo-guide-c3756bdbbf16
React & Tailwind reusable and customizable components with CVA, Clsx, and TailwindMerge Combo Guide | by Görkem Karamolla | JavaScript in Plain English
June 12, 2025 - To achieve this, we’ll make use of the class-variance-authority (CVA) library. Join Medium for free to get updates from this writer. ... The CVA library empowers us to build reusable components that can be customized to suit our specific needs.
🌐
Unwiredlearning
unwiredlearning.com › blog › reusable-tailwind-components
Reusable UI Components in React with Tailwind CSS
February 6, 2026 - Build reusable UI components in React with Tailwind CSS. Create Button, Card, and Input patterns using props to keep styling consistent—read it today.
🌐
Medium
komaldin.medium.com › using-tailwind-css-properties-as-a-reusable-component-25f5809749f4
Using Tailwind CSS properties as a reusable Component | by Komal | Medium
August 19, 2024 - I recently started using Tailinwind CSS and often found my <div> element with long strings of the same property throughout my project. React.js is built on components to practice “Don’t Repeat Yourself”(DRY) code so, why not implement same principal to our styling?
🌐
Medium
bawantharathnayaka.medium.com › create-highly-reusable-components-using-tailwind-css-239f75485837
Create highly reusable components using Tailwind CSS | by Bawantha Rathnayaka | Medium
February 2, 2024 - some times we need to create highly ... CSS framework for rapidly building custom user interfaces, paired with React you can create powerful and reusable components....
🌐
TailGrids
tailgrids.com
Tailgrids UI – Tailwind React Component Library and Design System | Tailgrids UI
Ship modern web apps faster with 600+ free components, pro-grade blocks, and templates - a unified React + Tailwind UI library and design system built for production crafted for developers and designers. Optimized for performance, accessibility, and consistent UI. npx @tailgrids/cli@latest initBrowse All - Components ... 600+ free and pro React UI components, production-ready blocks, templates, and a complete design system built for teams who design, build, and ship at scale. ... Build faster with 600+ reusable React and Tailwind CSS UI blocks for applications, dashboards, marketing sites, eCommerce, and AI products.
🌐
MakerX
blog.makerx.com.au › extracting-reusable-tailwind-react-components
Extracting reusable Tailwind CSS / React components
April 12, 2022 - When there is a reusable component that has a few slightly different presentations, like the above example of a grey box with different styles for the badge, we can codify that into the reusable component as variants. We've lovingly borrowed this terminology from stitches. We can extract the common HTML markup and/or Tailwind CSS that makes up the variants into a React component and use clsx to dynamically build the class names.
🌐
DEV Community
dev.to › rowsanali › building-scalable-and-reusable-react-components-with-tailwind-css-3jd6
Building Scalable and Reusable React Components with Tailwind CSS - DEV Community
February 15, 2025 - It allows you to create reusable UI components that can be composed to build complex UIs. React's component-based architecture promotes reusability and separation of concerns, making it easier to manage and scale large applications.