Buttons

A basic button utility including size modifier classes and a button group wrapper utility.

Examples

Generic button utility

Link

Button sizes

Button group

Examples HTML
<a href="#" class="btn">Link</a>
<button class="btn">Button</button>

<button class="btn btn-xs">Extra small</button>
<button class="btn btn-sm">Small</button>
<button class="btn btn">Normal</button>
<button class="btn btn-lg">Large</button>
<button class="btn btn-xl">Extra large</button>

<div class="btn-group" role="group" aria-label="Button group">
<button class="btn">One</button>
<button class="btn">Two</button>
<button class="btn">Three</button>
<button class="btn">Four</button>
</div>

Using the module

Add the sassmods.scss to your custom styles as below then include the Sass mixin anywhere below.

custom.scss
@use "sassmods/scss/sassmods" as *;
@include buttons-css;

See customizing for information about using the Sass and CSS variables in the source code (see below) to customize the styles, and Sass variables (on the using SassMods page) for other ways to use the variables to create custom styles.

Source

_buttons.scss
// ---------------------------------------------------------- 
// Buttons
// ----------------------------------------------------------
$btn-text-color:          var(--btn-text, CanvasText) !default;
$btn-font-size:           var(--btn-fs, inherit) !default;
$btn-line-height:         var(--btn-lh, inherit) !default;
$btn-padding-block:       var(--btn-py, 0.313rem) !default;
$btn-padding-inline:      var(--btn-px, 0.75rem) !default;  
$btn-border-color:        var(--btn-bd-color, color-mix(in srgb, CanvasText 12%, Canvas)) !default;
$btn-radius:              var(--btn-radius, 0.125em) !default;
$btn-background-color:    var(--btn-bg, color-mix(in srgb, CanvasText 3%, Canvas)) !default;
$btn-background-hover:    var(--btn-hover, color-mix(in srgb, CanvasText 6%, Canvas)) !default;
$btn-focus-shadow:        var(--focus-shadow, 0 0 0 0.12rem) !default;
$btn-focus-shadow-color:  var(--focus-color, color-mix(in srgb, CanvasText 16%, Canvas)) !default;

@mixin buttons-css {

.btn {
  color: $btn-text-color;
  font-size: $btn-font-size;
  line-height: $btn-line-height;
  text-align: center;
  text-decoration: none;
  display: var(--btn-d, inline-block); 
  padding-block: $btn-padding-block;
  padding-inline: $btn-padding-inline;  
  border: 1px solid $btn-border-color;
  border-radius: $btn-radius;
  background-color: $btn-background-color;
  cursor: pointer;
  -webkit-appearance: button;
}

.btn:is(:hover, :focus, :active) { 
  color: $btn-text-color;
  background-color: $btn-background-hover;
}

.btn:focus {
  outline: none;
  box-shadow: $btn-focus-shadow $btn-focus-shadow-color;
}

.btn:focus:not(:focus-visible) {  
  box-shadow: none;
  background-color: $btn-background-color;
}
  
.btn:focus:not(:focus-visible):hover {
  background-color: $btn-background-hover;
}

.btn-xs {
  --btn-fs: 0.75em;
  --btn-py: .15rem;
  --btn-px: .35rem;
}

.btn-sm {
  --btn-fs: 0.88em;
  --btn-py: .25rem;
  --btn-px: .5rem;
}

.btn-lg {
  --btn-fs: 1.1em;
  --btn-py: .35rem;
  --btn-px: .85rem;
}

.btn-xl {
  --btn-fs: 1.25em;
  --btn-py: .5rem;
  --btn-px: 1rem;
}

.btn-group {
  display: flex;
}

.btn-group * {
  border-radius: 0;
}

.btn-group *:not(:first-child) {
  margin-inline-start: -1px;
}

.btn-group *:first-child {
  border-start-start-radius: $btn-radius;
  border-end-start-radius: $btn-radius;
}

.btn-group *:last-child {
  border-start-end-radius: $btn-radius;
  border-end-end-radius: $btn-radius;
}

.btn-group *:is(:focus) {
  box-shadow: none;
}

} // end buttons-css