Commit f0e9343
Add support for defining simple custom utilities in CSS via
This PR allows you to add custom utilities to your project via the new
`@utility` rule.
For example, given the following:
```css
@Utility text-trim {
text-box-trim: both;
text-box-edge: cap alphabetic;
}
```
A new `text-trim` utility is available and can be used directly or with
variants:
```html
<div class="text-trim">...</div>
<div class="hover:text-trim">...</div>
<div class="lg:dark:text-trim">...</div>
```
If a utility is defined more than one time the latest definition will be
used:
```css
@Utility text-trim {
text-box-trim: both;
text-box-edge: cap alphabetic;
}
@Utility text-trim {
text-box-trim: both;
text-box-edge: cap ideographic;
}
```
Then using `text-trim` will produce the following CSS:
```css
.text-trim {
text-box-trim: both;
text-box-edge: cap ideographic;
}
```
You may also override specific existing utilities with this — for
example to add a `text-rendering` property to the `text-sm` utility:
```css
@Utility text-sm {
font-size: var(--font-size-sm, 0.875rem);
line-height: var(--font-size-sm--line-height, 1.25rem);
text-rendering: optimizeLegibility;
}
```
Though it's preferred, should you not need to add properties, to
override the theme instead.
Lastly, utilities with special characters do not need to be escaped like
you would for a class name in a selector:
```css
@Utility push-1/2 {
right: 50%;
}
```
We do however explicitly error on certain patterns that we want to
reserve for future use, for example `push-*` and `push-[15px]`.
---------
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>@utility (tailwindlabs#14044)1 parent 300524b commit f0e9343
File tree
7 files changed
+319
-111
lines changed- packages/tailwindcss/src
7 files changed
+319
-111
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
252 | 271 | | |
253 | 272 | | |
254 | 273 | | |
| |||
307 | 326 | | |
308 | 327 | | |
309 | 328 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | 329 | | |
318 | 330 | | |
319 | 331 | | |
| |||
345 | 357 | | |
346 | 358 | | |
347 | 359 | | |
348 | | - | |
| 360 | + | |
349 | 361 | | |
350 | 362 | | |
351 | 363 | | |
352 | 364 | | |
353 | 365 | | |
354 | 366 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | 380 | | |
399 | 381 | | |
400 | 382 | | |
| |||
560 | 542 | | |
561 | 543 | | |
562 | 544 | | |
563 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
564 | 548 | | |
565 | 549 | | |
566 | 550 | | |
| |||
629 | 613 | | |
630 | 614 | | |
631 | 615 | | |
632 | | - | |
| 616 | + | |
633 | 617 | | |
634 | | - | |
635 | | - | |
| 618 | + | |
| 619 | + | |
636 | 620 | | |
637 | 621 | | |
638 | 622 | | |
639 | 623 | | |
640 | 624 | | |
641 | 625 | | |
642 | 626 | | |
643 | | - | |
| 627 | + | |
644 | 628 | | |
645 | 629 | | |
646 | 630 | | |
647 | 631 | | |
648 | 632 | | |
649 | 633 | | |
650 | | - | |
651 | | - | |
| 634 | + | |
652 | 635 | | |
653 | 636 | | |
654 | 637 | | |
| |||
658 | 641 | | |
659 | 642 | | |
660 | 643 | | |
661 | | - | |
| 644 | + | |
662 | 645 | | |
663 | 646 | | |
664 | 647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 120 | + | |
125 | 121 | | |
126 | 122 | | |
127 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
68 | 99 | | |
69 | 100 | | |
70 | 101 | | |
| |||
224 | 255 | | |
225 | 256 | | |
226 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
227 | 262 | | |
228 | 263 | | |
229 | 264 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
24 | 18 | | |
25 | | - | |
| 19 | + | |
| 20 | + | |
26 | 21 | | |
27 | 22 | | |
28 | 23 | | |
| |||
0 commit comments