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:

  1. .opacity-0 { opacity: 0; }
  2. .opacity-25 { opacity: .25; }
  3. .opacity-50 { opacity: .5; }
  4. .opacity-75 { opacity: .75; }
  5. .opacity-100 { opacity: 1; }

Use the class option to change the class prefix used in the compiled CSS:

  1. $utilities: (
  2. "opacity": (
  3. property: opacity,
  4. class: o,
  5. values: (
  6. 0: 0,
  7. 25: .25,
  8. 50: .5,
  9. 75: .75,
  10. 100: 1,
  11. )
  12. )
  13. );

Output:

  1. .o-0 { opacity: 0; }
  2. .o-25 { opacity: .25; }
  3. .o-50 { opacity: .5; }
  4. .o-75 { opacity: .75; }
  5. .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.

  1. $utilities: (
  2. "opacity": (
  3. property: opacity,
  4. class: opacity,
  5. state: hover,
  6. values: (
  7. 0: 0,
  8. 25: .25,
  9. 50: .5,
  10. 75: .75,
  11. 100: 1,
  12. )
  13. )
  14. );

Output:

Responsive utilities

Add the responsive boolean to generate responsive utilities (e.g., .opacity-md-25) across .

  1. $utilities: (
  2. "opacity": (
  3. property: opacity,
  4. values: (
  5. 0: 0,
  6. 25: .25,
  7. 50: .5,
  8. 75: .75,
  9. )
  10. )
  11. );

Output:

  1. .opacity-0 { opacity: 0; }
  2. .opacity-25 { opacity: .25; }
  3. .opacity-50 { opacity: .5; }
  4. .opacity-75 { opacity: .75; }
  5. .opacity-100 { opacity: 1; }
  6. @media (min-width: 576px) {
  7. .opacity-sm-0 { opacity: 0; }
  8. .opacity-sm-25 { opacity: .25; }
  9. .opacity-sm-50 { opacity: .5; }
  10. .opacity-sm-75 { opacity: .75; }
  11. .opacity-sm-100 { opacity: 1; }
  12. }
  13. @media (min-width: 768px) {
  14. .opacity-md-0 { opacity: 0; }
  15. .opacity-md-25 { opacity: .25; }
  16. .opacity-md-50 { opacity: .5; }
  17. .opacity-md-75 { opacity: .75; }
  18. .opacity-md-100 { opacity: 1; }
  19. }
  20. @media (min-width: 992px) {
  21. .opacity-lg-0 { opacity: 0; }
  22. .opacity-lg-25 { opacity: .25; }
  23. .opacity-lg-50 { opacity: .5; }
  24. .opacity-lg-75 { opacity: .75; }
  25. .opacity-lg-100 { opacity: 1; }
  26. }
  27. @media (min-width: 1200px) {
  28. .opacity-xl-0 { opacity: 0; }
  29. .opacity-xl-25 { opacity: .25; }
  30. .opacity-xl-50 { opacity: .5; }
  31. .opacity-xl-75 { opacity: .75; }
  32. .opacity-xl-100 { opacity: 1; }
  33. }
  34. @media (min-width: 1400px) {
  35. .opacity-xxl-0 { opacity: 0; }
  36. .opacity-xxl-25 { opacity: .25; }
  37. .opacity-xxl-50 { opacity: .5; }
  38. .opacity-xxl-75 { opacity: .75; }
  39. .opacity-xxl-100 { opacity: 1; }
  40. }

Override existing utilities by using the same key. For example, if you want additional responsive overflow utility classes, you can do this:

  1. $utilities: (
  2. "overflow": (
  3. responsive: true,
  4. property: overflow,
  5. values: visible hidden scroll auto,
  6. ),
  7. );

Print utilities

Enabling the print option will also generate utility classes for print, which are only applied within the @media print { ... } media query.

  1. $utilities: (
  2. property: opacity,
  3. print: true,
  4. values: (
  5. 0: 0,
  6. 25: .25,
  7. 75: .75,
  8. 100: 1,
  9. )
  10. )
  11. );

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.

  1. @import "bootstrap/scss/utilities";
  2. $utilities: map-merge(
  3. $utilities,
  4. (
  5. "cursor": (
  6. property: cursor,
  7. class: cursor
  8. responsive: true,
  9. values: auto pointer grab,
  10. )
  11. )
  12. );

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.

  1. @import "bootstrap/scss/utilities";
  2. $utilities: map-merge(
  3. $utilities,
  4. (
  5. "width": map-merge(
  6. map-get($utilities, "width"),
  7. (
  8. values: map-merge(
  9. map-get(map-get($utilities, "width"), "values"),
  10. (10: 10%),
  11. ),
  12. ),
  13. ),
  14. )
  15. );

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.

  1. @import "bootstrap/scss/utilities";
  2. $utilities: map-merge(
  3. $utilities,
  4. (
  5. "width": null
  6. )
  7. );

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:

  1. $utilities: (
  2. "word-wrap": (
  3. property: word-wrap word-break,
  4. class: text,
  5. values: (break: break-word),
  6. rtl: false
  7. ),
  8. );

Output:

This doesn’t output anything in RTL, thanks to the RTLCSS remove control directive.