2019-05-23 11:56:03 +02:00
---
layout: docs
title: Utility API
2020-11-13 17:49:55 +01:00
description: The utility API is a Sass-based tool to generate utility classes.
2019-05-23 11:56:03 +02:00
group: utilities
2022-12-24 18:37:22 +02:00
aliases: "/docs/5.3/utilities/"
2019-05-23 11:56:03 +02:00
toc: true
---
2020-11-02 19:03:15 +02:00
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.
2019-05-23 11:56:03 +02:00
2020-11-02 19:03:15 +02:00
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:
2019-05-23 11:56:03 +02:00
v5.2.0 design refresh, plus responsive offcanvas classes (#35736)
* Add responsive offcanvas classes
- Updates navbar-expand classes to de-dupe some styles—these shouldn't interfere now.
- Adds some JS to the offcanvas component to help with responsiveness
Co-Authored-By: GeoSot <geo.sotis@gmail.com>
* Redesign homepage, docs, and examples
Homepage:
- New Bootstrap purple navbar
- Redesigned masthead
- Rewrote and redesigned homepage content
- Replace Copy text with icons like Bootstrap Icons site across all ClipboardJS instances
- Fixed padding issues in site footer
- Match homepage button styles to examples page, use gap instead of tons of responsive margin utils
Docs:
- New navbar, no more subnav. Migrated search and version picker into the main navbar and refreshed the design of it all, including the responsive toggles.
- New sidebar navigation is always expanded, and now features Bootstrap Icons alongside section headings
- Sidebar navigation autoscrolls to active link for better usability
- Subnav and navbar padding issues ironed out
- Enhanced the version picker in anticipation of v5.2: we can now link right to the same page in the previous version.
- Redesign callouts to add more color to our pages
- Collapse table of contents on mobile
- Cleanup and redesign button styles with CSS variables
- Update design for subnav version dropdown
- Update highlight and example to be full-width until md
- Improve the Added In badges
- Turn the ToC into a well on mobile
- Redesign code snippets to better house two action buttons
Examples:
- Redesign Examples page layout
- Add new example for responsive offcanvases in navbars
* Convert offcanvas to CSS vars
* Feat: add resize handler to Offcanvas.js.
If we could use as default the `.offcanvas` class without modifiers, we then, could add a simplified selector
The selector itself, ignores the .offcanvas class as it doesn't have any responsive behavior
The `aria-modal` addon is to protect us, selection backdrop elements
* Separate examples code, Add some selectors, fix stackblitz btn
Co-authored-by: GeoSot <geo.sotis@gmail.com>
2022-04-17 22:17:50 -07:00
{{< bs-table " table table-utilities " > }}
2022-03-16 12:50:12 +00:00
| Option | Type | Default value | Description |
| ---------------------------------------------- | ------------ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`property` ](#property ) | **Required** | – | Name of the property, this can be a string or an array of strings (e.g., horizontal paddings or margins). |
| [`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. |
| [`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. |
| [`css-var` ](#css-variable-utilities ) | Optional | `false` | Boolean to generate CSS variables instead of CSS rules. |
| [`css-variable-name` ](#css-variable-utilities ) | Optional | null | Custom un-prefixed name for the CSS variable inside the ruleset. |
| [`local-vars` ](#local-css-variables ) | Optional | null | Map of local CSS variables to generate in addition to the CSS rules. |
| [`state` ](#states ) | Optional | null | List of pseudo-class variants (e.g., `:hover` or `:focus` ) to generate. |
| [`responsive` ](#responsive ) | Optional | `false` | Boolean indicating if responsive classes should be generated. |
| `rfs` | Optional | `false` | Boolean to enable [fluid rescaling with RFS ]({{< docsref "/getting-started/rfs" >}} ). |
| [`print` ](#print ) | Optional | `false` | Boolean indicating if print classes need to be generated. |
| `rtl` | Optional | `true` | Boolean indicating if utility should be kept in RTL. |
2020-11-02 19:03:15 +02:00
{{< / bs-table > }}
2019-07-18 11:35:20 +03:00
2020-11-02 19:03:15 +02:00
## API explained
2019-05-23 11:56:03 +02:00
2020-11-02 19:03:15 +02:00
All utility variables are added to the `$utilities` variable within our `_utilities.scss` stylesheet. Each group of utilities looks something like this:
2019-05-23 11:56:03 +02:00
```scss
$utilities: (
"opacity": (
property: opacity,
values: (
0: 0,
25: .25,
2020-07-12 18:28:58 +04:30
50: .5,
2020-06-29 00:06:57 +04:30
75: .75,
2019-05-23 11:56:03 +02:00
100: 1,
)
)
2021-07-18 20:39:02 -07:00
);
2019-05-23 11:56:03 +02:00
```
2020-11-02 19:03:15 +02:00
Which outputs the following:
2019-05-23 11:56:03 +02:00
```css
2020-11-02 19:03:15 +02:00
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
2019-05-23 11:56:03 +02:00
```
2021-07-18 20:39:02 -07:00
### Property
2019-05-23 11:56:03 +02:00
2021-07-18 20:39:02 -07:00
The required `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:
```scss
$utilities: (
"text-decoration": (
property: text-decoration,
values: none underline line-through
)
);
```
Output:
```css
.text-decoration-none { text-decoration: none !important; }
.text-decoration-underline { text-decoration: underline !important; }
.text-decoration-line-through { text-decoration: line-through !important; }
```
### Values
Use the `values` key to specify which values for the specified `property` should be used in the generated class names and rules. Can be a list or map (set in the utilities or in a Sass variable).
As a list, like with [`text-decoration` utilities ]({{< docsref "/utilities/text#text-decoration" >}} ):
```scss
values: none underline line-through
```
As a map, like with [`opacity` utilities ]({{< docsref "/utilities/opacity" >}} ):
```scss
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
```
As a Sass variable that sets the list or map, as in our [`position` utilities ]({{< docsref "/utilities/position" >}} ):
```scss
values: $position-values
```
### Class
Use the `class` option to change the class prefix used in the compiled CSS. For example, to change from `.opacity-*` to `.o-*` :
2019-05-23 11:56:03 +02:00
```scss
$utilities: (
"opacity": (
property: opacity,
class: o,
values: (
0: 0,
25: .25,
2020-07-12 18:28:58 +04:30
50: .5,
2020-06-29 00:06:57 +04:30
75: .75,
2019-05-23 11:56:03 +02:00
100: 1,
)
)
2021-07-18 20:39:02 -07:00
);
```
Output:
```css
.o-0 { opacity: 0 !important; }
.o-25 { opacity: .25 !important; }
.o-50 { opacity: .5 !important; }
.o-75 { opacity: .75 !important; }
.o-100 { opacity: 1 !important; }
```
2021-12-28 15:38:35 +03:00
If `class: null` , generates classes for each of the `values` keys:
```scss
$utilities: (
"visibility": (
property: visibility,
class: null,
values: (
visible: visible,
invisible: hidden,
)
)
);
```
Output:
```css
.visible { visibility: visible !important; }
.invisible { visibility: hidden !important; }
```
2021-07-18 20:39:02 -07:00
### CSS variable utilities
2021-11-29 21:14:17 -08:00
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.
Consider our `.text-opacity-*` utilities. If we add the `css-variable-name` option, we'll get a custom output.
2021-07-18 20:39:02 -07:00
```scss
$utilities: (
"text-opacity": (
css-var: true,
2021-11-29 21:14:17 -08:00
css-variable-name: text-alpha,
2021-07-18 20:39:02 -07:00
class: text-opacity,
values: (
25: .25,
50: .5,
75: .75,
100: 1
)
),
);
```
Output:
```css
2021-11-29 21:14:17 -08:00
.text-opacity-25 { --bs-text-alpha: .25; }
.text-opacity-50 { --bs-text-alpha: .5; }
.text-opacity-75 { --bs-text-alpha: .75; }
.text-opacity-100 { --bs-text-alpha: 1; }
2021-07-18 20:39:02 -07:00
```
### Local CSS variables
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:
```scss
$utilities: (
"background-color": (
property: background-color,
class: bg,
local-vars: (
"bg-opacity": 1
),
values: map-merge(
$utilities-bg-colors,
(
"transparent": transparent
)
)
)
);
2019-05-23 11:56:03 +02:00
```
Output:
```css
2021-07-18 20:39:02 -07:00
.bg-primary {
--bs-bg-opacity: 1;
background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;
}
2019-05-23 11:56:03 +02:00
```
2021-04-14 13:23:16 -07:00
### States
2020-11-08 20:05:22 -08:00
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.
Need multiple pseudo-classes? Use a space-separated list of states: `state: hover focus` .
```scss
$utilities: (
"opacity": (
property: opacity,
class: opacity,
state: hover,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
```
Output:
```css
2021-06-14 14:53:24 -07:00
.opacity-0-hover:hover { opacity: 0 !important; }
.opacity-25-hover:hover { opacity: .25 !important; }
.opacity-50-hover:hover { opacity: .5 !important; }
.opacity-75-hover:hover { opacity: .75 !important; }
.opacity-100-hover:hover { opacity: 1 !important; }
2020-11-08 20:05:22 -08:00
```
2021-07-18 20:39:02 -07:00
### Responsive
2019-05-23 11:56:03 +02:00
2020-11-02 19:03:15 +02:00
Add the `responsive` boolean to generate responsive utilities (e.g., `.opacity-md-25` ) across [all breakpoints ]({{< docsref "/layout/breakpoints" >}} ).
2019-05-23 11:56:03 +02:00
```scss
$utilities: (
"opacity": (
property: opacity,
responsive: true,
values: (
0: 0,
25: .25,
2020-07-12 18:28:58 +04:30
50: .5,
2020-06-29 00:06:57 +04:30
75: .75,
2019-05-23 11:56:03 +02:00
100: 1,
)
)
2021-07-18 20:39:02 -07:00
);
2019-05-23 11:56:03 +02:00
```
Output:
```css
2021-06-14 14:53:24 -07:00
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
2020-11-02 19:03:15 +02:00
2019-05-23 11:56:03 +02:00
@media (min-width: 576px) {
2021-06-14 14:53:24 -07:00
.opacity-sm-0 { opacity: 0 !important; }
.opacity-sm-25 { opacity: .25 !important; }
.opacity-sm-50 { opacity: .5 !important; }
.opacity-sm-75 { opacity: .75 !important; }
.opacity-sm-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
}
2020-11-02 19:03:15 +02:00
2019-05-23 11:56:03 +02:00
@media (min-width: 768px) {
2021-06-14 14:53:24 -07:00
.opacity-md-0 { opacity: 0 !important; }
.opacity-md-25 { opacity: .25 !important; }
.opacity-md-50 { opacity: .5 !important; }
.opacity-md-75 { opacity: .75 !important; }
.opacity-md-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
}
2020-11-02 19:03:15 +02:00
2019-05-23 11:56:03 +02:00
@media (min-width: 992px) {
2021-06-14 14:53:24 -07:00
.opacity-lg-0 { opacity: 0 !important; }
.opacity-lg-25 { opacity: .25 !important; }
.opacity-lg-50 { opacity: .5 !important; }
.opacity-lg-75 { opacity: .75 !important; }
.opacity-lg-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
}
2020-11-02 19:03:15 +02:00
2019-05-23 11:56:03 +02:00
@media (min-width: 1200px) {
2021-06-14 14:53:24 -07:00
.opacity-xl-0 { opacity: 0 !important; }
.opacity-xl-25 { opacity: .25 !important; }
.opacity-xl-50 { opacity: .5 !important; }
.opacity-xl-75 { opacity: .75 !important; }
.opacity-xl-100 { opacity: 1 !important; }
2020-11-02 19:03:15 +02:00
}
@media (min-width: 1400px) {
2021-06-14 14:53:24 -07:00
.opacity-xxl-0 { opacity: 0 !important; }
.opacity-xxl-25 { opacity: .25 !important; }
.opacity-xxl-50 { opacity: .5 !important; }
.opacity-xxl-75 { opacity: .75 !important; }
.opacity-xxl-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
}
```
2021-07-18 20:39:02 -07:00
### Print
2019-05-23 11:56:03 +02:00
2020-11-02 19:03:15 +02:00
Enabling the `print` option will **also** generate utility classes for print, which are only applied within the `@media print { ... }` media query.
2019-05-23 11:56:03 +02:00
```scss
$utilities: (
"opacity": (
property: opacity,
print: true,
values: (
0: 0,
25: .25,
2020-07-12 18:28:58 +04:30
50: .5,
2020-06-29 00:06:57 +04:30
75: .75,
2019-05-23 11:56:03 +02:00
100: 1,
)
)
2021-07-18 20:39:02 -07:00
);
2019-05-23 11:56:03 +02:00
```
Output:
```css
2021-06-14 14:53:24 -07:00
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
@media print {
2021-06-14 14:53:24 -07:00
.opacity-print-0 { opacity: 0 !important; }
.opacity-print-25 { opacity: .25 !important; }
.opacity-print-50 { opacity: .5 !important; }
.opacity-print-75 { opacity: .75 !important; }
.opacity-print-100 { opacity: 1 !important; }
2019-05-23 11:56:03 +02:00
}
```
2021-06-14 14:53:24 -07:00
## Importance
All utilities generated by the API include `!important` to ensure they override components and modifier classes as intended. You can toggle this setting globally with the `$enable-important-utilities` variable (defaults to `true` ).
2020-11-03 10:44:03 -08:00
## Using the API
2019-05-23 11:56:03 +02:00
2022-03-16 12:50:12 +00:00
Now that you're familiar with how the utilities API works, learn how to add your own custom classes and modify our default utilities. There are two ways you can do this:
2020-07-19 21:08:41 +03:00
2022-03-16 12:50:12 +00:00
1. If you only need to override our default utilities or add new ones, we'll merge your `$utilities` variable with ours
2. If you require more fine grained control, we provide mixins to let you update our default utilities configuration.
You may also want to refer to some of the utilities configuration in your Sass code, for which we provide some handy functions.
### Adding or overriding utilities
2021-07-18 20:39:02 -07:00
Override existing utilities by using the same key. For example, if you want additional responsive overflow utility classes, you can do this:
```scss
$utilities: (
"overflow": (
responsive: true,
property: overflow,
values: visible hidden scroll auto,
),
);
2022-03-16 12:50:12 +00:00
@import 'bootstrap/scss/utilities';
@import 'bootstrap/scss/utilities/api';
```
2020-07-19 21:08:41 +03:00
2022-03-16 12:50:12 +00:00
### Modifying our defaults
2020-07-19 21:08:41 +03:00
2022-03-16 12:50:12 +00:00
After importing `bootstrap/scss/utilities` , you can use mixins to:
2022-05-26 14:11:27 -07:00
2022-03-16 12:50:12 +00:00
- add or remove utilities
- update utilities options, like `responsive` , `class` , `rtl` ...
- add, remove or update utility values
2020-07-19 21:08:41 +03:00
2022-03-16 12:50:12 +00:00
#### Adding and removing utilities
2020-07-19 21:08:41 +03:00
2022-03-16 12:50:12 +00:00
`utilities-add` and `utilities-remove` mixins let you add and remove utilities from the configuration.
Adding an existing utility will completely override it.
2020-07-19 21:08:41 +03:00
```scss
2021-01-05 12:11:56 -08:00
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2021-11-23 09:06:33 +01:00
@import "bootstrap/scss/maps";
2021-11-03 05:31:21 -07:00
@import "bootstrap/scss/mixins";
2020-07-19 21:08:41 +03:00
@import "bootstrap/scss/utilities";
2022-03-16 12:50:12 +00:00
@include utilities-add(cursor, (
property: cursor,
class: cursor,
responsive: true,
values: auto pointer grab,
));
// Remove user-select and shadow
@include utilities-remove(user-select, shadow);
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/utilities/api";
2020-07-19 21:08:41 +03:00
```
2020-11-03 10:44:03 -08:00
2022-03-16 12:50:12 +00:00
#### Updating utility options
2021-05-22 00:51:30 -07:00
2022-03-16 12:50:12 +00:00
`utilities-set-option` and `utilities-set-options` let you configure one or several options of a utility.
`utilities-set-options` will merge the new options with the existing ones by default,
but you can provide a third `$merge: false` argument to completely override them.
And if the utility does not exist, both mixins will create a new one.
2021-05-22 00:51:30 -07:00
```scss
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2021-11-23 09:06:33 +01:00
@import "bootstrap/scss/maps";
2021-11-03 05:31:21 -07:00
@import "bootstrap/scss/mixins";
2021-05-22 00:51:30 -07:00
@import "bootstrap/scss/utilities";
2022-03-16 12:50:12 +00:00
// Let's make the overflow utility responsive
@include utilities-set-option(overflow, responsive, true);
2021-05-22 00:51:30 -07:00
2022-03-16 12:50:12 +00:00
// Or revert the class for the margin-start utilities to their v4 values
@include utilities-set-option(margin-start, class, ml);
2021-05-22 00:51:30 -07:00
2022-03-16 12:50:12 +00:00
// Let's make line-height responsive and override its values
@include utilities-set-options(line-height, (
responsive: true,
values: (
1: 1,
1.25: 1.25,
1.5: 1.5
inherit: inherit
)
));
2021-05-22 00:51:30 -07:00
2022-03-16 12:50:12 +00:00
@import 'bootstrap/scss/utilities/api';
2021-05-22 00:51:30 -07:00
```
2022-03-16 12:50:12 +00:00
#### Updating utility values
2021-01-13 20:01:36 +01:00
2022-03-16 12:50:12 +00:00
If you want to keep most of the default values for a utility, and just add, remove or update a few,
replacing the `values` option can be a bit of a burden to maintain.
`utilities-add-values` and `utilities-remove-values` mixins will help you make these targeted updates.
2021-01-13 20:01:36 +01:00
```scss
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2021-11-23 09:06:33 +01:00
@import "bootstrap/scss/maps";
2021-11-03 05:31:21 -07:00
@import "bootstrap/scss/mixins";
2021-01-13 20:01:36 +01:00
2022-03-16 12:50:12 +00:00
@import 'bootstrap/scss/utilities';
2022-05-26 14:11:27 -07:00
2022-03-16 12:50:12 +00:00
// Let's add a few new values to the `flex` utility
@include utilities-add-values(flex, (
none: none,
auto: auto
));
// And remove the row-reverse and column-reverse from flex-direction
@include utilities-remove-values(flex-direction, row-reverse, column-reverse);
@import 'bootstrap/scss/utilities/api';
2021-01-13 20:01:36 +01:00
```
2022-03-16 12:50:12 +00:00
#### Practical examples
2020-11-03 10:44:03 -08:00
2022-03-16 12:50:12 +00:00
##### Enable responsive
You can enable responsive classes for an existing set of utilities that are not currently responsive by default. For example, to make the `border` classes responsive:
2020-11-03 10:44:03 -08:00
```scss
2021-01-05 12:11:56 -08:00
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2021-11-23 09:06:33 +01:00
@import "bootstrap/scss/maps";
2021-11-03 05:31:21 -07:00
@import "bootstrap/scss/mixins";
2022-03-16 12:50:12 +00:00
2020-11-03 10:44:03 -08:00
@import "bootstrap/scss/utilities";
2022-05-26 14:11:27 -07:00
2022-03-16 12:50:12 +00:00
@include utilities-set-option(border, responsive, true);
2022-05-26 14:11:27 -07:00
2021-11-03 05:31:21 -07:00
@import "bootstrap/scss/utilities/api";
2022-05-26 14:11:27 -07:00
```
2022-03-16 12:50:12 +00:00
##### Rename utilities
Missing v4 utilities, or used to another naming convention? The utilities API can be used to override the resulting `class` of a given utility—for example, to rename `.ms-*` utilities to oldish `.ml-*` :
2022-05-26 14:11:27 -07:00
```scss
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
2022-03-16 12:50:12 +00:00
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/utilities";
2020-11-03 10:44:03 -08:00
2022-03-16 12:50:12 +00:00
@include utilities-set-option(margin-start, class, ml);
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/utilities/api";
```
2022-03-16 12:50:12 +00:00
##### Remove utility in RTL
2022-05-26 14:11:27 -07:00
2022-03-16 12:50:12 +00:00
Some edge cases make [RTL styling difficult ](https://rtlstyling.com/posts/rtl-styling#common-things-that-might-not-work-for-rtl ), such as line breaks in Arabic. Thus utilities can be dropped from RTL output by setting the `rtl` option to `false` :
2022-05-26 14:11:27 -07:00
```scss
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
2023-01-16 16:05:53 -08:00
@import "bootstrap/scss/variables-dark";
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
2022-03-16 12:50:12 +00:00
@import "bootstrap/scss/utilities";
2022-05-26 14:11:27 -07:00
2022-03-16 12:50:12 +00:00
@include utilities-set-option(word-wrap, rtl, false);
2022-05-26 14:11:27 -07:00
@import "bootstrap/scss/utilities/api";
2020-11-03 10:44:03 -08:00
```
2020-06-09 16:44:20 +03:00
Output:
```css
/* rtl:begin:remove */
.text-break {
word-wrap: break-word !important;
word-break: break-word !important;
}
/* rtl:end:remove */
```
This doesn't output anything in RTL, thanks to [the RTLCSS `remove` control directive ](https://rtlcss.com/learn/usage-guide/control-directives/#remove ).
2022-03-16 12:50:12 +00:00
### Referring to the utilities configuration
The `utilities-get-value` function let your grab a specific value of a utility.
This can help you run some computations with it, either in Sass or with `calc()` .
It also lets you access values that can be tweaked by other utilities,
(like how `bg` , `text` and `border` can be tweaked by `bg-opacity` , `text-opacity` or `border-opacity` respectively).
```scss
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/variables-dark";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";
// The box will be configurable with the bg-opacity and text-opacity classes
.box {
border: utilities-get-value(border, null);
padding: map-get($spacers, 3);
background: utilities-get-value(background-color, body);
color: utilities-get-value(color, body);
}
```
This is likely the function you'll use the most, but you can also:
- access all the values of a utility with `utilities-get-values` , which will always return a map to simplify their processing
- access a specific option with `utilities-get-option`
- or even all the options with `utilities-get-options`