Open In App

Primer CSS Em-based Spacing

Last Updated : 18 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Primer CSS Spacing contains Em-based Spacing which 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.

GitHub’s body font size is 14px which is difficult to work with, so we sometimes can’t achieve a whole number. Variables listed below are preferred for use within components and custom CSS.

Variables Fraction Y Padding (em) Total height at 14px Total height at 16px
$em-spacer-1 1/16 .0625 22.75 26
$em-spacer-2 1/8 .125 24.5 28
$em-spacer-3 1/4 .25 28 32
$em-spacer-4 3/8 .375 31.5 36
$em-spacer-5 1/2 .5 35 40
$em-spacer-6 3/4 .75 42 48

Syntax:

$name-of-the-variable: value;

Below examples illustrate the Primer CSS Em-based Spacing

Example 1: In this example, we will render two buttons, by creating our own variable $em-spacer-12 that will hold the value of 1em.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href=
"https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" rel="stylesheet" />
  
</head>
  
<body>
    <div class="text-center">
        <h1 class="color-fg-success">
            GeeksforGeeks
        </h1>
        <h2>Primer CSS Em-based Spacing</h2>
        <br>
        <div class="gap mx-4">
            <button class="color-bg-success">
                <p>Button 1</p>
            </button>
            <button class="color-bg-success">
                <p>Button 2</p>
            </button>
        </div>
    </div>
</body>
  
</html>


SCSS:

$em-spacer-12: 1em;
.gap {
      gap:$em-spacer-12;
}

CSS:

.gap{
    gap: 1em;
      }

Output:

 

Example 2: In this example, we will use spacing inside of the button element as padding.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href=
"https://unpkg.com/@primer/css@^20.2.4/dist/primer.css" rel="stylesheet" />
</head>
  
<body>
    <div class="text-center">
        <h1 class="color-fg-success">
            GeeksforGeeks
        </h1>
        <h2>Primer CSS Em-based Spacing</h2>
        <br>
        <div class="mx-4">
            <button class="color-bg-success">
                <p class="left">Button 1</p>
            </button>
        </div>
    </div>
</body>
  
</html>


SCSS:

$em-spacer-12: 1em;
.left {
      padding:$em-spacer-12;
}

CSS:

.left{
    padding: 1em;
      }

Output:

 

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



Similar Reads

How to Adjust Line Spacing & Letter Spacing in CSS ?
Line spacing and letter spacing are two significant factors in improving a website's readability. They can be utilized to make stunning and intuitive web pages. Below are the approaches to adjust line spacing and letter spacing in CSS: Table of Content Line-Height propertyLetter Spacing propertyLine-Height propertyLine spacing can be adjusted using
3 min read
Primer CSS Spacing
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 approa
4 min read
Primer CSS Extended Spacing Scale
Primer CSS is a free open-source CSS framework built on technologies that provide insights into key design elements like space, typeface, and color. This methodical approach guarantees that the patterns are both consistent and compatible. It's primarily useful and adaptable. It was made with the help of the GitHub design system. Its CSS approach is
3 min read
Primer CSS Spacing Scale
Primer CSS is a free open-source CSS framework based on technologies that provide insights into important style aspects like space, font, and color. This meticulous methodology ensures that its patterns are both stable and compatible. It's mostly practical and adaptable. It was created using the GitHub design system. Object-oriented CSS foundations
3 min read
Primer CSS Float based Grid
Primer CSS is a free open-source CSS framework that is built upon systems that create 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, an
2 min read
CSS letter-spacing Property
The letter-spacing property in CSS is used to set the spacing behavior between text characters i.e increasing or decreasing the space between characters in a text. Syntax: letter-spacing: normal|length|initial|inherit;Property values: normal: The normal letter spacing for the current font i.e no extra space between characters. This is the default v
2 min read
CSS border-spacing Property
The border-spacing Property is used to set the distance between the borders of neighboring cells in the Table. This property works only when the border-collapse property is set to no-collapse separate. Default Value: 2px Syntax: border-spacing: length|initial|inherit; Property values: length-length: It is used to set the distance between the border
2 min read
Tailwind CSS Letter Spacing
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS letter-spacing property. This class is used to set the spacing behavior between text characters i.e, increasing or decreasing the space between characters in a text. Letter Spacing classes: tracking-tighter: Th
2 min read
How to set letter spacing using CSS ?
In this article, we will see how to set letter spacing using CSS. We can define letter spacing as the amount of space between adjacent characters. The default letter-spacing can't change this means it is equivalent to a 0 value. Approach: The letter-spacing CSS property is used to set the horizontal spacing behavior between the text characters. Thi
1 min read
Create a Letter-Spacing Animation Effect using HTML and CSS
In this article, we are going to create a letter-spacing animation using CSS. Letter spacing is the available space between the letters in a particular word, we will walk through each step to achieve this animation effect for our web page. Approach: Initially, letter-spacing will be -15px.At 20%, letter-spacing will be 10px.Finally, at 100% letter-
2 min read