Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tailwindcss/forms

tailwindlabs7.7mMIT0.5.10TypeScript support: included

A plugin that provides a basic reset for form styles that makes form elements easy to override with utilities.

readme

@tailwindcss/forms

A plugin that provides a basic reset for form styles that makes form elements easy to override with utilities.

Installation

Install the plugin from npm:

npm install -D @tailwindcss/forms

Then add the plugin to your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/forms'),
    // ...
  ],
}

Basic usage

View the live demo

All of the basic form elements you use will now have some simple default styles that are easy to override with utilities.

Currently we add basic utility-friendly form styles for the following form element types:

  • input[type='text']
  • input[type='password']
  • input[type='email']
  • input[type='number']
  • input[type='url']
  • input[type='date']
  • input[type='datetime-local']
  • input[type='month']
  • input[type='week']
  • input[type='time']
  • input[type='search']
  • input[type='tel']
  • input[type='checkbox']
  • input[type='radio']
  • select
  • select[multiple]
  • textarea

Every element has been normalized/reset to a simple visually consistent style that is easy to customize with utilities, even elements like <select> or <input type="checkbox"> that normally need to be reset with appearance: none and customized using custom CSS:

<!-- You can actually customize padding on a select element now: -->
<select class="rounded-full px-4 py-3">
  <!-- ... -->
</select>

<!-- Or change a checkbox color using text color utilities: -->
<input type="checkbox" class="rounded text-pink-500" />

More customization examples and best practices coming soon.

Using classes to style

In addition to the global styles, we also generate a set of corresponding classes which can be used to explicitly apply the form styles to an element. This can be useful in situations where you need to make a non-form element, such as a <div>, look like a form element.

<input type="email" class="form-input rounded-full px-4 py-3" />

<select class="form-select rounded-full px-4 py-3">
  <!-- ... -->
</select>

<input type="checkbox" class="form-checkbox rounded text-pink-500" />

Here is a complete table of the provided form-* classes for reference:

Base Class
[type='text'] form-input
[type='email'] form-input
[type='url'] form-input
[type='password'] form-input
[type='number'] form-input
[type='date'] form-input
[type='datetime-local'] form-input
[type='month'] form-input
[type='search'] form-input
[type='tel'] form-input
[type='time'] form-input
[type='week'] form-input
textarea form-textarea
select form-select
select[multiple] form-multiselect
[type='checkbox'] form-checkbox
[type='radio'] form-radio

Using only global styles or only classes

Although we recommend thinking of this plugin as a "form reset" rather than a collection of form component styles, in some cases our default approach may be too heavy-handed, especially when integrating this plugin into existing projects.

If generating both the global (base) styles and classes doesn't work well with your project, you can use the strategy option to limit the plugin to just one of these approaches.

// tailwind.config.js
plugins: [
  require("@tailwindcss/forms")({
    strategy: 'base', // only generate global styles
    strategy: 'class', // only generate classes
  }),
],

When using the base strategy, form elements are styled globally, and no form-{name} classes are generated.

When using the class strategy, form elements are not styled globally, and instead must be styled using the generated form-{name} classes.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

  • Nothing yet!

0.5.10 - 2025-01-07

Fixed

  • Support installing with beta versions of Tailwind CSS v4 (#163)

0.5.9 - 2024-09-05

Fixed

  • Fallback to static chevron color if theme is using variables (#167)

0.5.8 - 2024-08-28

Fixed

  • Support installing with alpha versions of Tailwind CSS v4 (#163)

0.5.7 - 2023-11-10

Fixed

  • Use normal checkbox and radio appearance in forced-colors mode (#152)

0.5.6 - 2023-08-28

Fixed

  • Fix date time bottom spacing on MacOS Safari (#146)

0.5.5 - 2023-08-22

Fixed

  • Fix text alignment on date and time inputs on iOS (#144)

0.5.4 - 2023-07-13

Fixed

  • Remove chevron for selects with a non-default size (#137)
  • Allow for <input> without type (#141)

0.5.3 - 2022-09-02

Fixed

  • Update TypeScript types (#126)

0.5.2 - 2022-05-18

Added

  • Add TypeScript type declarations (#118)

0.5.1 - 2022-05-03

Fixed

  • Remove duplicate outline property (#116)
  • Fix autoprefixer warning about color-adjust (#115)

0.5.0 - 2022-03-02

Changed

  • Generate both global styles and classes by default (#71)

0.4.1 - 2022-03-02

Added

  • Remove dist folder and related dependencies (#96)

Fixed

  • Use addComponents for class strategy (#91)
  • Fix extra height on Safari date/time inputs (#109)

0.4.0 - 2021-12-09

Changed

  • Update color palette references for v3 (#83)
  • Don't read outline.none value from config (#89)

0.3.4 - 2021-09-28

Fixed

  • Fix compatibility with optimizeUniversalDefaults experimental feature in Tailwind CSS v2.2 (#81)

0.3.3 - 2021-06-03

Fixed

  • Fix typo in selector when using class strategy that breaks background colors on checkboxes and radio buttons (#72)

0.3.2 - 2021-03-26

Fixed

  • Filter null rules for JIT compatibility (b4c4e03)

0.3.1 - 2021-03-26

Fixed

  • Use base as default strategy, not class (#61)

0.3.0 - 2021-03-25

Added

  • Add class strategy for you babies and your custom select and date picker libraries ;) (#39)

0.2.1 - 2020-11-17

Fixed

  • Fix issue where default checkbox/radio border color took precedence over user border color on focus (d0b9fd9)

0.2.0 - 2020-11-16

Changed

  • Update form styles to be less opinionated and encourage custom styling (3288709)
  • Update custom property names to match namespaced variables in Tailwind CSS v2.0 (adb9807, bbd8510)

0.1.4 - 2020-11-12

Fixed

  • Fix SVG background images not rendering properly in all browsers (#5)

0.1.3 - 2020-11-12

Changed

  • Update focus styles to account for changes to ring API in latest Tailwind CSS 2.0 alpha (5c16689)

0.1.2 - 2020-11-11

Fixed

  • Work around iOS Safari bug that causes date inputs to render with no height when empty (b98365b)

0.1.1 - 2020-11-11

Changed

  • Move tailwindcss to dependencies, hoping to get it working with Tailwind Play (d625ea1)

0.1.0 - 2020-11-11

Initial release!