The 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:
All utility variables are added to the $utilities
variable within our _utilities.scss
stylesheet. Each group of utilities looks something like this:
Which outputs the following:
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
Use the class
option to change the class prefix used in the compiled CSS:
$utilities: (
"opacity": (
property: opacity,
class: o,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Output:
.o-0 { opacity: 0; }
.o-25 { opacity: .25; }
.o-50 { opacity: .5; }
.o-75 { opacity: .75; }
.o-100 { opacity: 1; }
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.
$utilities: (
"opacity": (
property: opacity,
class: opacity,
state: hover,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Output:
Responsive utilities
Add the responsive
boolean to generate responsive utilities (e.g., .opacity-md-25
) across .
$utilities: (
"opacity": (
property: opacity,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
)
)
);
Output:
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
@media (min-width: 576px) {
.opacity-sm-0 { opacity: 0; }
.opacity-sm-25 { opacity: .25; }
.opacity-sm-50 { opacity: .5; }
.opacity-sm-75 { opacity: .75; }
.opacity-sm-100 { opacity: 1; }
}
@media (min-width: 768px) {
.opacity-md-0 { opacity: 0; }
.opacity-md-25 { opacity: .25; }
.opacity-md-50 { opacity: .5; }
.opacity-md-75 { opacity: .75; }
.opacity-md-100 { opacity: 1; }
}
@media (min-width: 992px) {
.opacity-lg-0 { opacity: 0; }
.opacity-lg-25 { opacity: .25; }
.opacity-lg-50 { opacity: .5; }
.opacity-lg-75 { opacity: .75; }
.opacity-lg-100 { opacity: 1; }
}
@media (min-width: 1200px) {
.opacity-xl-0 { opacity: 0; }
.opacity-xl-25 { opacity: .25; }
.opacity-xl-50 { opacity: .5; }
.opacity-xl-75 { opacity: .75; }
.opacity-xl-100 { opacity: 1; }
}
@media (min-width: 1400px) {
.opacity-xxl-0 { opacity: 0; }
.opacity-xxl-25 { opacity: .25; }
.opacity-xxl-50 { opacity: .5; }
.opacity-xxl-75 { opacity: .75; }
.opacity-xxl-100 { opacity: 1; }
}
Override existing utilities by using the same key. For example, if you want additional responsive overflow utility classes, you can do this:
$utilities: (
"overflow": (
responsive: true,
property: overflow,
values: visible hidden scroll auto,
),
);
Print utilities
Enabling the print
option will also generate utility classes for print, which are only applied within the @media print { ... }
media query.
$utilities: (
property: opacity,
print: true,
values: (
0: 0,
25: .25,
75: .75,
100: 1,
)
)
);
Output:
New utilities can be added to the default $utilities
map with a map-merge
. Make sure our _utilities.scss
is 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.
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"cursor": (
property: cursor,
class: cursor
responsive: true,
values: auto pointer grab,
)
)
);
Modify utilities
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.
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": map-merge(
map-get($utilities, "width"),
(
values: map-merge(
map-get(map-get($utilities, "width"), "values"),
(10: 10%),
),
),
),
)
);
Remove any of the default utilities by setting the group key to null
. For example, to remove all our width
utilities, create a $utilities
map-merge
and add "width": null
within.
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": null
)
);
Remove utility in RTL
Some edge cases make , such as line breaks in Arabic. Thus utilities can be dropped from RTL output by setting the rtl
option to false
:
$utilities: (
"word-wrap": (
property: word-wrap word-break,
class: text,
values: (break: break-word),
rtl: false
),
);
Output:
This doesn’t output anything in RTL, thanks to the RTLCSS remove
control directive.