Automatically format and organize Tailwind CSS classes by categories with responsive grouping.
Features
- ✅ Groups Tailwind classes by categories (layout, spacing, typography, background, borders, effects)
- ✅ Groups responsive variants with their base classes (e.g.,
pt-4 sm:pt-6 md:pt-8)
- ✅ Orders responsive breakpoints correctly (base → sm → md → lg → xl → 2xl)
- ✅ Automatic formatting on save
- ✅ Automatic formatting on paste
- ✅ Manual format command
- ✅ Configurable line width with smart wrapping
- ✅ Customizable indentation styles
- ✅ Works with both
class (HTML) and className (React/JSX)
Demo
Before:
<div class="pt-4 bg-gray-100 sm:pt-6 px-2 lg:pt-8 md:px-4 text-lg dark:bg-gray-800">
After:
<div
class="
pt-4 sm:pt-6 lg:pt-8 px-2 md:px-4
text-lg
bg-gray-100 dark:bg-gray-800
"
>
Usage
The extension will automatically format your Tailwind classes when:
- Saving the file (if
formatOnSave is enabled)
- Pasting content (if
formatOnPaste is enabled)
Manual Command
- Open the Command Palette (
Ctrl+Shift+P or Cmd+Shift+P on Mac)
- Search for "Format Tailwind CSS Classes"
- Press Enter
Or use a keyboard shortcut (you can configure this in VSCode's Keyboard Shortcuts).
Configuration
Access settings via File > Preferences > Settings and search for "Tailwind Formatter".
| Setting |
Type |
Default |
Description |
tailwindFormatter.formatOnSave |
boolean |
true |
Format classes when saving the file |
tailwindFormatter.formatOnPaste |
boolean |
true |
Format classes when pasting content |
tailwindFormatter.closeQuoteOnNewLine |
boolean |
true |
Place the closing quote on a new line |
tailwindFormatter.maxLineWidth |
number |
80 |
Maximum line width before wrapping (0 = no limit) |
tailwindFormatter.wrapIndentStyle |
string |
"same" |
Indentation style for wrapped lines: "same" or "extra" |
Configuration Examples
{
"tailwindFormatter.formatOnSave": true,
"tailwindFormatter.maxLineWidth": 80,
"tailwindFormatter.wrapIndentStyle": "same",
"tailwindFormatter.closeQuoteOnNewLine": true
}
{
"tailwindFormatter.maxLineWidth": 0,
"tailwindFormatter.closeQuoteOnNewLine": false
}
{
"tailwindFormatter.wrapIndentStyle": "extra"
}
How It Works
The extension organizes Tailwind classes in the following order:
- Layout -
flex, grid, block, inline, hidden, absolute, relative, etc.
- Sizing -
w-*, h-*, min-w-*, max-w-*, etc.
- Spacing -
p-*, m-*, px-*, py-*, pt-*, etc.
- Typography -
text-*, font-*, leading-*, tracking-*, etc.
- Background -
bg-*, from-*, via-*, to-*, etc.
- Borders -
border-*, rounded-*, ring-*, outline-*, etc.
- Effects -
shadow-*, opacity-*, transition-*, animate-*, etc.
- Filters -
blur-*, brightness-*, contrast-*, etc.
- Transforms -
scale-*, rotate-*, translate-*, etc.
- Interactivity -
cursor-*, select-*, pointer-events-*, etc.
- SVG -
fill-*, stroke-*, etc.
- Accessibility -
sr-only, etc.
- Other - Any unrecognized classes
Variant Support
The formatter handles all types of variants:
- Responsive:
sm:, md:, lg:, xl:, 2xl:
- Dark mode:
dark:
- Hover/Focus:
hover:, focus:, active:
- Combined:
dark:hover:sm:bg-gray-100
Examples
Complex Example with Multiple Categories
Input:
<button class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded shadow-lg transition duration-300 ease-in-out transform hover:scale-105">
Output:
<button
class="
py-2 px-4
text-white font-bold
bg-blue-500 hover:bg-blue-600
rounded
shadow-lg transition duration-300 ease-in-out
transform hover:scale-105
"
>
Responsive Design Example
Input:
<div class="p-4 sm:p-6 md:p-8 lg:p-10 text-sm sm:text-base md:text-lg lg:text-xl bg-white dark:bg-gray-900">
Output:
<div
class="
p-4 sm:p-6 md:p-8 lg:p-10
text-sm sm:text-base md:text-lg lg:text-xl
bg-white dark:bg-gray-900
"
>
Known Limitations
- Only works with
class="..." and className="..." attributes
- Does not format classes in template literals or dynamic class strings
- Requires classes to be in a single string (doesn't support spread syntax)
Requirements
- Visual Studio Code 1.85.0 or higher
Contributing
Found a bug or have a feature request? Please open an issue on GitHub.
License
See LICENSE for details.
Release Notes
See CHANGELOG.md for details.
Enjoy! 🎉
| |