Convert Figma logo to code with AI

tailwindlabs logotailwindcss-custom-forms

A better base for styling form elements with Tailwind CSS.

1,547
69
1,547
45

Top Related Projects

31,532

A rugged, minimal framework for composing JavaScript behavior in your markup.

4,735

The form framework for coding agents

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.

📋 React Hooks for form state management and validation (Web + React Native)

34,369

Build forms in React, without the tears 😭

4,408

Performance-focused API for React forms 🚀

Quick Overview

The tailwindlabs/tailwindcss-custom-forms project is a Tailwind CSS plugin that provides a set of utility classes to style form elements in a consistent and customizable way. It aims to address the common challenges of styling form elements across different browsers and platforms.

Pros

  • Consistent Styling: The plugin provides a set of utility classes that ensure consistent styling of form elements across different browsers and platforms.
  • Customizable: The plugin allows for easy customization of the form element styles, enabling developers to match the design of their application.
  • Integrates with Tailwind CSS: The plugin seamlessly integrates with the Tailwind CSS framework, allowing developers to leverage the existing utility classes and workflow.
  • Actively Maintained: The project is actively maintained by the Tailwind CSS team, ensuring regular updates and bug fixes.

Cons

  • Dependency on Tailwind CSS: The plugin requires the use of the Tailwind CSS framework, which may not be suitable for all projects.
  • Limited Functionality: The plugin focuses on styling form elements and does not provide additional functionality, such as form validation or submission handling.
  • Potential Learning Curve: Developers who are not familiar with Tailwind CSS may need to invest time in learning the framework and the plugin's usage.
  • Potential Performance Impact: The addition of the plugin's utility classes may increase the overall size of the CSS bundle, which could impact the performance of the application.

Code Examples

Here are a few examples of how to use the tailwindlabs/tailwindcss-custom-forms plugin:

  1. Styling a Text Input:
<input
  type="text"
  class="form-input"
  placeholder="Enter your name"
/>
  1. Styling a Checkbox:
<div class="form-checkbox">
  <input type="checkbox" id="remember-me" />
  <label for="remember-me">Remember me</label>
</div>
  1. Styling a Radio Button:
<div class="form-radio">
  <input type="radio" name="gender" id="male" value="male" />
  <label for="male">Male</label>
</div>
<div class="form-radio">
  <input type="radio" name="gender" id="female" value="female" />
  <label for="female">Female</label>
</div>
  1. Styling a Select Dropdown:
<select class="form-select">
  <option>Select an option</option>
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
</select>

Getting Started

To get started with the tailwindlabs/tailwindcss-custom-forms plugin, follow these steps:

  1. Install the plugin using npm or yarn:
npm install @tailwindcss/forms

or

yarn add @tailwindcss/forms
  1. Add the plugin to your Tailwind CSS configuration file (tailwind.config.js):
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/forms'),
  ],
}
  1. Start using the plugin's utility classes in your HTML:
<input
  type="text"
  class="form-input"
  placeholder="Enter your name"
/>
  1. Customize the plugin's styles by overriding the default styles in your CSS:
@tailwind base;
@tailwind components;
@tailwind utilities;

.form-input {
  /* Custom styles for the form input */
  border-color: #4a5568;
  border-width: 2px;
  padding: 0.5rem 1rem;
}

That's it! You can now start using the tailwindlabs/tailwindcss-custom-forms plugin to style your form elements in a consistent and customizable way.

Competitor Comparisons

31,532

A rugged, minimal framework for composing JavaScript behavior in your markup.

Pros of Alpine

  • Lightweight and minimal JavaScript framework
  • Easy to learn and integrate into existing projects
  • Provides reactive and declarative nature for building interactive UIs

Cons of Alpine

  • Limited to DOM manipulation and basic interactivity
  • May require additional libraries for complex applications
  • Not as feature-rich as full-fledged JavaScript frameworks

Code Comparison

Alpine:

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <span x-show="open">Content</span>
</div>

Tailwind CSS Custom Forms:

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

Key Differences

  • Alpine is a JavaScript framework for adding interactivity, while Tailwind CSS Custom Forms is a plugin for styling form elements
  • Alpine focuses on behavior and reactivity, whereas Tailwind CSS Custom Forms emphasizes appearance and styling
  • Alpine can be used across various UI elements, while Tailwind CSS Custom Forms is specifically designed for form inputs

Use Cases

  • Alpine: Building interactive components, dropdowns, modals, and dynamic UI elements
  • Tailwind CSS Custom Forms: Consistent and customizable styling for form inputs, selects, and other form elements
4,735

The form framework for coding agents

Pros of FormKit

  • More comprehensive form building solution with built-in validation and error handling
  • Offers a wider range of pre-built form components and input types
  • Provides a plugin system for easy extensibility and customization

Cons of FormKit

  • Steeper learning curve due to its more complex API and configuration options
  • Potentially larger bundle size compared to the lightweight Tailwind CSS approach
  • May require additional setup and integration steps in existing projects

Code Comparison

FormKit:

<FormKit
  type="text"
  name="username"
  label="Username"
  validation="required|length:3,16"
/>

tailwindcss-custom-forms:

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

FormKit provides a more declarative approach with built-in validation, while tailwindcss-custom-forms relies on Tailwind CSS classes for styling and requires separate validation implementation.

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.

Pros of Headless UI

  • Provides fully accessible, unstyled UI components
  • Offers more complex, interactive components like dropdowns and modals
  • Designed to work seamlessly with Tailwind CSS

Cons of Headless UI

  • Requires more setup and customization for basic form elements
  • May have a steeper learning curve for beginners
  • Less focused on form-specific styling

Code Comparison

Tailwindcss-custom-forms:

<input class="form-input mt-1 block w-full" type="text" placeholder="Enter your name">

Headless UI:

<Listbox value={selected} onChange={setSelected}>
  <Listbox.Button>{selected.name}</Listbox.Button>
  <Listbox.Options>
    {people.map((person) => (
      <Listbox.Option key={person.id} value={person}>
        {person.name}
      </Listbox.Option>
    ))}
  </Listbox.Options>
</Listbox>

Tailwindcss-custom-forms focuses on enhancing basic form elements with consistent styling, while Headless UI provides more complex, unstyled components that can be customized extensively. Headless UI offers greater flexibility and accessibility but requires more effort to style and implement. Tailwindcss-custom-forms is simpler to use for basic form styling needs but lacks the advanced interactive features of Headless UI.

📋 React Hooks for form state management and validation (Web + React Native)

Pros of react-hook-form

  • More focused on form handling and validation in React applications
  • Provides a complete solution for managing form state and submissions
  • Offers better performance with minimal re-renders

Cons of react-hook-form

  • Limited to React applications, not usable with other frameworks
  • Requires learning a specific API and concepts
  • May be overkill for simple forms or projects

Code Comparison

react-hook-form:

import { useForm } from "react-hook-form";

const { register, handleSubmit } = useForm();
const onSubmit = data => console.log(data);

<form onSubmit={handleSubmit(onSubmit)}>
  <input {...register("firstName")} />
  <input type="submit" />
</form>

tailwindcss-custom-forms:

<form>
  <input class="form-input px-4 py-3 rounded-full" />
  <button class="form-button px-4 py-3 rounded-full">Submit</button>
</form>

tailwindcss-custom-forms focuses on styling form elements using Tailwind CSS classes, while react-hook-form provides a comprehensive solution for form handling in React applications. The choice between the two depends on whether you need form logic and state management (react-hook-form) or just custom styling for form elements (tailwindcss-custom-forms).

34,369

Build forms in React, without the tears 😭

Pros of Formik

  • Comprehensive form management solution for React applications
  • Handles form state, validation, and submission out of the box
  • Integrates well with popular validation libraries like Yup

Cons of Formik

  • Steeper learning curve for beginners compared to simple CSS solutions
  • Requires additional JavaScript code to implement form functionality
  • May be overkill for simple forms or projects with minimal form requirements

Code Comparison

Formik:

<Formik
  initialValues={{ email: '', password: '' }}
  onSubmit={(values) => handleSubmit(values)}
>
  {({ values, handleChange, handleSubmit }) => (
    <form onSubmit={handleSubmit}>
      <input
        type="email"
        name="email"
        value={values.email}
        onChange={handleChange}
      />
      <input
        type="password"
        name="password"
        value={values.password}
        onChange={handleChange}
      />
      <button type="submit">Submit</button>
    </form>
  )}
</Formik>

Tailwindcss-custom-forms:

<form>
  <input type="email" class="form-input" />
  <input type="password" class="form-input" />
  <button type="submit" class="form-submit">Submit</button>
</form>

The Formik example demonstrates its form management capabilities, while Tailwindcss-custom-forms focuses on styling form elements using utility classes.

4,408

Performance-focused API for React forms 🚀

Pros of unform

  • Provides a complete form management solution for React applications
  • Offers advanced features like schema validation and custom field components
  • Supports multiple UI libraries and frameworks

Cons of unform

  • Steeper learning curve due to its comprehensive nature
  • May be overkill for simple form implementations
  • Requires additional setup and configuration

Code Comparison

unform:

import { Form } from '@unform/web';
import Input from './components/Input';

function MyForm() {
  return (
    <Form onSubmit={handleSubmit}>
      <Input name="email" />
      <button type="submit">Submit</button>
    </Form>
  );
}

tailwindcss-custom-forms:

<form>
  <input class="form-input px-4 py-3 rounded-full" type="email">
  <button class="btn btn-blue" type="submit">Submit</button>
</form>

Summary

unform is a comprehensive form management solution for React applications, offering advanced features and flexibility. It's well-suited for complex form implementations but may be excessive for simpler use cases. tailwindcss-custom-forms, on the other hand, focuses on providing customizable form styles using Tailwind CSS classes, making it easier to implement visually appealing forms with less setup. The choice between the two depends on the project's specific requirements and complexity.

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

This project is not compatible with Tailwind CSS v2.0+ and has been deprecated in favor of @tailwindcss/forms.

You can still use this if you are on Tailwind CSS v1.x, but we recommend updating to v2.0 and migrating to @tailwindcss/forms if possible.


Tailwind CSS Custom Forms

Out of the box, selects, checkboxes, and radios look awful in Tailwind and the only way to make them look better is with custom CSS.

The goal of this project is to provide a better starting point for form elements that is still fairly unopinionated, and easy to customize by adding utilities instead of having to write complicated CSS rules.

Demo

Screenshot

Install

  1. Install the plugin:
# Using npm
npm install @tailwindcss/custom-forms --save-dev

# Using Yarn
yarn add @tailwindcss/custom-forms -D
  1. Add it to your tailwind.config.js file:
// tailwind.config.js
module.exports = {
  // ...
  plugins: [
    require('@tailwindcss/custom-forms')
  ]
}

Documentation

The project is still early but basic documentation can be found here:

Read the documentation

Local development

  1. Clone the repository:

    git clone https://github.com/tailwindcss/custom-forms.git tailwindcss-custom-forms
    
    cd tailwindcss-custom-forms
    
  2. Install the dependencies:

    # Using npm
    npm install
    
    # Using Yarn
    yarn
    
  3. Start the development server:

    # Using npm
    npm run dev
    
    # Using Yarn
    yarn run dev
    

    Now you should be able to see the demo/docs running at localhost:3000.

NPM DownloadsLast 30 Days