Open In App

Primer CSS Spacing

Last Updated : 15 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Primer CSS is a free open-source CSS framework that is built with the GitHub design system to provide support to the broad spectrum of Github websites. It creates the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, and BEM architecture. It is a highly reusable model.

Primer CSS Spacing can be utilized to provide the indentation around the element by implementing the defined classes i.e. it is used to provide the spacing within the components such as buttons, form elements, etc. It is primarily used to achieve a bigger vertical as well as horizontal spacing between the sections.

Primer CSS Spacing Components:

  • Spacing scale: It is a predefined range of values that is used to specify the amount of the utilities like margin, padding, etc. It is used in Primer CSS is a base-8 scale, using it is extremely flexible because we can multiply or divide the eight as many times as we want and we will end up with whole numbers.
  • Extended spacing scale: It adds six more options to the existing spacing scale. That means the scale which had the range of 0-6 is now increased to 7-12. But this extended range doesn’t work for every utility class in every direction. We can use extended class is in margin and padding. The extended range i.e., 7-12 doesn’t work on the x-axis but does work on the left and right sides individually for margin and padding. But for margin, we cannot use that 7-12 range for the complete x-axis neither together nor individually. Unlike the Basic Scaling Scale in the Extended part, the value increases by 16px instead of 8px.
  • Em-based spacing: It is mainly used to provide the spacing between the components, having the values in em, for which the value combined with typography, line-height, or the total height becomes sensible numbers.

Syntax:

<div class="Primer-CSS-SpacingClasses">
   ...
</div>

We can provide spacing around the element in 2 ways, i.e. by using the padding & margin that will create space around the elements. 

Please refer to the Primer CSS Padding & Primer CSS Margin articles for a detailed description.

Example 1: This example describes the Primer CSS Spacing by demonstrating the uniform padding utilities using the required classes in it.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0" />
    <title>Primer CSS Spacing</title>
    <link href=
"https://unpkg.com/@primer/css@^19.0.0/dist/primer.css" 
          rel="stylesheet" />
</head>
  
<body>
    <center>
        <h1 class="color-fg-open">
              GeeksforGeeks
          </h1>
        <h3>Primer CSS Spacing</h3
    </center
    <strong>p-0:</strong>
        <div class="p-0 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-1:</strong>
        <div class="p-1 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-2:</strong>
        <div class="p-2 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-3:</strong>
        <div class="p-3 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-4:</strong>
        <div class="p-4 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-5:</strong>
        <div class="p-5 color-bg-success">
            GeeksforGeeks 
        </div
    <strong>p-6:</strong>
        <div class="p-6 color-bg-success">
            GeeksforGeeks 
        </div>
</body>
</html>


Output:

 

Example 2: This example describes the Primer CSS Spacing by demonstrating the uniform margin utilities using the required classes in it.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0" />
    <title>Primer CSS Spacing</title>
    <link href=
"https://unpkg.com/@primer/css@^19.0.0/dist/primer.css" 
          rel="stylesheet" />
</head>
  
<body>
    <div class="m-4">
        <h1 class="color-fg-success">
            GeeksforGeeks
        </h1>
        <h2>Primer CSS Spacing</h2
    </div>
    <div class="d-flex flex-items-baseline flex-justify-around">
        <div class="color-bg-success">
            <div class="m-0 p-1 color-bg-success-emphasis">
                .m-0 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-1 p-1 color-bg-success-emphasis">
                .m-1 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-2 p-1 color-bg-success-emphasis">
                .m-2 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-3 p-1 color-bg-success-emphasis">
                .m-3 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-4 p-1 color-bg-success-emphasis">
                .m-4 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-5 p-1 color-bg-success-emphasis">
                .m-5 
            </div>
        </div>
        <div class="color-bg-success">
            <div class="m-6 p-1 color-bg-success-emphasis">
                .m-6 
            </div>
        </div>
    </div>
</body>
</html>


Output: 

 

Reference: https://primer.style/css/support/spacing



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads