Customization in Tailwind CSS: Adding Arbitrary Values

Welcome to my blog ππ½
I'm a Front-End Developer with a passion for learning!
I write about Programming π©π½βπ» and Productivity Tips β
Search for a command to run...

Welcome to my blog ππ½
I'm a Front-End Developer with a passion for learning!
I write about Programming π©π½βπ» and Productivity Tips β
No comments yet. Be the first to comment.
In this series, you will find fast, short, and sweet tips/hacks that you may or may not be aware of. I will try to provide these (fairly) regularly on Fridays.
Improve the Developer Experience with this Quick Tip
Although my experience is primarily with front-end development, my current job is affording me the opportunity to do more full-stack work. Naturally, this meant that I needed to explore the different database GUIs available on the market. Here is a l...

A Note on the Series: Fast Fridays π is a series where you will find fast, short, and sweet tips/hacks that you may or may not be aware of. I will try to provide these (fairly) regularly on Fridays. In this Fast Friday tip, I'll explain how to crea...

Over the past year, Iβve started incorporating a Git GUI into my workflow. I still reach for the terminal about 90% of the time, but Iβve found that a GUI can really shine when it comes to things like viewing diffs, checking stashes, or resolving mer...

Simplifying Branch Management with Git Worktree

With all the AI tools popping up these days, I figured I'd try out some speech-to-text software in an attempt to boost my productivity. I've been hearing a lot about βdeveloping at the speed of thoughtβ, so here's a list of the top speech-to-text sof...

A Note on the Series:
Fast Fridays π is a series where you will find fast, short, and sweet tips/hacks that you may or may not be aware of. I will try to provide these (fairly) regularly on Fridays.
Tailwind CSS is a utility-first CSS framework that makes styling your app a breeze. Tailwind is jam-packed with a myriad of classes that fit almost every use-case. For those scenarios where there isn't a pre-existing class that suits your need, Tailwind provides a way to easily customize your CSS using arbitrary values.
I want to preface by saying that there are multiple ways to customize CSS in Tailwind. A non-exhaustive list of ways you can customize include:
theme section of your tailwind.config.js.@layer directive - which adds additional styles to Tailwind's utilities, components, and base layers.To keep things nice and succinct for this Fast Friday Tip π, this article will discuss option #3. However, know that there are various customization options to choose from.
As of v3.0 of Tailwind, arbitrary values are now included by default. Versions prior to v3.0 will require the Just-In-Time engine in order to support this feature. Arbitrary values are great to use if you want to apply one-off styles without having to create a custom class in the stylesheet.
Adding an arbitrary value requires the square bracket [] notation. For example, let's say we wanted to create a card element that contains a custom background-color, font-size, and min-height.
<div class="max-w-sm rounded shadow-lg bg-[#74c7d5] min-h-[240px]">
<div class="p-7 text-center">
<div class="font-bold mb-2 text-[2rem]">Card Header</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</p>
</div>
</div>
bg-[#74c7d5] sets the custom background-colormin-h-[240px] sets the custom min-height text-[2rem] sets the custom font-sizeThe neat part is that arbitrary values can be applied across many different utilities from interactive modifiers like hover states to super custom arbitrary properties that Tailwind doesn't include out of the box. The possibilities are endless!
If you enjoy what you read, feel free to like this article or subscribe to my newsletter, where I write about programming and productivity tips.
As always, thank you for reading, and happy coding!