Opacity
Standard opacity utility classes with module mixins for responsive modifiers.
Examples (anchor)
The examples below demonstrate the styles but fail contrast-ratio testing for content accessibility, so please be aware of accessibility concerns when using opacity styles with text content.
<div class="bg bg-blue opacity-100">100%</div>
<div class="bg bg-blue opacity-75">75%</div>
<div class="bg bg-blue opacity-50">50%</div>
<div class="bg bg-blue opacity-25">25%</div>
Use the .opacity-v
utility to customize opacity with custom values inline
<div class="bg bg-blue opacity-v" style="--op:0.85;">85%</div>
<div class="bg bg-blue opacity-v" style="--op:0.66;">66%</div>
<div class="bg bg-blue opacity-v" style="--op:0.33;">33%</div>
<div class="bg bg-blue opacity-v" style="--op:0.15;">15%</div>
Using the module (anchor)
To use the module load the StyleMods scss
directory as follows (changing the path to suit the source files location as required) then include the Sass mixin anywhere below.
@use "stylemods/scss" as *;
@include opacity-css;
Responsive modifier mixins can be included in custom breakpoints:
@use "stylemods/scss" as *;
@include opacity-css;
@media (max-width: 480px) {
@include opacity-sm-css;
}
Source code (anchor)
See customizing for information about using the Sass and CSS variables in the source code to customize the styles, and Sass functionality (on the using StyleMods page) for other ways to use the variables to create custom styles.
opacity.scss
// ----------------------------------------------------------
// Opacity
// ----------------------------------------------------------
$opacity-100: 1 !default;
$opacity-75: 0.75 !default;
$opacity-50: 0.5 !default;
$opacity-25: 0.25 !default;
$opacity-variable: var(--op) !default;
$opacity-values: (
"100": $opacity-100,
"75": $opacity-75,
"50": $opacity-50,
"25": $opacity-25,
"v": $opacity-variable,
) !default;
@mixin opacity-css {
@each $name, $value in $opacity-values {
.opacity-#{$name} {
opacity: #{$value};
}
}
}
@mixin opacity-xxl-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-xxl {
opacity: #{$value};
}
}
}
@mixin opacity-xl-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-xl {
opacity: #{$value};
}
}
}
@mixin opacity-lg-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-lg {
opacity: #{$value};
}
}
}
@mixin opacity-md-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-md {
opacity: #{$value};
}
}
}
@mixin opacity-sm-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-sm {
opacity: #{$value};
}
}
}
@mixin opacity-xs-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-xs {
opacity: #{$value};
}
}
}
@mixin opacity-xxs-css {
@each $name, $value in $opacity-values {
.opacity-#{$name}-xxs {
opacity: #{$value};
}
}
}