Convert Figma logo to code with AI

tailwindlabs logotailwindcss-forms

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

4,196
221
4,196
4

Top Related Projects

Beautiful typographic defaults for HTML you don't control.

A plugin that provides utilities for visually truncating text after a fixed number of lines.

A plugin for Tailwind CSS v3.2+ that provides utilities for container queries.

33,595

๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ โ€ƒThe most popular, free and open-source Tailwind CSS component library

Quick Overview

Tailwind CSS Forms is a plugin that provides a basic reset for form styles that makes form elements easy to override with utilities. It's designed to work seamlessly with Tailwind CSS, providing a solid foundation for custom form designs without imposing opinionated styles.

Pros

  • Provides a consistent base styling for form elements across browsers
  • Easily customizable using Tailwind CSS utility classes
  • Lightweight and doesn't add unnecessary bloat to your stylesheets
  • Integrates seamlessly with existing Tailwind CSS projects

Cons

  • Requires Tailwind CSS to be installed and configured in your project
  • May require additional customization for more complex form designs
  • Limited to form-specific styling, not a comprehensive UI framework
  • Learning curve for developers new to Tailwind CSS ecosystem

Code Examples

  1. Basic form input styling:
<input type="text" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
  1. Custom checkbox styling:
<label class="inline-flex items-center">
  <input type="checkbox" class="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
  <span class="ml-2">Remember me</span>
</label>
  1. Styled select dropdown:
<select class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
</select>

Getting Started

  1. Install the plugin:
npm install -D @tailwindcss/forms
  1. Add the plugin to your tailwind.config.js file:
module.exports = {
  plugins: [
    require('@tailwindcss/forms'),
    // ...
  ],
}
  1. Use the plugin in your HTML:
<form>
  <input type="text" class="form-input px-4 py-3 rounded-full">
  <button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
    Submit
  </button>
</form>

Competitor Comparisons

Beautiful typographic defaults for HTML you don't control.

Pros of tailwindcss-typography

  • Focuses on enhancing the typography of content-heavy pages
  • Provides a set of ready-to-use styles for common HTML elements
  • Offers more customization options for typography-related styles

Cons of tailwindcss-typography

  • Limited to typography-related styles, not covering form elements
  • May require additional configuration for non-standard content structures
  • Potentially larger file size due to comprehensive typography styles

Code Comparison

tailwindcss-typography:

@layer base {
  h1 {
    @apply text-4xl font-bold mb-4;
  }
  p {
    @apply mb-4 leading-relaxed;
  }
}

tailwindcss-forms:

@layer base {
  [type='text'],
  [type='email'] {
    @apply border-gray-300 rounded-md shadow-sm;
  }
}

The tailwindcss-typography plugin focuses on enhancing the appearance of text content, while tailwindcss-forms is specifically designed to style form elements. Typography provides a more comprehensive set of styles for text-based elements, whereas Forms offers targeted styling for input fields and form controls. The choice between the two depends on the specific needs of your project, with Typography being more suitable for content-rich pages and Forms being ideal for projects with extensive form usage.

A plugin that provides utilities for visually truncating text after a fixed number of lines.

Pros of tailwindcss-line-clamp

  • Focused on a specific text truncation feature, making it lightweight and easy to implement
  • Provides a simple solution for limiting text to a specific number of lines
  • Compatible with responsive design, allowing different line clamp values for various screen sizes

Cons of tailwindcss-line-clamp

  • Limited in scope compared to tailwindcss-forms, which offers a broader range of form styling options
  • May require additional custom CSS for more complex text truncation scenarios
  • Less frequently updated, potentially leading to compatibility issues with newer Tailwind CSS versions

Code Comparison

tailwindcss-line-clamp:

<p class="line-clamp-3">
  This text will be truncated after three lines...
</p>

tailwindcss-forms:

<input type="text" class="form-input px-4 py-3 rounded-full">
<select class="form-select mt-1 block w-full">
  <option>Option 1</option>
  <option>Option 2</option>
</select>

The code examples demonstrate the simplicity of using tailwindcss-line-clamp for text truncation, while tailwindcss-forms provides more comprehensive styling options for form elements. tailwindcss-line-clamp focuses on a single utility class, whereas tailwindcss-forms offers a wider range of classes for various form components.

A plugin for Tailwind CSS v3.2+ that provides utilities for container queries.

Pros of tailwindcss-container-queries

  • Enables responsive design based on container size, not just viewport
  • Allows for more flexible and modular component design
  • Supports modern CSS container queries specification

Cons of tailwindcss-container-queries

  • Limited browser support compared to traditional media queries
  • Requires additional setup and configuration
  • May increase complexity for simpler layouts

Code Comparison

tailwindcss-container-queries:

<div class="@container">
  <div class="@lg:text-2xl @sm:text-base">
    Responsive text based on container size
  </div>
</div>

tailwindcss-forms:

<form>
  <input type="text" class="form-input px-4 py-3 rounded-full">
  <select class="form-select mt-1 block w-full">
    <option>Option 1</option>
    <option>Option 2</option>
  </select>
</form>

The tailwindcss-container-queries plugin focuses on container-based responsive design, while tailwindcss-forms provides default styling for form elements. The container queries plugin offers more flexibility in component-level responsiveness, but tailwindcss-forms simplifies form styling with pre-defined classes. Choose based on your project's specific needs: advanced responsive layouts or streamlined form design.

33,595

๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ ๐ŸŒผ โ€ƒThe most popular, free and open-source Tailwind CSS component library

Pros of daisyUI

  • Offers a comprehensive set of pre-built components and utility classes
  • Provides a theme system for easy customization and dark mode support
  • Includes interactive components like modals and dropdowns out of the box

Cons of daisyUI

  • May introduce additional complexity and increase bundle size
  • Less flexibility for custom designs compared to using Tailwind CSS directly
  • Potential learning curve for developers already familiar with Tailwind CSS

Code Comparison

tailwindcss-forms:

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

daisyUI:

<input type="text" class="input input-bordered w-full max-w-xs">

The tailwindcss-forms example uses Tailwind's utility classes directly, while daisyUI provides pre-styled components with fewer class names. daisyUI's approach can lead to cleaner HTML but may sacrifice some flexibility in customization.

Both libraries aim to enhance form styling in Tailwind CSS projects, but they take different approaches. tailwindcss-forms focuses on resetting and normalizing form elements, while daisyUI provides a complete component library with pre-designed styles. The choice between them depends on project requirements and developer preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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:

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.

NPM DownloadsLast 30 Days