You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bootstrap utilities are generated with our utility API and can be used to modify or extend our default set of utility classes via Sass. Our utility API is based on a series of Sass maps and functions for generating families of classes with various options. If you’re unfamiliar with Sass maps, read up on the [official Sass docs](https://sass-lang.com/documentation/values/maps/) to get started.
8
+
Bootstrap utilities are generated with our utility API and can be used to modify or extend our default set of utility classes via Sass. Our utility API is based on a series of Sass maps and functions for generating families of classes with various options. If you're unfamiliar with Sass maps, read up on the [official Sass docs](https://sass-lang.com/documentation/values/maps/) to get started.
9
9
10
10
The `$utilities` map contains all our utilities and is later merged with your custom `$utilities` map, if present. The utility map contains a keyed list of utility groups which accept the following options:
11
11
12
12
<BsTableclass="table table-utilities">
13
13
| Option | Type | Default value | Description |
14
14
| --- | --- | --- | --- |
15
-
|[`property`](#property)|**Required**| – | Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins). |
15
+
|[`property`](#property)|**Required**| – | Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins). Can also be a map for [property-value mapping](#property-value-mapping). |
16
16
|[`values`](#values)|**Required**| – | List of values, or a map if you don't want the class name to be the same as the value. If `null` is used as map key, `class` is not prepended to the class name. |
17
-
|[`selector`](#selector)| Optional |`class`| Type of CSS selector in the generated CSS ruleset. Can be `class`, `attr-starts`, or `attr-includes`. |
17
+
|[`selector`](#selector)| Optional |`class`| Type of CSS selector in the generated CSS ruleset. Must be `class`, `attr-starts`, or `attr-includes`. Attribute selectors require the `class` option. |
18
18
|[`class`](#class)| Optional | null | Name of the generated class. If not provided and `property` is an array of strings, `class` will default to the first element of the `property` array. If not provided and `property` is a string, the `values` keys are used for the `class` names. |
19
-
|[`css-var`](#css-variable-utilities)| Optional |`false`| Boolean to generate CSS variables instead of CSS rules. |
20
-
|[`css-variable-name`](#css-variable-utilities)| Optional | null | Custom un-prefixed name for the CSS variable inside the ruleset. |
21
-
|[`local-vars`](#local-css-variables)| Optional | null | Map of local CSS variables to generate in addition to the CSS rules. |
19
+
|[`variables`](#variables)| Optional | null | List or map of local CSS variables to generate within the utility's ruleset. If a list, each variable receives the utility value. If a map, uses the provided static values. |
22
20
|[`state`](#states)| Optional | null | List of pseudo-class variants (e.g., `:hover` or `:focus`) to generate. |
23
21
|[`responsive`](#responsive)| Optional |`false`| Boolean indicating if responsive classes should be generated. |
24
22
|[`important`](#importance)| Optional |`false`| Boolean indicating if `!important` should be added to the utility's CSS rules. |
25
23
|[`print`](#print)| Optional |`false`| Boolean indicating if print classes need to be generated. |
26
-
|`rtl`| Optional |`true`| Boolean indicating if utility should be kept in RTL. |
The `property` key must be set for any utility, and it must contain a valid CSS property. This property is used in the generated utility’s ruleset. When the `class` key is omitted, it also serves as the default class name. Consider the `text-decoration` utility:
59
+
The `property` key must be set for any utility, and it must contain a valid CSS property. This property is used in the generated utility's ruleset. When the `class` key is omitted, it also serves as the default class name. Consider the `text-decoration` utility:
63
60
64
61
```scss
65
62
$utilities: (
@@ -208,18 +205,20 @@ Output:
208
205
.invisible { visibility: hidden; }
209
206
```
210
207
211
-
### CSS variable utilities
208
+
### Variables
212
209
213
-
Set the `css-var` boolean option to `true` and the API will generate local CSS variables for the given selector instead of the usual `property: value` rules. Add an optional `css-variable-name` to set a different CSS variable name than the class name.
210
+
Use the `variables`option to generate local CSS custom properties within the utility's ruleset. It accepts either a list or a map.
214
211
215
-
Consider our `.text-opacity-*` utilities. If we add the `css-variable-name` option, we'll get a custom output.
212
+
When `variables` is a **list**, each variable receives the current utility value:
216
213
217
214
```scss
218
215
$utilities: (
219
-
"text-opacity": (
220
-
css-var: true,
221
-
css-variable-name: text-alpha,
222
-
class: text-opacity,
216
+
"opacity": (
217
+
property: opacity,
218
+
class: opacity,
219
+
variables: (
220
+
"opacity-value"
221
+
),
223
222
values: (
224
223
25: .25,
225
224
50: .5,
@@ -233,29 +232,29 @@ $utilities: (
233
232
Output:
234
233
235
234
```css
236
-
.text-opacity-25 { --bs-text-alpha: .25; }
237
-
.text-opacity-50 { --bs-text-alpha: .5; }
238
-
.text-opacity-75 { --bs-text-alpha: .75; }
239
-
.text-opacity-100 { --bs-text-alpha: 1; }
235
+
.opacity-25 {
236
+
--opacity-value: .25;
237
+
opacity: .25;
238
+
}
239
+
.opacity-50 {
240
+
--opacity-value: .5;
241
+
opacity: .5;
242
+
}
243
+
/* ... */
240
244
```
241
245
242
-
### Local CSS variables
243
-
244
-
Use the `local-vars` option to specify a Sass map that will generate local CSS variables within the utility class’s ruleset. Please note that it may require additional work to consume those local CSS variables in the generated CSS rules. For example, consider our `.bg-*` utilities:
246
+
When `variables` is a **map**, the provided static values are used instead:
Use the `state` option to generate pseudo-class variations. Example pseudo-classes are `:hover` and `:focus`. When a list of states are provided, classnames are created for that pseudo-class. For example, to change opacity on hover, add `state: hover` and you’ll get `.opacity-hover:hover` in your compiled CSS.
274
+
Use the `state` option to generate pseudo-class variations. Example pseudo-classes are `:hover` and `:focus`. When a list of states are provided, classnames are created for that pseudo-class. For example, to change opacity on hover, add `state: hover` and you'll get `.opacity-hover:hover` in your compiled CSS.
276
275
277
276
Need multiple pseudo-classes? Use a space-separated list of states: `state: hover focus`.
278
277
@@ -445,7 +444,7 @@ Some utilities like `display`, `position`, and `visibility` have `important: tru
445
444
446
445
## Using the API
447
446
448
-
Now that you’re familiar with how the utilities API works, learn how to add your own custom classes and modify our default utilities.
447
+
Now that you're familiar with how the utilities API works, learn how to add your own custom classes and modify our default utilities.
449
448
450
449
### Override utilities
451
450
@@ -463,7 +462,7 @@ $utilities: (
463
462
464
463
### Add utilities
465
464
466
-
New utilities can be added to the default `$utilities` map with a `map-merge`. Make sure our required Sass files and `_utilities.scss` are imported first, then use the `map-merge` to add your additional utilities. For example, here’s how to add a responsive `cursor` utility with three values.
465
+
New utilities can be added to the default `$utilities` map with a `map-merge`. Make sure our required Sass files and `_utilities.scss` are imported first, then use the `map-merge` to add your additional utilities. For example, here's how to add a responsive `cursor` utility with three values.
467
466
468
467
```scss
469
468
@import"bootstrap/scss/functions";
@@ -490,7 +489,7 @@ $utilities: map-merge(
490
489
491
490
### Modify utilities
492
491
493
-
Modify existing utilities in the default `$utilities` map with `map-get` and `map-merge` functions. In the example below, we’re adding an additional value to the `width` utilities. Start with an initial `map-merge` and then specify which utility you want to modify. From there, fetch the nested `"width"` map with `map-get` to access and modify the utility’s options and values.
492
+
Modify existing utilities in the default `$utilities` map with `map-get` and `map-merge` functions. In the example below, we're adding an additional value to the `width` utilities. Start with an initial `map-merge` and then specify which utility you want to modify. From there, fetch the nested `"width"` map with `map-get` to access and modify the utility's options and values.
494
493
495
494
```scss
496
495
@import"bootstrap/scss/functions";
@@ -640,7 +639,7 @@ $utilities: map-merge(
640
639
641
640
### Add, remove, modify
642
641
643
-
You can add, remove, and modify many utilities all at once with the [`map-merge()` Sass function](https://sass-lang.com/documentation/modules/map/#merge). Here’s how you can combine the previous examples into one larger map.
642
+
You can add, remove, and modify many utilities all at once with the [`map-merge()` Sass function](https://sass-lang.com/documentation/modules/map/#merge). Here's how you can combine the previous examples into one larger map.
0 commit comments