Skip to content

Commit a5410ba

Browse files
authored
Document --default(…) in --value(…) and --modifier(…) (#2488)
Direct link: https://tailwindcss-com-git-feat-document-default-fn-tailwindlabs.vercel.app/docs/adding-custom-styles#default-values This PR documents the `--default(…)` option that can be used in `--value(…)` and `--modifier(…)` when defining custom functional utilities in CSS using `@utility`. This was been implemented in tailwindlabs/tailwindcss#19989
1 parent 7ea8cbe commit a5410ba

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/docs/adding-custom-styles.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,45 @@ The `--value()` function can also take multiple arguments and resolve them left
580580
}
581581
```
582582

583+
#### Default values
584+
585+
Use `--default()` inside `--value()` to support a default value when the utility is used without an explicit value:
586+
587+
```css
588+
/* [!code filename:CSS] */
589+
/* [!code word:--default(4)] */
590+
@utility tab-* {
591+
tab-size: --value(integer, --default(4));
592+
}
593+
```
594+
595+
This matches both `tab-2` and `tab-4`, as well as just `tab` which uses the default value of `4`:
596+
597+
```css
598+
/* [!code filename:Compiled CSS] */
599+
/* [!code highlight:4] */
600+
.tab {
601+
tab-size: 4;
602+
}
603+
604+
.tab-2 {
605+
tab-size: 2;
606+
}
607+
```
608+
609+
The `--default()` function can also be used inside `--modifier()` to provide a default value when no modifier is present:
610+
611+
```css
612+
/* [!code filename:CSS] */
613+
/* [!code word:--default(1)] */
614+
@utility tab-* {
615+
tab-size: --value(integer);
616+
line-height: --modifier(integer, --default(1));
617+
}
618+
```
619+
620+
This matches `tab-2/3` with a line-height of `3`, and `tab-2` with a line-height of `1`.
621+
583622
#### Negative values
584623

585624
To support negative values, register separate positive and negative utilities into separate declarations:

0 commit comments

Comments
 (0)