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.

100%
75%
50%
25%
<div class="grid g-4 gap-2 mb-3" style="--bg-col:royalblue">
<div class="bg p-3 opacity-100">100%</div>
<div class="bg p-3 opacity-75">75%</div>
<div class="bg p-3 opacity-50">50%</div>
<div class="bg p-3 opacity-25">25%</div>
</div>

Use the .opacity-v utility to customize opacity with custom values inline:

85%
66%
33%
15%
<div class="grid g-4 gap-2 mb-3" style="--bg-col:royalblue">
<div class="bg p-3 opacity-v" style="--op:0.85;">85%</div>
<div class="bg p-3 opacity-v" style="--op:0.66;">66%</div>
<div class="bg p-3 opacity-v" style="--op:0.33;">33%</div>
<div class="bg p-3 opacity-v" style="--op:0.15;">15%</div>
</div>

Using the module (anchor)

Load StyleMods as demonstrated (change file path as required) then include the Sass mixin anywhere below.

custom.scss
@use "stylemods/scss" as *;
@include opacity-css;

Responsive modifier mixins can be included in custom breakpoints:

custom.scss
@use "stylemods/scss" as *;
@include opacity-css;
@media (max-width: 480px) {
  @include opacity-sm-css;
}

See the using modules page for more information including how to compile the modules in cascade layers and include and reuse them in multiple source files.

Using the framework (anchor)

Using the recommended custom setup enable the styles in an overrides document:

overrides.scss
@use "stylemods/scss/configuration" as *;
$enable-opacity:      true;
// Breakpoints
$enable-opacity-lg:   true;
$enable-opacity-md:   true;
$enable-opacity-sm:   true;

Include the overrides and the framework styles with your custom document for compiling the framework:

custom.scss
@use "overrides";
@use "stylemods/scss/stylemods";

See using the framework for more information including how the styles can also be compiled within cascade layers.

Source code (anchor)

The modules and the framework follow the same methods for customizing the default values and using the CSS variables to create custom theme documents. See the customizing page for more information.

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};        
    }
  }
}