Forms & buttons

Consistent reset styles for standard HTML form and button elements.

Examples

Forms

Fieldset legend







Buttons

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 forms-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

_forms-buttons.scss
// ---------------------------------------------------------- 
// Forms and buttons
// ----------------------------------------------------------
$button-form-font-family:  inherit !default;
$input-focus-shadow:       var(--focus-shadow, 0 0 0 0.12rem) !default;
$input-focus-color:        var(--focus-color, color-mix(in srgb, CanvasText 16%, Canvas)) !default;

$button-text-color:        var(--btn-text, CanvasText) !default;
$button-font-size:         var(--btn-fs, inherit) !default;
$button-line-height:       var(--btn-lh, inherit) !default;
$button-padding-block:     var(--btn-py, 0.313rem) !default;
$button-padding-inline:    var(--btn-px, 0.75rem) !default;
$button-border-color:      var(--btn-bd-color, color-mix(in srgb, CanvasText 12%, Canvas)) !default;
$button-radius:            var(--btn-radius, 0.188rem) !default;
$button-background-color:  var(--btn-bg, color-mix(in srgb, CanvasText 3%, Canvas)) !default;
$button-background-hover:  var(--btn-hover, color-mix(in srgb, CanvasText 6%, Canvas)) !default;

$form-text-color:          var(--form-text, inherit) !default;
$form-font-size:           var(--form-fs, inherit) !default;
$form-line-height:         var(--form-lh, inherit) !default;
$form-padding-block:       var(--form-py, 0.313rem) !default;
$form-padding-inline:      var(--form-px, 0.5rem) !default;
$form-border-color:        var(--form-bd-color, color-mix(in srgb, CanvasText 12%, Canvas)) !default;
$form-radius:              var(--form-radius, 0.188rem) !default;
$form-background-color:    var(--form-bg, Canvas) !default;
$accent-color:             var(--accent, initial) !default;
$fieldset-border-color:    var(--form-bd-color, color-mix(in srgb, CanvasText 12%, Canvas)) !default;
$fieldset-radius:          0.125em !default;
$fieldset-margin-bottom:   1.25rem !default;
$fieldset-padding-inline:  1.25rem !default;
$legend-margin-bottom:     0.25rem !default;
$legend-padding-block:     var(--form-py, 0.313rem) !default;
$legend-padding-inline:    0.75rem !default;
$legend-background-color:  var(--btn-bg, color-mix(in srgb, CanvasText 3%, Canvas)) !default;

@mixin forms-buttons-css {

:where(input, button, select, optgroup, textarea),
::file-selector-button {
  font-family: $button-form-font-family;
}

:where(button, [type=button], [type=submit], [type=reset]),
::file-selector-button {
  color: $button-text-color;
  font-size: $button-font-size;
  line-height: $button-line-height;
  padding-block: $button-padding-block;
  padding-inline: $button-padding-inline;
  border: 1px solid $button-border-color;
  border-radius: $button-radius;
  background-color: $button-background-color;
  -webkit-appearance: button;
}

:where(select, optgroup, textarea, input:not([type=button], [type=submit], [type=reset])) {
  color: $form-text-color;
  font-size: $form-font-size;
  line-height: $form-line-height;
  padding-block: $form-padding-block;
  padding-inline: $form-padding-inline;
  border: 1px solid $form-border-color;
  border-radius: $form-radius;
  background-color: $form-background-color;
}

:where(input, button, select, optgroup, textarea):disabled,
:where([aria-disabled=true]) {
  opacity: 0.65;
  pointer-events: none;
}

:where(button, select, optgroup, [type=button], [type=submit], [type=reset]),
::file-selector-button {
  cursor: pointer;
}

:where([type=file]) {
  --form-bg: transparent;
  --form-py: 0;
  --form-px: 0;
  border: none;
}

::file-selector-button {
  margin-inline-end: 0.5rem;
}

:where(input, button, select, optgroup, textarea):focus {
  outline: none;
  box-shadow: $input-focus-shadow $input-focus-color;
}

:where(input, button, select, optgroup, textarea):focus:not(:focus-visible) {
  box-shadow: none;
}

:where(button, [type=button], [type=submit], [type=reset]):is(:hover, :focus) {
  background-color: $button-background-hover;
}

:where(button, [type=button], [type=submit], [type=reset], .btn):focus:not(:focus-visible) {
  background-color: $button-background-color;
}

:where(button, [type=button], [type=submit], [type=reset]):focus:not(:focus-visible):hover,
::file-selector-button:hover {
  background-color: $button-background-hover;
}

:where(textarea) {
  display: block;
  resize: vertical;
}

::-webkit-input-placeholder {
  color: var(--btn-text, inherit);
  opacity: 0.5;
}

:where([type=radio], [type=checkbox], [type=range], [progress]) {
  accent-color: $accent-color;
}

:where([type=checkbox], [type=radio]) {
  block-size: var(--input-size, initial);
  inline-size: var(--input-size, initial);
}

:where([type=checkbox], [type=radio]):has(+ label) {
  margin-block-start: -0.22rem;
  margin-inline-end: 0.2rem;
}

:where(select) {
  word-wrap: normal;
}

:where(fieldset, legend) {
  border: 1px solid $fieldset-border-color;
  border-radius: $fieldset-radius;
}

:where(fieldset) {
  margin-block-end: $fieldset-margin-bottom;
  padding-inline: $fieldset-padding-inline;
}

:where(legend) {
  margin-block-end: $legend-margin-bottom;
  padding-block: $legend-padding-block;
  padding-inline: $legend-padding-inline;
  background-color: $legend-background-color;
}

:where([type=color]) {
  cursor: pointer;
  padding: 0;
}

:where(input[type=color])::-webkit-color-swatch-wrapper {
  padding: 0;
}

:where(input[type=color i])::-webkit-color-swatch {
  border-color: var(--form-bd-color, color-mix(in srgb, CanvasText 12%, Canvas));
}

:where(input):autofill,
:where(input):-webkit-autofill {
  border: 1px solid var(--form-bd-color, color-mix(in srgb, CanvasText 12%, Canvas));
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1.5rem var(--form-bg, Canvas) inset;
}

} // end forms-buttons-css