Several months ago (at the time of writing), Tailwind CSS open-sourced its work on Tailwind CSS v4.0. (You can find it on GitHub here).
Recently, Tailwind announced a public beta for Tailwind CSS 4, and in this article I'll cover the highlights of the new version. So let's get started!
Tailwind has undergone a rework of its engine that drastically improves performance. Full builds are up to 5x faster, incremental builds up to 100x (you read that right) faster.
Tailwind v4 also has a unified toolchain. Remember having to install autoprefixer and postcss in all of your Tailwind projects? You won't have to anymore!
Taking an interesting approach to configuration, Tailwind is moving from JS config files to CSS config. This means you will configure plugins, themes, and other behavior directly in your CSS.
Tailwind is also getting support for the latest features in CSS.
Now, with the general changes out the way, let's see what specifically Tailwind is adding!
If you want to try Tailwind v4, view the getting started docs for v4 (beta).
If you want to easily upgrade your project, just run npx @tailwindcss/upgrade@next and Tailwind will do it for you. Be careful! There may be breaking changes.
The Tailwind v4 color palette is based on oklch instead of rgb. The RGB color system is a bit limiting in terms of consistency across screens and vibrancy. Since the oklch color system is now widely supported, Tailwind v4 is going to take advantage of it!
Tailwind v4 now supports container queries by default. If you don't know what container queries are, let me explain.
You know things in Tailwind like md:, sm:, etc. that allow you to customize what CSS is applied on different screen sizes?
In those cases, the classes refer to the size of a window. With container queries, they can refer to the size of a container instead.
In the above example, the grid will have 3 columns — not when the window reaches the small size, but when the container does. As you can imagine, this is super handy in responsive layouts.
Field sizing
field-sizing isn't a universally supported CSS feature yet, but it's going to be awesome when it is! Instead of needing JS to create auto-resizing textareas, you can use CSS only.
And Tailwind v4 supports it!Try out the demo on Tailwind's website.
You can now simply add the field-sizing-content class to your textarea to use it.Descendant updates
Tailwind stable (you may not know this) has an * variant that allows you to target direct children of an element with a class. For example:
The new ** variant in Tailwind v4 will target all descendants:
Inset shadows (and rings)
It will also now be easy to create inset shadows and rings on elements using the inset-shadow and inset-ring classes.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3