Skip to content

Margins

A set of commonly used margin spacing utilities with module mixins for responsive modifiers.

Utilities (anchor)

Margin utilities and property values
Utility name Property values
Margin
.m-auto margin: auto
.m-0 margin: 0
.m-1 margin: 0.25rem
.m-2 margin: 0.5rem
.m-3 margin: 1rem
.m-4 margin: 1.5rem
.m-5 margin: 2rem
Margin block
.my-auto margin-block: auto
.my-0 margin-block: 0
.my-1 margin-block: 0.25rem
.my-2 margin-block: 0.5rem
.my-3 margin-block: 1rem
.my-4 margin-block: 1.5rem
.my-5 margin-block: 2rem
Margin block start
.mt-auto margin-block-start: auto
.mt-0 margin-block-start: 0
.mt-1 margin-block-start: 0.25rem
.mt-2 margin-block-start: 0.5rem
.mt-3 margin-block-start: 1rem
.mt-4 margin-block-start: 1.5rem
.mt-5 margin-block-start: 2rem
Margin block end
.mb-auto margin-block-end: auto
.mb-0 margin-block-end: 0
.mb-1 margin-block-end: 0.25rem
.mb-2 margin-block-end: 0.5rem
.mb-3 margin-block-end: 1rem
.mb-4 margin-block-end: 1.5rem
.mb-5 margin-block-end: 2rem
Margin inline
.mx-auto margin-inline: auto
.mx-0 margin-inline: 0
.mx-1 margin-inline: 0.25rem
.mx-2 margin-inline: 0.5rem
.mx-3 margin-inline: 1rem
.mx-4 margin-inline: 1.5rem
.mx-5 margin-inline: 2rem
Margin inline start
.ms-auto margin-inline-start: auto
.ms-0 margin-inline-start: 0
.ms-1 margin-inline-start: 0.25rem
.ms-2 margin-inline-start: 0.5rem
.ms-3 margin-inline-start: 1rem
.ms-4 margin-inline-start: 1.5rem
.ms-5 margin-inline-start: 2rem
Margin inline end
.me-auto margin-inline-end: auto
.me-0 margin-inline-end: 0
.me-1 margin-inline-end: 0.25rem
.me-2 margin-inline-end: 0.5rem
.me-3 margin-inline-end: 1rem
.me-4 margin-inline-end: 1.5rem
.me-5 margin-inline-end: 2rem

Responsive mixins (anchor)

Responsive modifier mixins are provided to include where required in custom breakpoints, the utilities available use the following modifier class naming convention:

.m-auto
.m-auto-xxl
.m-auto-xl
.m-auto-lg
.m-auto-md
.m-auto-sm
.m-auto-xs
.m-auto-xxs

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 margins-css;

// Example breakpoint
@media (width < 480px) {
  @include margins-sm-css;
}

See the using modules page for more information.

Using the framework (anchor)

Using the recommended custom setup enable the styles (and required breakpoints) in an overrides document:

overrides.scss
@use "stylemods/scss/configuration" as *;
$enable-margins:      true;
$enable-margins-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.

Source code (anchor)

The Margins source file is included with the layout module files, you can view the source code from the latest release (v1.5.0) via the Github link below.

Source document
stylemods/scss/layout/margins.scss
View on Github
https://github.com/pmbrown/StyleMods/blob/main/scss/layout/margins.scss

Shared documentation about how to customize the default property values for the styles using the Sass and CSS variables is provided on the customizing page.