MotivationInstallDocsCustomize
MotivationInstallDocsCustomize
  • Overview
  • Important! Purge!
  • Getting Started
    • Colors and Pseudo Classes
      • Colors
        • Color Shades

        • Psuedo Classes

      • Classes with Colors
        • Text Color

        • Background Color

        • Border Color

        • Outline Color

        • Text Decoration

        • Selection

      • Transitions
        • Transition Classes

        • With Pseudo Classes

      • Additional Classes
        • Font Size

        • Font Family

        • Font Weight

        • Text Decoration & Style

        • Border Width & Style

        • Outline Width & Style

    • Dark Mode
      • With JS

      • No JS

      • Grid
        • Class Definitions

        • Responsive Examples

        • Responsive Examples
          • Breakpoints

          • Max Breakpoints

          • Examples

          • Margin
            • Classes

            • Examples

          • Padding
            • Classes

            • Examples

          • Border Width
            • Classes

            • Examples

          • Outline Width
            • Classes

            • Outline Offset

            • Examples

          • Width
            • Rem Values

            • Percantage Values

            • Screen relative Values

            • XS - XL

          • Height
            • Rem Values

            • Percantage Values

            • Screen relative Values

            • XS - XL

          • Display
          • Flex
            • Flex Direction

            • Flex Wrap

            • Shrink & Grow

            • Justify Content

            • Align Content

            • Align Items

            • Align Self

            • Not Included

          • Text/Font
            • Font Size

            • Line Height

            • Letter Spacing

          • Position
            • Top Left Right & Bottom

          • Overflow
            • Overflow x & y

          • Box Sizing
        • Box-Shadow
          • Size

          • Color

          • Respoinsive

          • Psuedo States

          • Other Utilities
            • Text/Font
              • Align

              • Transform

              • Indent

              • Wrap

              • Font Family

              • Font Weight

              • Font Style

              • Text Decoration

              • Decoration Thickness

            • Border
              • Directional Style

            • Outline Style
            • Cursor
            • Opacity
            • Visibility
            • z-Index

          Simple Scss Utilities


          Margin

          How to use

          Margins and paddings can have both size values such as sm md lg as well as fractional values, which by default cover every 5% up until 100% plus 1/3 and 2/3 fractional values. Like with most other things with many values, both the names and values can be edited in the _variables.scss file. See the Customize section for more details.

          What about Negitive Margins?

          I did not include negitive margins in this framework, since in my experience I don't use 'em that heavily, however, they are useful sometimes. If you need negitive margins it could be a good time to write some custom SCSS.

          Alright let's get into the classes.

          Classes

          Here are the default classes. Note that in addition to the m-[size] classes, there's also .mt,.mb,ml, and mr classes for top, bottom, left, and right margins respectively, as well as .mx and .my classes for both left and right or top and bottom.

          All these clases also respond to the responsive prefixes, see the (Responsive)[/docs/responsive-classes/] section for details for that as well.

          Note that with the fraction classes the percents aren't repeated, for example, there's a 1/20 and a 3/20 margin, but not a 2/20 margin or a 4/20 margin because those are already handled by the 1/10 and 1/5 classes.

          ClassCSS rule
          .m-0margin: 0;
          .m-xxsmargin: 0.125rem;
          .m-xsmargin: 0.25rem;
          .m-smmargin: 0.5rem;
          .m-mdmargin: 0.75rem;
          .m-basemargin: 1rem;
          .m-lgmargin: 1.25rem;
          .m-xlmargin: 1.5rem;
          .m-2xlmargin: 2rem;
          .m-3xlmargin: 3rem;
          .m-4xlmargin: 4rem;
          .m-5xlmargin: 5rem;
          .m-5xlmargin: 5rem;
          .m-1/2margin: 50%
          .m-1/3margin: 33%
          .m-2/3margin: 66%
          .m-1/4margin: 25%
          .m-2/4margin: 50%
          .m-3/4margin: 75%
          .m-1/5margin: 20%
          .m-2/5margin: 40%
          .m-3/5margin: 60%
          .m-4/5margin: 80%
          .m-1/10margin: 10%
          .m-3/10margin: 30%
          .m-7/10margin: 70%
          .m-9/10margin: 90%
          .m-1/20margin: 5%
          .m-3/20margin: 15%
          .m-7/20margin: 35%
          .m-9/20margin: 45%
          .m-11/20margin: 55%
          .m-13/20margin: 65%
          .m-17/20margin: 85%
          .m-19/20margin: 95%
          .m-fullmargin: 100%

          Each of these classes are repeated for top, bottom, left, right, x, and y directions so see some examples below:

          Examples

          Margin Sizes

          These are the example "default" sizes for margins. Note these can all be changed by editing the _variables.scss file. See the Customize section for further info. These are just a collection of examples, each blue box has a margin the size of the caption applied to it:

          .mr-xs

          .mr-lg

          .mr-3xl

          .mr-sm

          .mr-xl

          .mr-4xl

          .mr-md

          .mr-2xl

          .mr-5xl

          Here's what the html for one of the boxes above would look like

          HTML
          <div>
          <div class="bg-background-dkr border-lg border-dark-mode-only-ltr border-dashed">
          <div class="bg-blue w-3 h-3 mr-xl" />
          </div>
          <p>.mr-xl</p>
          </div>

          Fractional Sizes

          Percents are relative to the containing element, so each box here has been given a fixed size, and the margin left pushes it away from the left side by the percent that the fraction is equal to:

          .ml-1/10

          .ml-1/5

          .ml-1/3

          .ml-1/2

          .ml-17/20

          .ml-full

          Here's an example for the HTML of the ml-1/2 box:

          HTML
          <div class="m-md">
          <div class="bg-background-dkr border-lg border-dark-mode-only-ltr border-dashed w-16">
          <div class="bg-blue w-3 h-3 ml-1/2" />
          </div>
          <p>.ml-1/2</p>
          </div>

          Directional Margins

          And here are examples of classes going in each direction. Each "directional" class also works for every one of the widths i.e. sm, md, lg, etc.

          .ml-xl

          .mr-xl

          .mt-xl

          .mb-xl

          .mx-xl

          .my-xl

          A few examples of the above boxes (just mt, mb, and mx):

          HTML
          <div class="display-flex flex-col justify-center ">
          <div class="display-flex center">
          <div class="bg-background-dkr border-dark-mode-only-ltr border-lg border-dashed">
          <div class="bg-blue w-3 h-3 mt-xl" />
          </div>
          </div>
          <p>.mt-xl</p>
          </div>
          <div class="display-flex flex-col justify-center ">
          <div class="display-flex center">
          <div class="bg-background-dkr border-dark-mode-only-ltr border-lg border-dashed">
          <div class="bg-blue w-3 h-3 mb-xl" />
          </div>
          </div>
          <p>.mb-xl</p>
          </div>
          <div class="display-flex flex-col justify-center ">
          <div class="display-flex center">
          <div class="bg-background-dkr border-dark-mode-only-ltr border-lg border-dashed">
          <div class="bg-blue w-3 h-3 mx-xl" />
          </div>
          </div>
          <p>.mx-xl</p>
          </div>

          Responsive Margins

          And finally, here's some examples with the responsive classes set. If you're on a browser, adjust the screen sizes to see them in action, although for small sizes you'll have to close the sidebar:

          .m-sm

          .tab:m-lg

          .scr:m-2xl

          .lg:m-3xl

          Code for the Box:

          HTML
          <div class="bg-background-dkr border-dark-mode-only-ltr border-lg border-dashed radius-md mb-md">
          <div class="w-5 h-5 m-sm tab:m-lg scr:m-2xl lg:m-3xl bg-blue radius-md" />
          </div>

          Responive margin with the max-[breakpoint] classes. Here the margin left is 1/4 for widths under 1024px and 3/4 for widths over that amount:

          .max-scr:ml-1/4

          .ml-3/4

          And here's the HTML:

          HTML
          <div class="center flex-col m-xl">
          <div class="bg-background-dkr border-lg border-dark-mode-only-ltr border-dashed w-16">
          <div class="bg-blue w-3 h-3 ml-3/4 max-scr:ml-1/4" />
          </div>
          </div>

          Anyway hope that clears up how the margin works.

          Happy coding!

          © 2025 Simple Scss Utilities