New Update:
Good news! Starting from Bootstrap version 5.3, the breakpoint variables are back and readily available out of the box. You can easily access them using the following JavaScript:
getComputedStyle(document.body)
.getPropertyValue('--bs-breakpoint-md');
Previous Information:
In Bootstrap 4, all breakpoints were added as variables to the root. However, in Bootstrap 5, this is no longer the case, and you will need to create them manually using SASS. Simply add the following code to your styles.scss file:
:root {
@each $breakpoint, $value in $grid-breakpoints {
--breakpoint-#{$breakpoint}: #{$value};
}
}
The resulting output (which can also be added directly in the styles.css) will look like this:
:root {
--breakpoint-xs: 0;
--breakpoint-sm: 576px;
--breakpoint-md: 768px;
--breakpoint-lg: 992px;
--breakpoint-xl: 1200px;
--breakpoint-xxl: 1400px;
}
After implementing this, your JavaScript functionality should continue to work smoothly as before.
Note: With Bootstrap 5, there is also a change in using prefixes for CSS variables. For more information, refer to the official documentation on prefixes.