Tailwind

Overview

Tailwind is a CSS utility framework. It provides a large number of pre-built CSS classes that often only set a single CSS property. These can be used as values of the class attribute on HTML elements. They can also be customized in each application that uses them.

Other CSS frameworks such as Bootstrap, Bulma, Foundation, and Materialize define styling for components. Tailwind takes a different approach, providing lower level styling that can be combined in order to create custom looks.

Tailwind is not a replacement for CSS. It is still necessary for developers to be familiar with CSS properties and their supported values.

Tailwind is implemented as a PostCSS plugin. It can be used in conjunction with other PostCSS plugins such as those that support preprocessors like Sass.

The base styles in Tailwind provide a CSS reset known as "Preflight".

Pros

Cons

No Build Process

There are two approaches for using Tailwind without a build process.

The easiest approach is to include it from a CDN with this link tag:

<script src="https://cdn.tailwindcss.com"></script>

This has the downside that it includes every Tailwind CSS class, not just the ones actually used in the app.

A more involved approach is to generate a CSS file that only contains the Tailwind CSS classes that are actually used. The steps to do this are as follows:

  1. Install Tailwind by entering npm install -D tailwindcss

  2. Create the file tailwind.config.js by entering npx tailwindcss init

  3. Edit the value of content in tailwind.config.js to specify the files that might used Tailwind classes. For example:

    content: ["**/*.{html,tsx}"],
  4. Create the file global.css containing the following:

    @tailwind base;
    @tailwind components;
    @tailwind utilities;

    This file can also define custom CSS classes.

  5. Generate a CSS file containing only the Tailwind classes used in your app.

    Enter npx tailwindcss -i ./global.css -o public/tailwind.css --watch to generate public/tailwind.css now and again every time any of the "content" files are modified.

    Consider adding a package.json script for this such as:

    "tw": "npx tailwindcss -i ./global.css -o public/tailwind.css --watch"
  6. Include the following link element in the base HTML of the app.

    <link href="/public/tailwind.css" rel="stylesheet" />

This also requires enabling serving static files with the following steps:

  1. Install a plugin by entering bun add @elysiajs/static
  2. In the server code, add a call to app.use(staticPlugin());

Basic Build Process

To install Tailwind in a project that has a package.json file, enter npm install -D tailwindcss.

A build process is required to use Tailwind. Many approaches can be taken, but the simplest is to create a public directory and add the following to the scripts section in the package.json file:

  "build:css": "tailwind build src/style.css -o public/style.css",

The file src/style.css should, at a minimum, contain the following:

@tailwind base;
@tailwind components;
@tailwind utilities;

To build the required set of Tailwind CSS classes in public/style.css, enter npm run build:css. This will replace @tailwind directives above with generated CSS. The generated CSS file will contain:

Highlights of the Preflight styles include:

It is only necessary to rebuild the Tailwind-generated CSS when Tailwind directives have been modified or when the build process is configured to purge unused CSS rules and the Tailwind CSS classes being used have changed. Avoiding rebuilds speeds development.

For details on configuring various build tools to support Tailwind, see Tailwind installation.

PostCSS Build Process

An advantage of using PostCSS to build the Tailwind CSS used by an application is that other PostCSS plugins can also be used.

Building with PostCSS is only slightly more complicated. The steps to do this are:

  1. Install all the PostCSS plugins to be used. For example:

    npm install -D postcss-cli autoprefixer@9.8.6
  2. Create the file postcss.config.js containing:

    module.exports = {
    // Include a require for each PostCSS plugin to be used here.
    plugins: [require('tailwindcss'), require('autoprefixer')]
    };
  3. Change the build:css script in package.json to:

    "build:css": "postcss src/style.css -o public/style.css"

Watching For Changes

To automatically run the build:css script any time a file in the src directory changes:

  1. Enter npm install -D watch

  2. Add the following script in package.json:

    "watch": "watch 'npm run build:css' ./src"

Configuration

To see all the Tailwind properties that can be customized, create a new configuration file by entering npx tailwindcss init --full. This creates the file tailwind.config.js. You may wish to save this file for later reference. Consider renaming it to tailwind.config-full.js.

Generate a new tailwind.config.js file by entering npx tailwindcss init and add customizations here. This file will be much shorter than the full version, making it easier to find your customizations. Values used by the provided CSS classes can be customized to change many styling aspects including colors, breakpoints, fonts, and more.

To change the actual colors used when white and black are specified, add a color property to the extend property as follows:

  theme: {
extend: {
colors: {
black: "#222", // very dark gray
white: "#ddd" // very light gray
}

To define new, custom colors, add color properties to the extend property as follows:

  theme: {
extend: {
colors: {
primary: "cornflowerblue",
secondary: "orange"
}

With these in place, we can use CSS class names like bg-primary and text-secondary.

To change the responsive breakpoints, modify the values below:

  theme: {
...
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1280px"
},

To change the fonts used when font-sans, font-serif, and font-mono are specified, modify the font name lists in the arrays below:

  theme: {
...
fontFamily: {
sans: [...],
serif: [...],
mono: [...]
},

To register new fonts and add custom font sizes, specify the fontFamily and fontSize properties in the extend object. For example:

  theme: {
extend: {
fontFamily: {
body: ['SomeFont1', 'SomeFont2']
},
fontSize: {
"hero": "6rem"
},

With this in place we can cause a header element to use it as follows:

<h1 class="text-hero">Welcome to My Page</h1>

The tailwind.config.js file defines a future property whose value is an object with boolean properties that are commented out. Uncomment these to get warnings about usage of features that will break in future releases.

Using With Frameworks

From the website for tailwind-merge, "If you use Tailwind CSS with a component-based UI renderer like React or Vue, you're probably familiar with the situation that you want to change some styles of a component, but only in a one-off case." tailwind-merge provides the function twMerge that takes any number of strings containing space-separated lists of CSS and Tailwind classes. It resolves any conflicts and returns a single string of class names.

Purging Unused CSS Classes

The purge configuration property can be modified to purge unused CSS classes. If this is not done, the generated CSS file will be massive. As of 10/13/2020, the size is 2413K uncompressed, 1967K minified, 190K gzipped, and 46K compressed with Brotli.

The purge property should be set to an array of glob patterns for file paths that can contain references to CSS classes. Tailwind will automatically check for references to Tailwind CSS classes in CSS files.

By default, unused CSS classes are only removed when the NODE_ENV environment variable is set to production. This is desirable. Otherwise every time a new Tailwind CSS class is used, another Tailwind build is required, which slows development.

To remove unused CSS classes regardless of the value of NODE_ENV, set the enabled property in the purge object to true.

For example, the purge property can be configured as follows::

  purge: {
content: ['./public/**/*.html', './src/**.*.svelte'],
enabled: true
},

Minimizing CSS

To minimize the generated CSS, including removing comments, in order to make it smaller:

  1. Enter npm install -D cssnano

  2. Change the content of the postcss.config.js file to include :the following:

    const cssnano = require('cssnano');

    module.exports = {
    plugins: [
    require('tailwindcss'),
    require('autoprefixer'),
    cssnano({
    preset: 'default'
    })
    ]
    };

It may be desirable to only minimize CSS in production builds. To modify postcss.config.js to do this, see the end of How to setup Tailwind with PurgeCSS and PostCSS.

Serving Changes

There are many approaches to serve a site from local files and automatically refresh the browser when changes are detected. One simple approach is to use live-server.

To use live-server:

  1. Enter npm install -g live-server
  2. Enter live-server public where public contains an index.html file.
  3. Browse localhost:8080.

VS Code Support

The VS Code extension Tailwind CSS IntelliSense provides autocomplete, syntax highlighting, and linting.

While entering Tailwind CSS class names, a popup displays all matching names and their definitions. For example, entering "upp" displays "uppercase - text-transform: uppercase".

To see the definition of a Tailwind CSS class that has already been entered, hover over its name.

A small color swatch is displayed in front of each Tailwind class name that represents a color.

The VS Code extension Tailwind Fold automatically folds the values of class attributes in HTML and className props in JSX. To see one of these values, move the cursor to its line. To toggle the folding behavior off and on, press ctrl-option-a.

To enable Emmet completions of Tailwind CSS class names, add the following in the VS Code settings.json file:

  "tailwindCSS.emmetCompletions": true

Icons

The makers of Tailwind created heroicons which is a website that provides a large collection of free SVG icons. Hover over an icon to expose buttons for downloading it in SVG or JSX. Paste this into an HTML file or React component.

The icons come in three variations with a viewBox of a specific size:

By default the icons have the Tailwind classes w-6 and h-6 which makes them a 1.5rem square. To change the size of an icon, change these w and h classes.

To set the color of an icon, set its CSS color property.

When using React or Next.js, another option is to enter npm install @heroicons/react and import specific icons in component source files. For example:

import {BeakerIcon} from '@heroicons/react/24/solid';

Responsive Breakpoints

By default Tailwind uses the following responsive breakpoints:

Namemin-width
sm640px
md768px
lg1024px
xl1280px

These specify min-width values, so a mobile-first approach is used.

Precede Tailwind CSS class names with a breakpoint name and a colon to only apply the CSS class when the screen/window width is greater than or equal to the corresponding min-width value. For example: lg:m-4 applies a margin of 1rem only if the screen/window width is greater than or equal to 1024px.

Class names with no breakpoint prefix are used when the screen/window width is smaller than the largest prefix used. For example text-red md:text-green makes the text red for all widths less than 768px and green for all widths greater than or equal to 768px.

To show an element only when on a mobile device, use md:hidden. To hide an element when on a mobile device, use hidden md:block.

This approach for making UIs responsive is easier than writing CSS media queries.

The breakpoint values can be overridden by modifying the tailwind.config.js file as shown in the Configuration section.

Pseudo-class Variants

Tailwind supports many prefixes that can be added before class names, separated by a colon, that cause the class to only be applied when a certain condition holds.

VariantCondition
activeelement is active (ex. a <button> is being pressed)
checkedcheckbox or radio button is checked
darkuser set OS to use dark mode (default is light mode, no light variant)
disabledform element is disabled
even-childelement is an event-numbered child of its parent (zero-based index is odd)
first-childelement is the first child of its parent
focus-visibleelement has focus and the user is using a keyboard
focus-withinancestor element has focus
focusform element (ex. <input>) has focus
group-focusancestor element has the group class and has focus
group-hoverhovering over an ancestor element that has the group class
hovermouse cursor is over the element
last-childelement is the last child of its parent
motion-reduceprefers-reduced-motion media feature matches reduce
motion-safeprefers-reduced-motion media feature matches no-preference
odd-childelement is an odd-numbered child of its parent (zero-based index is even)
visitedlink (<a>) has been visited

These prefixes can be combined with responsive prefixes. For example, md:hover:border.

TODO: How can you enable a class when one of these conditions is NOT met?

Tailwind Directives

Tailwind supports several directives described below.

@apply

The @apply directive includes properties from any number of Tailwind classes in a custom CSS rule. This enables a set of Tailwind classes to be reused on several elements without repeating them.

For example, the following can be added to src/style.css after the @tailwind directives:

@layer components {
.my-alert {
@apply bg-red-400 inline-block p-4 rounded-full text-2xl text-white;
}
}

After a Tailwind build, the my-alert class can be used to apply the styling of all the Tailwind classes specified with the @apply directive.

For example:

<div class="my-alert">Alert! Something is wrong.</div>

@layer

The @layer directive is used to add custom CSS rules to a specific bucket of Tailwind CSS rules.

@responsive

The @responsive directive generates responsive variants of custom CSS classes where the same styling is used for every breakpoint. To use different styling for some breakpoints, define media queries that override these.

@screen

The @screen directive creates a media query that utilizes a breakpoint value. For example, instead of writing a media query like this:

@media (min-width: 768px) {
/* rules go here */
}

it can be written as follows to use the min-width value specified for the md breakpoint:

@screen md {
/* rules go here */
}

@tailwind

The @tailwind directive is used to inject Tailwind CSS class definitions into the content of a CSS file. Earlier we saw this used in the src/style.css file.

@variants

The @variants directive is used to generate variants of your own CSS classes that are responsive or are only used when an element is hovered over, has focus, or is active.

Tailwind Functions

Tailwind currently provides a single function, theme.

theme Function

The theme function is used obtain values from the Tailwind config in CSS property values. For example, to use a shade of yellow from Tailwind in a custom CSS rule:

.warning {
background-color: theme('colors.yellow.600');
}

Note that the string passed to the theme function is a dot-separated path to a Tailwind configuration value, not the name of a Tailwind class.

The rule above could also be written using the the @apply directive as follows:

.warning {
@apply bg-yellow-600;
}

The theme function is primarily useful when a value will be used as part of a longer value or in a calculation using the CSS calc function.

Provided CSS Classes

The following sections list all the provided Tailwind CSS classes. There are a large number of them!

This same information is available in the official docs at tailwindcss.com/docs. It is included here in a more compact manner that is more easily searchable because they are all on a single page.

Many Tailwind class names end with a numeric strength value. Often this represents a multiple of 0.25rem. For example, the class p-4 adds padding of 1rem to all sides of an element. Class names for colors can specify strength values that are multiples of 100. For example, the class text-red-400 specifies a certain shade of red.

Many Tailwind class names support specifying an arbitrary value in square brackets. For example, the class p-[19px] adds padding of 19px to all sides of an element.

In class names that include -color, color should be replaced by one of gray, red, orange, yellow, green, teal, blue, indigo, purple, or pink.

In the "CSS Property" column of the tables below, lines where the property name start with -- are setting the value of a CSS variables (a.k.a. CSS custom properties).

Backgrounds

Class NameCSS Property
bg-fixedbackground-attachment: fixed;
bg-localbackground-attachment: local;
bg-scrollbackground-attachment: scroll;
bg-clip-borderbackground-clip: border-box;
bg-clip-contentbackground-clip: content-box;
bg-clip-paddingbackground-clip: padding-box;
bg-clip-textbackground-clip: text;
bg-transparentbackground-color: transparent;
bg-currentbackground-color: currentColor;
bg-blackbackground-color: #000;
bg-whitebackground-color: #fff;
bg-slate-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-gray-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-zinc-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-neutral-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-stone-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-red-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-orange-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-amber-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-yellow-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-lime-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-green-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-emerald-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-teal-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-cyan-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-sky-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-blue-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-indigo-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-violet-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-purple-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-fuchsia-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-pink-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-rose-nbackground-color: #X;
where X is 50, 950, or a multiple of 100
bg-{color}-{n}background-color: {color-hex-code};
where n is 100 to 900 in increments of 100
bg-opacity-{n}--bg-opacity: {n}/100;
where n = 0, 25, 50, 75, or 100
bg-bottombackground-position: bottom;
bg-centerbackground-position: center;
bg-leftbackground-position: left;
bg-left-bottombackground-position: left bottom;
bg-left-topbackground-position: left top;
bg-rightbackground-position: right;
bg-right-bottombackground-position: right bottom;
bg-right-topbackground-position: right top;
bg-topbackground-position: top;
bg-repeatbackground-repeat: repeat;
bg-no-repeatbackground-repeat: no-repeat;
bg-repeat-xbackground-repeat: repeat-x;
bg-repeat-ybackground-repeat: repeat-y;
bg-repeat-roundbackground-repeat: round;
bg-repeat-spacebackground-repeat: space;
bg-autobackground-size: auto;
bg-containbackground-size: contain;
bg-coverbackground-size: cover;
bg-nonebackground-image: none;
bg-gradient-to-tbackground-image: linear-gradient(to top, var(--gradient-color-stops));
bg-gradient-to-trbackground-image: linear-gradient(to top right, var(--gradient-color-stops));
bg-gradient-to-rbackground-image: linear-gradient(to right, var(--gradient-color-stops));
bg-gradient-to-brbackground-image: linear-gradient(to bottom right, var(--gradient-color-stops));
bg-gradient-to-bbackground-image: linear-gradient(to bottom, var(--gradient-color-stops));
bg-gradient-to-blbackground-image: linear-gradient(to bottom left, var(--gradient-color-stops));
bg-gradient-to-lbackground-image: linear-gradient(to left, var(--gradient-color-stops));
bg-gradient-to-tlbackground-image: linear-gradient(to top left, var(--gradient-color-stops));
from-transparent--gradient-from-color: transparent
from-current--gradient-from-color: currentColor
from-black--gradient-from-color: #000
from-white--gradient-from-color: #fff
from-{color}-{n}--gradient-from-color: {color-hex-code};
where n is 100 to 900 in increments of 100
via-transparent--gradient-via-color: transparent
via-current--gradient-via-color: currentColor
via-black--gradient-via-color: #000
via-white--gradient-via-color: #fff
via-{color}-{n}--gradient-via-color: {color-hex-code};
where n is 100 to 900 in increments of 100
to-transparent--gradient-to-color: transparent
to-current--gradient-to-color: currentColor
to-black--gradient-to-color: #000
to-white--gradient-to-color: #fff
to-{color}-{n}--gradient-to-color: {color-hex-code};
where n is 100 to 900 in increments of 100

Borders

In the class names below, side can be one of the following:

Side AbbreviationSide NameCSS Properties Affected
bbottomborder-bottom-left and border-bottom-right
lleftborder-bottom-left and border-top-left
rrightborder-bottom-right and border-top-right
ttopborder-top-left and border-top-right

In the class names below, corner can be one of the following:

Corner AbbreviationCorner NameCSS Property Affected
blbottom leftborder-bottom-left
brbottom rightborder-bottom-right
tltop leftborder-top-left
trtop rightborder-top-right

 

Class NameCSS Property
rounded-noneborder-radius: 0;
rounded-smborder-radius: 0.125rem;
roundedborder-radius: 0.25rem;
rounded-mdborder-radius: 0.375rem;
rounded-lgborder-radius: 0.5rem;
rounded-full:border-radius: 9999px;
rounded-{side/corner}-nonesets affected properties to 0
rounded-{side/corner}-smsets affected properties to 0.125rem
rounded-{side/corner}sets affected properties to 0.25rem
rounded-{side/corner}-mdsets affected properties to 0.375rem
rounded-{side/corner}-lgsets affected properties to 0.5rem
rounded-{side/corner}-fullsets affected properties to 9999px
borderborder-width: 1px;
border-{n}border-width: {n}px;
where n = 0, 2, 4, or 8
border-sidesets affected property: to 1px;
border-side-{n}sets affected property: to {n}px;
where n = 0, 2, 4, or 8
border-transparentborder-color: transparent;
border-currentborder-color: currentColor;
border-blackborder-color: #000;
border-whiteborder-color: #fff;
border-{color}-{n}border-color: {color-hex-code};
where n is 100 to 900 in increments of 100
border-opacity-{n}--border-opacity: {n}/100;
where n = 0, 25, 50, 75, or 100
border-dashedborder-style: dashed;
border-dottedborder-style: dotted;
border-doubleborder-style: double;
border-noneborder-style: none;
border-solidborder-style: solid;
divide-xborder-left-width: 1px;
divide-x-{n}border-left-width: {n}px;
where n = 0, 2, 4, or 8
divide-x-reverse--divide-x-reverse: 1;
divide-yborder-top-width: 1px;
divide-y-{n}border-top-width: {n}px;
where n = 0, 2, 4, or 8
divide-y-reverse--divide-y-reverse: 1;
divide-transparentborder-color: transparent;
divide-currentborder-color: currentColor;
divide-blackborder-color: #000;
divide-whiteborder-color: #fff;
divide-{color}-{n}border-color: {color-hex-code};
where n is 100 to 900 in increments of 100
divide-opacity-{n}--divide-opacity: {n}/100;
where n = 0, 25, 50, 75, or 100
divide-dashedborder-style: dashed;
divide-dottedborder-style: dotted;
divide-doubleborder-style: double;
divide-noneborder-style: none;
divide-solidborder-style: solid;

Box Alignment

Name PrefixCSS Property
content-centeralign-content: center;
content-startalign-content: flex-start;
content-endalign-content: flex-end;
content-betweenalign-content: space-between;
content-aroundalign-content: space-around;
content-evenlyalign-content: space-evenly;
items-baseline;align-items: baseline;
items-center;align-items: center;
items-end;align-items: flex-end;
items-start;align-items: flex-start;
items-stretch;align-items: stretch;
justify-aroundjustify-content: space-around;
justify-betweenjustify-content: space-between;
justify-centerjustify-content: center;
justify-endjustify-content: flex-end;
justify-evenlyjustify-content: space-evenly;
justify-startjustify-content: flex-start;
justify-items-autojustify-items: auto;
justify-items-centerjustify-items: center;
justify-items-endjustify-items: end;
justify-items-startjustify-items: start;
justify-items-stretchjustify-items: stretch;
justify-self-autojustify-self: auto;
justify-self-centerjustify-self: center;
justify-self-endjustify-self: end;
justify-self-startjustify-self: start;
justify-self-stretchjustify-self: stretch;
place-content-aroundplace-content: space-around;
place-content-betweenplace-content: space-between;
place-content-centerplace-content: center;
place-content-endplace-content: end;
place-content-evenlyplace-content: space-evenly;
place-content-startplace-content: start;
place-content-stretchplace-content: stretch;
place-items-autoplace-items: auto;
place-items-centerplace-items: center;
place-items-endplace-items: end;
place-items-startplace-items: start;
place-items-stretchplace-items: stretch;
place-self-autoplace-self: auto;
place-self-centerplace-self: center;
place-self-endplace-self: end;
place-self-startplace-self: start;
place-self-stretchplace-self: stretch;
self-autoalign-self: auto;
self-centeralign-self: center;
self-endalign-self: flex-end;
self-startalign-self: flex-start;
self-stretchalign-self: stretch;

Box Sizing

Name PrefixCSS Property
box-borderbox-sizing: border-box;
box-contentbox-sizing: content-box;

Container

Name PrefixEffect
containersets max-width to breakpoint size or
width to 100% if no breakpoint specified

For example, lg:container or container.

Display

Name PrefixCSS Property
blockdisplay: block;
inlinedisplay: inline;
inline-blockdisplay: inline-block;
flexdisplay: flex;
inline-flexdisplay: inline-flex;
tabledisplay: table;
table-captiondisplay: table-caption;
table-celldisplay: table-cell;
table-column-groupdisplay: table-column-group;
table-footer-groupdisplay: table-footer-group;
table-header-groupdisplay: table-header-group;

Effects

The box-shadow values set by the shadow classes are somewhat complicated. For details see the Box Shadow docs.

Name PrefixCSS Property
opacity-nopacity: {n}/100;
where n = 0, 25, 50, 75, or 100
shadow-nonebox-shadow: none
shadow-innerbox-shadow: ...; see docs
shadow-outlinebox-shadow: ...; see docs
shadowbox-shadow: ...; see docs
shadow-xsbox-shadow: ...; see docs
shadow-smbox-shadow: ...; see docs
shadow-mdbox-shadow: ...; see docs
shadow-lgbox-shadow: ...; see docs
shadow-xlbox-shadow: ...; see docs
shadow-2xlbox-shadow: ...; see docs

Flexbox

Name PrefixCSS Property
flex-1flex: 1 1 0%;
flex-autoflex: 1 1 auto;
flex-initialflex: 0 1 auto;
flex-noneflex: none;
flex-colflex-direction: column;
flex-col-reverseflex-direction: column-reverse;
flex-rowflex-direction: row;
flex-row-reverseflex-direction: row-reverse;
flex-wrapflex-wrap: wrap;
flex-wrap-reverseflex-wrap: wrap-reverse;
flex-no-wrapflex-wrap: nowrap;
flex-growflex-grow: 1;
flex-grow-0flex-grow: 0;
flex-shrinkflex-shrink: 1;
flex-shrink-0flex-shrink: 0;
order-{n}order: {n};
where n is 1 to 12

Also see the classes in the Box Alignment category.

Float and Clear

Name PrefixCSS Property
clear-bothclear: both;
clear-leftclear: left;
clear-noneclear: none;
clear-rightclear: right;
clearfix&:after { content: ""; display: table; clear: both; }
float-leftfloat: left;
float-nonefloat: none;
float-rightfloat: right;

Grid

Name PrefixCSS Property
auto-cols-autogrid-auto-columns: auto
auto-cols-frgrid-auto-columns: minmax(0, 1fr)
auto-cols-maxgrid-auto-columns: max-content
auto-cols-mingrid-auto-columns: min-content
auto-rows-autogrid-auto-rows: auto
auto-rows-frgrid-auto-rows: minmax(0, 1fr)
auto-rows-maxgrid-auto-rows: max-content
auto-rows-mingrid-auto-rows: min-content
col-autogrid-column: auto
col-end-{n}grid-column-end: {n}
where n is 1 to 13
col-end-autogrid-column-end: auto
col-span-{n}grid-column: span {n} / span {n}
where n is 1 to 12
col-span-fullgrid-column: 1 / -1
col-start-{n}grid-column-start: {n}
where n is 1 to 13
col-start-autogrid-column-start: auto
gap-{n}gap: {n}
where n is 0 to 8, 10, 12, 16, 20, 24, 32, 40, 48, 56, or 64
gap-pxgap: 1px
gap-x-{n}column-gap: {n}*0.25rem
where n is 0 to 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 56, or 64
gap-x-pxcolumn-gap: 1px
gap-y-{n}row-gap: {n}*0.25rem
where n is 0 to 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 56, or 64
gap-y-pxrow-gap: 1px
grid-cols-{n}grid-template-columns: repeat({n}, minmax(0, 1fr));
where n is 1 to 12
grid-cols-nonegrid-template-columns: none;
grid-flow-col-densegrid-auto-flow: column dense
grid-flow-colgrid-auto-flow: column
grid-flow-row-densegrid-auto-flow: row dense
grid-flow-rowgrid-auto-flow: row
grid-rows-{n}grid-template-rows: repeat({n}, minmax(0, 1fr));
where n is 1 to 6
grid-rows-nonegrid-template-rows: none;
row-autogrid-row: auto
row-end-{n}grid-row-end: {n}
where n is 1 to 7
row-end-autogrid-row-end: auto
row-span-{n}grid-row: span {n} / span {n}
where n is 1 to 6
row-start-{n}grid-row-start: {n}
where n is 1 to 7
row-start-autogrid-row-start: auto

Interactivity

Name PrefixCSS Property
appearance-noneappearance: none;
cursor-autocursor: auto;
cursor-defaultcursor: default;
cursor-pointercursor: pointer;
cursor-waitcursor: wait;
cursor-textcursor: text;
cursor-movecursor: move;
cursor-not-allowedcursor: not-allowed;
outline-noneoutline: none;
pointer-events-autopointer-events: auto;
pointer-events-nonepointer-events: none;
resize-noneresize: none;
resize-xresize: horizontal;
resize-yresize: vertical;
resizeresize: both;
select-noneuser-select: none;
select-alluser-select: all;
select-autouser-select: auto;
select-textuser-select: text;

Object Fit

Name PrefixCSS Property
object-containobject-fit: contain;
object-coverobject-fit: cover;
object-fillobject-fit: fill;
object-noneobject-fit: none;
object-scale-downobject-fit: scale-down;

Object Position

Name PrefixCSS Property
object-bottomobject-position: bottom;
object-centerobject-position: center;
object-leftobject-position: left;
object-left-bottomobject-position: left bottom;
object-left-topobject-position: left top;
object-rightobject-position: right;
object-right-bottomobject-position: right bottom;
object-right-topobject-position: right top;
object-topobject-position: top;

Overflow

Name PrefixCSS Property
overflow-autooverflow: auto;
overflow-hiddenoverflow: hidden;
overflow-scrolloverflow: scroll;
overflow-visibleoverflow: visible;
overflow-x-autooverflow-x: auto;
overflow-x-hiddenoverflow-x: hidden;
overflow-x-scrolloverflow-x: scroll;
overflow-x-visibleoverflow-x: visible;
overflow-y-autooverflow-y: auto;
overflow-y-hiddenoverflow-y: hidden;
overflow-y-scrolloverflow-y: scroll;
overflow-y-visibleoverflow-y: visible;

Overscroll Behavior

Name PrefixCSS Property
overscroll-autooverscroll-behavior: auto;
overscroll-containoverscroll-behavior: contain;
overscroll-noneoverscroll-behavior: none;
overscroll-x-autooverscroll-behavior-x: auto;
overscroll-x-containoverscroll-behavior-x: contain;
overscroll-x-noneoverscroll-behavior-x: none;
overscroll-y-autooverscroll-behavior-y: auto;
overscroll-y-containoverscroll-behavior-y: contain;
overscroll-y-noneoverscroll-behavior-y: none;

Position

Name PrefixCSS Property
absoluteposition: absolute;
fixedposition: fixed;
relativeposition: relative;
staticposition: static;
stickyposition: sticky;
inset-0bottom: 0; left: 0; right: 0; top: 0;
inset-autobottom: auto; left: auto; right: auto; top: auto;
inset-x-0left: 0; right: 0;
inset-x-autoleft: auto; right: auto;
inset-y-0bottom: 0; top: 0;
inset-y-autobottom: auto; top: auto;
bottom-{s}top: {s}; where s is 0 or auto
left-{s}left: {s}; where s is 0 or auto
right-{s}right: {s}; where s is 0 or auto
top-{s}top: {s}; where s is 0 or auto

Sizing

Name PrefixCSS Property
h-{n}height: {n}*0.25rem;
where n is 0 to 8, 10, 12, 16, or 20
w-{n}width: {n}*0.25rem;
where n is 0 to 8, 10, 12, 16, or 20
max-h-fullmax-height: 100%;
max-h-screenmax-height: 100vh;
max-w-nonemax-width: none;
max-w-xsmax-width: 20rem;
max-w-smmax-width: 24rem;
max-w-mdmax-width: 28rem;
max-w-lgmax-width: 32rem;
max-w-xlmax-width: 36rem;
max-w-2xlmax-width: 42rem;
max-w-3xlmax-width: 48rem;
max-w-4xlmax-width: 56rem;
max-w-5xlmax-width: 64rem;
max-w-6xlmax-width: 72rem;
max-w-fullmax-width: 100%;
min-h-0min-height: 0;
min-h-fullmin-height: 100%;
min-h-screenmin-height: 100vh;
min-w-0min-width: 0;
min-w-fullmin-width: 100%;

Spacing

Name PrefixCSS Properties
m-{n}margin: {n}*0.25rem;
where n is 0 to 8, 10, 12, 16, or 20
ml-*margin-left: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
mr-*margin-right: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
mt-*margin-top: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
mx-*margin-left: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
my-*margin-bottom: {n}*0.25rem; margin-top: {n}*0.25rem;
where n = 0, 1, or 2
p-{n}padding: {n}*0.25rem;
where n is 0 to 8, 10, 12, 16, or 20
pl-*padding-left: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
pr-*padding-right: {n}*0.25rem; margin-right: {n}*0.25rem;
where n = 0, 1, or 2
px-*padding-left: {n}*0.25rem; padding-right: {n}*0.25rem;
where n = 0, 1, or 2
py-*padding-bottom: {n}*0.25rem; padding-top: {n}*0.25rem;
where n = 0, 1, or 2
space-x-{n}margin-left: {n}*0.25rem;
where n is 0 to 5
space-y-{n}margin-top: {n}*0.25rem;
where n is 0 to 5

SVG

Name PrefixCSS Property
fill-currentfill: currentColor;
stroke-currentstroke: currentColor;
stroke-{n}stroke-width: {n}; where n is 0, 1, or 2

Tables

Name PrefixCSS Property
border-collapseborder-collapse: collapse;
border-separateborder-collapse: separate;
table-autotable-layout: auto;
table-fixedtable-layout: fixed;

Transforms

For all the classes in this section, n can be 0, 50, 75, 90, 95, 100, 105, 110, 125, or 150.

Name PrefixCSS Property
scale-{n}--transform-scale-x: {n}/100; --transform-scale-y: {n}/100;
scale-x-{n}--transform-scale-x: {n}/100;
scale-y-{n}--transform-scale-y: {n}/100;
rotate-{n}--transform-rotate: {n}deg;
where n is 0, 45, 90, or 180
-rotate-{n}--transform-rotate: -{n}deg;
where n is 45, 90, or 180
translate-x-px--transform-translate-x: 1px;
-translate-x-px--transform-translate-x: -1px;
translate-x-{n}--transform-translate-x: {n}*0.25rem;
where n is 0 to 8, 10, 12, 16, 20, 24, 32, 40, 48, 56, or 64
-translate-x-{n}--transform-translate-x: -{n}*0.25rem;
where n is 1 to 8, 10, 12, 16, 20, 24, 32, 40, 48, 56, or 64
translate-x-full--transform-translate-x: 100%;
-translate-x-full--transform-translate-x: -100%;
translate-x-1/2--transform-translate-x: 50%;
-translate-x-1/2--transform-translate-x: -50%;
translate-y-{above}--transform-translate-y: ...;
all the same variations as for x above
skew-x-{n}--transform-skew-x: {n}deg;
where n is 0, 3, 6, or 12
-skew-x-{n}--transform-skew-x: {n}deg;
where n is 3, 6, or 12
skew-y-{n}--transform-skew-y: ...;
all the same variations as for x above
origin-bottom-righttransform-origin: bottom right;
origin-bottomtransform-origin: bottom;
origin-centertransform-origin: center;
origin-lefttransform-origin: left;
origin-righttransform-origin: right;
origin-top-lefttransform-origin: top left;
origin-top-righttransform-origin: top right;
origin-toptransform-origin: top;

Transitions and Animation

The Tailwind transition-*, ease-*, and duration-* classes can be combined to easily create transitions from one CSS property value to another. For example, the following set of Tailwind classes on a button cause it to transition from having a red border and light red background to a green border and light green background on hover. The size of the button also increases slightly on hover.

<button className="
border-2 px-2 py-1 rounded-full
border-red-700 bg-red-300
hover:border-green-700 hover:bg-green-300 hover:scale-110
transition ease-linear duration-500
">
Press Me
</button>

The animation and @keyframe values set by the animate classes are somewhat complicated. For details see the Animation docs.

Name PrefixCSS Property
transitiontransition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow, transform;
transition-alltransition-property: all;
transition-colorstransition-property: background-color, border-color, color, fill, stroke;
transition-nonetransition-property: none;
transition-opacitytransition-property: opacity;
transition-shadowtransition-property: box-shadow;
transition-transformtransition-property: transform;
duration-{n}transition-duration: {n}ms;
where n is 75, 100, 150, 200, 300, 500, 700, or 1000
ease-lineartransition-timing-function: linear;
ease-intransition-timing-function: cubic-bezier(0.4, 0, 1, 1);
ease-outtransition-timing-function: cubic-bezier(0, 0, 0.2, 1);
ease-in-outtransition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
delay-{n}transition-delay: {n}ms;
where n is 75, 100, 150, 200, 300, 500, 700, or 1000
animate-noneanimation: none;
animate-{effect}animation: {effect} ...; @keyframes {effect} {...}
where effect is bounce, ping, pulse or, spin; see docs

Typography/Fonts

In the class name text-{color}-{n}, a number is required at the end. For example, text-red is not a valid Tailwind CSS class name.

Name PrefixCSS Property
font-sansfont-family: boatload of san serif fonts;
includes Arial
font-seriffont-family: boatload of serif fonts;
includes Times New Roman
font-monofont-family: boatload of monospace fonts;
includes Courier New
text-xsfont-size: 0.75rem;
text-smfont-size: 0.875rem;
text-basefont-size: 1rem;
Why not named text-md?
text-lgfont-size: 1.125rem;
text-xlfont-size: 1.25rem;
text-2xlfont-size: 1.5rem;
text-3xlfont-size: 1.875rem;
text-4xlfont-size: 2.25rem;
text-5xlfont-size: 3rem;
text-6xlfont-size: 4rem;
antialiasedfont-smoothing
with vendor-specific prefixes and values
subpixel-antialiasedfont-smoothing: antialiased;
with vendor-specific prefixes and values
italicfont-style: italic;
not-italicfont-style: normal;
odd class name!
font-hairlinefont-weight: 100;
font-thinfont-weight: 200;
font-lightfont-weight: 300;
font-normalfont-weight: 400;
font-mediumfont-weight: 500;
font-semiboldfont-weight: 600;
font-boldfont-weight: 700;
font-extraboldfont-weight: 800;
font-blackfont-weight: 900;
normal-numsfont-variant-numeric: normal;
ordinalfont-variant-numeric: ordinal;
slashed-zerofont-variant-numeric: slashed-zero;
lining-numsfont-variant-numeric: lining-nums;
oldstyle-numsfont-variant-numeric: oldstyle-nums;
proportional-numsfont-variant-numeric: proportional-nums;
tabular-numsfont-variant-numeric: tabular-nums;
diagonal-fractionsfont-variant-numeric: diagonal-fractions;
stacked-fractionsfont-variant-numeric: stacked-fractions;
tracking-tighterletter-spacing: -0.05em;
tracking-tightletter-spacing: -0.025em;
tracking-normalletter-spacing: 0em;
tracking-wideletter-spacing: 0.025em;
tracking-widerletter-spacing: 0.05em;
tracking-widestletter-spacing: 0.1em;
leading-{n}line-height: {n}*0.25rem;
where n = 3 to 10
leading-noneline-height: 1;
leading-tightline-height: 1.25rem;
leading-snugline-height: 1.375rem;
leading-normalline-height: 1.5rem;
list-nonelist-style-type: none;
list-disclist-style-type: disc;
list-decimallist-style-type: decimal;
list-insidelist-style-position: inside;
list-outsidelist-style-position: outside;
placeholder-transparentcolor: transparent;
placeholder-currentcolor: currentColor;
placeholder-blackcolor: #000;
placeholder-whitecolor: #fff;
placeholder-{color}-{n}color: {color-hex-code};
where n is 100 to 900 in increments of 100
placeholder-opacity-{n}--placeholder-opacity: {n}/100;
where n = 0, 25, 50, 75, or 100
text-centertext-align: center;
text-justifytext-align: justify;
text-lefttext-align: left;
text-righttext-align: right;
text-currentcolor: currentColor;
text-blackcolor: #000;
text-whitecolor: #fff;
text-transparentcolor: transparent;
text-{color}-{n}color: {color-hex-code};
where n is 100 to 900 in increments of 100
text-slate-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-gray-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-zinc-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-neutral-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-stone-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-red-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-orange-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-amber-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-yellow-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-lime-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-green-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-emerald-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-teal-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-cyan-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-sky-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-blue-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-indigo-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-violet-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-purple-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-fuchsia-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-pink-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-rose-ncolor: #X;
where X is 50, 950, or a multiple of 100
text-opacity-{n}--text-opacity: {n}/100;
where n is 0, 25, 50, 75, or 100
line-throughtext-decoration: line-through;
no-underlinetext-decoration: none;
underlinetext-decoration: underline;
capitalizetext-transform: capitalize;
lowercasetext-transform: lowercase;
normal-casetext-transform: none;
uppercasetext-transform: uppercase;
align-baselinevertical-align: baseline;
align-bottomvertical-align: bottom;
align-middlevertical-align: middle;
align-text-bottomvertical-align: text-bottom;
align-text-topvertical-align: text-top;
align-topvertical-align: top;
whitespace-no-wrapwhite-space: nowrap;
whitespace-normalwhite-space: normal;
whitespace-pre-linewhite-space: pre-line;
whitespace-pre-wrapwhite-space: pre-wrap;
whitespace-prewhite-space: pre;
break-allword-break: break-all;
break-normaloverflow-wrap: normal; word-break: normal;
break-wordsoverflow-wrap: break-word;
truncateoverflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

Visibility

Name PrefixCSS Property
invisiblevisibility: hidden;
visiblevisibility: visible;

Z-Index

Name PrefixCSS Property
z-{n}z-index: {n};
where n is 0, 10, 20, 30, 40, or 50
z-autoz-index: auto;

HyperUI

HyperUI is a collection of free UI components defined with Tailwind CSS classes and optionally AlpineJS directives.

There is no need to install anything. Just find a component to use from the website, copy its code, and paste in into your project.

Components are defined in a large number of categories including Auth Forms, Alerts, Badges, Breadcrumbs, Button Groups, Details Lists, Dividers, Dropdowns, Error Pages, Grids, Header, Inputs, Media, Pagination, Progress, Radio Groups, Selects, Side Menu, Stats, Steps, Tables, Tabs, Textareas, Toggles, and Vertical Menu.

There are also components that are specialized for eCommerce and Marketing.

Here is an example of a Toggle that only uses Tailwind classes:

<label
for="AcceptConditions"
class="relative h-8 w-14 cursor-pointer [-webkit-tap-highlight-color:_transparent]"
>

<input type="checkbox" id="AcceptConditions" class="peer sr-only" />

<span
class="absolute inset-0 rounded-full bg-gray-300 transition peer-checked:bg-green-500"
>
</span>

<span
class="absolute inset-y-0 start-0 m-1 h-6 w-6 rounded-full bg-white transition-all peer-checked:start-6"
>
</span>
</label>

This code can be placed in a component for the specific framework being used (such as Astro or Svelte) to avoid pasting the same code in multiple places.