Sub topic 9
Arbitrary values and theme customization
This chapter covers how to go beyond Tailwind's default durations, delays and easing curves. It assumes you know the basic transition-*, duration-*, delay-* and ease-* utilities from earlier chapters, and that you can read a small CSS file. Examples are shown for Tailwind v4 (CSS-first configuration) with the v3 equivalent where it differs.
Why you need more than the defaults
Tailwind ships with a fixed scale for motion. Durations run from duration-75 to duration-1000. Easing has ease-linear, ease-in, ease-out and ease-in-out. Most interfaces can live with these. Sooner or later a design asks for "250ms" or for a specific cubic-bezier curve that the scale does not contain.
You have two ways to handle that:
- An arbitrary value is a one-off value written in square brackets inside the class name, such as
duration-[250ms]. It affects only that element. - A theme customization adds a named value to your design system, so every element can use it by name, such as
ease-snappy.
The rule of thumb: use an arbitrary value when you need something once, and move it into the theme when it appears a second or third time.
Arbitrary values for timing
Square brackets tell Tailwind to take whatever is inside as the raw CSS value.
<button class="bg-indigo-600 px-4 py-2 text-white transition-colors duration-[250ms] delay-[40ms] ease-[cubic-bezier(0.22,1,0.36,1)] hover:bg-indigo-700">
Save
</button>Here duration-[250ms] sets transition-duration: 250ms, delay-[40ms] sets transition-delay: 40ms, and ease-[cubic-bezier(0.22,1,0.36,1)] sets the timing function.
A few details are easy to get wrong:
- Spaces are not allowed inside the brackets. Use an underscore where you would write a space, and Tailwind converts it back. Commas are fine without spaces, as in the cubic-bezier above.
- Units are required for time values.
duration-[250]is not valid CSS in the way you might expect, so writeduration-[250ms]. - Class names must be written out in full. Tailwind scans your source files as plain text. A class built by string concatenation, such as `
duration-[${ms}ms]`, is never seen and no CSS is generated for it.
In v4 you can also pass a bare number to duration-* and delay-*. duration-250 works because v4 computes the value from the number. In v3, only values on the scale (or in your config) exist, so use duration-[250ms] there.
Arbitrary values for the transition property
The same square-bracket syntax works on transition-*. It lets you list exactly the properties you want to animate.
<div class="transition-[background-color,box-shadow] duration-200 hover:bg-slate-100 hover:shadow-md">
Hover me
</div>This generates transition-property: background-color, box-shadow. It is more precise than transition-all, and it avoids animating properties you did not mean to animate.
Arbitrary properties
If no utility exists for a property at all, you can write the whole declaration in brackets.
<div class="[transition-behavior:allow-discrete] transition-opacity duration-200">
Content
</div>This is called an arbitrary property. Use it sparingly. If you reach for the same one repeatedly, a theme entry or a named utility is easier to maintain.
CSS variable shorthand
Instead of a literal value, you can point at a CSS custom property. In v4 the shorthand is parentheses:
<div class="duration-(--card-speed) ease-(--card-ease) transition-transform hover:scale-105">
Card
</div>In v3 you wrote the same thing as duration-[var(--card-speed)]. Both forms produce transition-duration: var(--card-speed).
This is useful when a parent sets the value and many children inherit it, or when JavaScript changes the speed at runtime.
<section style="--card-speed: 400ms; --card-ease: ease-out">
<div class="duration-(--card-speed) ease-(--card-ease) transition-transform hover:scale-105">
Slow card
</div>
</section>Theme customization in Tailwind v4
In v4 your design tokens live in CSS, inside an @theme block. Tailwind reads certain variable prefixes and turns each one into utility classes.
| Theme variable prefix | Utilities it creates |
|---|---|
| `--ease-*` | `ease-*` |
| `--animate-*` | `animate-*` |
| `--default-transition-duration` | The duration used by `transition` and its siblings when you give none |
| `--default-transition-timing-function` | The easing used by `transition` and its siblings when you give none |
Adding a named easing curve
@import "tailwindcss";
@theme {
--ease-snappy: cubic-bezier(0.22, 1, 0.36, 1);
--ease-bounce-out: cubic-bezier(0.34, 1.56, 0.64, 1);
}You can now write ease-snappy or ease-bounce-out in markup.
<button class="transition-transform duration-300 ease-snappy hover:scale-105">
Buy now
</button>The name carries intent. A reader sees ease-snappy and understands the design decision, where ease-[cubic-bezier(0.22,1,0.36,1)] hides it.
Changing the defaults
The bare transition utility uses a 150ms duration and a standard easing curve. Override those once and every transition in your project follows.
@theme {
--default-transition-duration: 200ms;
--default-transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}Be careful with this. Changing a default affects every element that relies on it, including those inside third-party components that use Tailwind classes. Prefer new named values over overriding defaults unless you want a global change.
Removing or replacing a namespace
Setting a whole namespace to initial clears Tailwind's built-in values for it. You then define only your own.
@theme {
--ease-*: initial;
--ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
--ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
}After this, ease-in-out no longer exists, and using it generates nothing. That is the point: it keeps a team on the approved set.
Custom animations in the theme
Custom keyframes also belong in @theme, covered in detail in the next chapter. The pattern is the same: a --animate-* variable creates the utility, and @keyframes placed inside the block are emitted with it.
@theme {
--animate-fade-in: fade-in 0.3s ease-out both;
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
}Theme variables are also CSS variables
Every @theme entry becomes a real custom property on :root. You can read it in plain CSS or in arbitrary values.
.toast {
transition: transform 250ms var(--ease-snappy);
}By default, Tailwind only outputs a theme variable if a utility uses it. If you need all of them in the final CSS (for example to read them from JavaScript), use @theme static.
Theme customization in Tailwind v3
In v3 the same ideas live in tailwind.config.js, under theme.extend. Putting values under extend adds to the defaults. Putting them directly under theme replaces the whole scale.
// tailwind.config.js (Tailwind v3)
module.exports = {
theme: {
extend: {
transitionTimingFunction: {
snappy: 'cubic-bezier(0.22, 1, 0.36, 1)',
},
transitionDuration: {
250: '250ms',
400: '400ms',
},
transitionDelay: {
40: '40ms',
},
},
},
};This produces ease-snappy, duration-250, duration-400 and delay-40. The config keys differ from the class prefixes: transitionTimingFunction becomes ease-*, transitionDuration becomes duration-*.
A table of the mapping helps:
| Goal | v4 (CSS) | v3 (config) |
|---|---|---|
| Named easing | `--ease-snappy: ...` | `transitionTimingFunction.snappy` |
| Named duration | use `duration-<number>` or `--default-transition-duration` | `transitionDuration.250` |
| Named animation | `--animate-wiggle: ...` plus `@keyframes` | `animation.wiggle` plus `keyframes.wiggle` |
Choosing between the options
Use these criteria:
- Arbitrary value: a single element, a prototype, or a value that only makes sense in that spot.
- Theme entry: a value that expresses a design decision, such as "our standard easing". It also gives you one place to change it.
- CSS variable: a value that changes with context, such as a parent that slows all its children, or a value set from JavaScript.
Common errors
- Dynamic class names. `
duration-[${ms}ms]generates nothing. Either list the full class names somewhere Tailwind can see them, or set a CSS variable with inlinestyleand useduration-(--x)`. - Spaces inside brackets. Write
transition-[opacity,transform]with no space after the comma, or use underscores where a space is needed. - Wrong config key in v3. Writing
durationoreaseundertheme.extenddoes nothing. The keys aretransitionDurationandtransitionTimingFunction. - Using a v3 config in a v4 project without loading it. v4 does not read
tailwind.config.jsautomatically. Load it with@config "./tailwind.config.js";or move the values into@theme. - Forgetting that
extendmatters. In v3, definingtransitionDurationoutsideextendremovesduration-75throughduration-1000. - Overriding defaults by accident. A changed
--default-transition-durationalters every baretransitionin the project.
Verifying your customization
After adding a theme value, check that the utility exists. Create a test element, run your build, and inspect the element in browser developer tools. Under the computed styles, look for transition-timing-function. If the value is missing, the class name did not match a theme entry or the file was not scanned.
<div class="size-16 bg-indigo-600 transition-transform duration-500 ease-snappy hover:translate-x-24"></div>Hover the box. A snappy curve moves fast at the start and settles gently, so you can see the curve's character when you swap it for ease-linear.
Exercise
You use the same curve cubic-bezier(0.22,1,0.36,1) in eight components, and a designer asks you to change it. In Tailwind v4, where should the value live, and what class do the components use?
Show answer
Define it once in the @theme block as --ease-snappy: cubic-bezier(0.22, 1, 0.36, 1); and use ease-snappy in the components. Changing the one variable updates all eight. Eight copies of ease-[cubic-bezier(...)] would each need editing.
Exercise
A component builds its class with ` duration-[${delay}ms] ` and no style is applied. Why, and how do you fix it while keeping the value dynamic?
Show answer
Tailwind scans source files as plain text and never sees the finished class name, so it generates no CSS for it. Set a CSS variable with inline style, for example style="--speed: 400ms", and use duration-(--speed) in the class list. In v3, write duration-[var(--speed)].
Exercise
In a v3 project you add transitionDuration: { 250: '250ms' } directly under theme instead of theme.extend. What happens to duration-150?
Show answer
It stops working. Placing the key under theme replaces the whole default duration scale, so only duration-250 exists. Put it under theme.extend to add to the defaults.