VOOZH about

URL: https://www.geeksforgeeks.org/css/primer-css-em-based-spacing/

⇱ Primer CSS Em-based Spacing - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Primer CSS Em-based Spacing

Last Updated : 23 Jul, 2025

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.

VariablesFractionY Padding (em)Total height at 14pxTotal height at 16px
$em-spacer-11/16.062522.7526
$em-spacer-21/8.12524.528
$em-spacer-31/4.252832
$em-spacer-43/8.37531.536
$em-spacer-51/2.53540
$em-spacer-63/4.754248

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.

SCSS:

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

CSS:

.gap{
 gap: 1em;
 }

Output:

👁 Image
 

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

SCSS:

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

CSS:

.left{
 padding: 1em;
 }

Output:

👁 Image
 

References: https://primer.style/

Comment