Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

tailwindlabs/tailwindcss-forms

Repository files navigation

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, when using Tailwind CSS v4, add the plugin to your main stylesheet:

/* app.css */@import"tailwindcss";@plugin"@tailwindcss/forms";

If you are still usingTailwind CSS v3, add the plugin to yourtailwind.config.js file:

// tailwind.config.jsmodule.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 withappearance: none and customized using custom CSS:

<!-- You can actually customize padding on a select element now: --><selectclass="rounded-full px-4 py-3"><!-- ... --></select><!-- Or change a checkbox color using text color utilities: --><inputtype="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.

<inputtype="email"class="form-input rounded-full px-4 py-3"/><selectclass="form-select rounded-full px-4 py-3"><!-- ... --></select><inputtype="checkbox"class="form-checkbox rounded text-pink-500"/>

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

BaseClass
[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
textareaform-textarea
selectform-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 thestrategy option to limit the plugin to just one of these approaches.

When using Tailwind CSS v4, configure the plugin in your main stylesheet:

/* app.css */@plugin"@tailwindcss/forms" {strategy:"base";/* only generate global styles; or */strategy:"class";/* only generate classes */}

If you are still usingTailwind CSS v3, configure the plugin in yourtailwind.config.js file:

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

When using thebase strategy, form elements are styled globally, and noform-{name} classes are generated.

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors21


[8]ページ先頭

©2009-2025 Movatter.jp