Socket
Socket
Sign inDemoInstall

@tailwindcss/forms

Package Overview
Dependencies
128
Maintainers
5
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @tailwindcss/forms

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


Version published
Weekly downloads
1.4M
increased by4.8%
Maintainers
5
Install size
59.3 kB
Created
Weekly downloads
 

Package description

What is @tailwindcss/forms?

The @tailwindcss/forms plugin is a Tailwind CSS plugin that provides a basic reset for form styles that makes form elements easy to override with utilities. It helps in creating consistent and customizable forms with Tailwind CSS utility classes.

What are @tailwindcss/forms's main functionalities?

Form Inputs Styling

This feature allows you to style form inputs such as text fields, making them more consistent and visually appealing across different browsers.

<input class='block w-full px-4 py-2 mt-2 text-gray-700 bg-white border border-gray-300 rounded-md focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50' type='text' placeholder='Full name'>

Checkbox and Radio Buttons Styling

With this feature, you can apply Tailwind CSS styles to checkboxes and radio buttons to make them match the overall design of your site.

<input type='checkbox' class='w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500'>

Select Dropdown Styling

This feature allows you to style select dropdowns with Tailwind CSS, providing a more consistent and customizable appearance.

<select class='block w-full px-4 py-2 mt-2 text-gray-700 bg-white border border-gray-300 rounded-md focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50'><option>Option 1</option><option>Option 2</option></select>

File Input Styling

This feature enables you to style file inputs with Tailwind CSS, making them blend in with the rest of your form elements.

<input type='file' class='block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-violet-50 file:text-violet-700 hover:file:bg-violet-100'>

Other packages similar to @tailwindcss/forms

Readme

Source

@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="px-4 py-3 rounded-full">
  <!-- ... -->
</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 px-4 py-3 rounded-full">

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

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

Here is a complete table of the provided form-* 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 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.

FAQs

Last updated on 10 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc