Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Bootstrap
  • Tailwind
  • Bulma
  • Foundation
  • Primer
  • Spectre
  • Onsen UI
  • Semantic UI
  • Pure CSS
  • Materialize
  • SASS
  • LESS
  • Blaze UI
  • CSS Frameworks
  • Color Picker
  • CSS
  • CSS Formatter
  • Web Technology
Open In App
Next Article:
Primer CSS Extended Spacing Scale
Next article icon

Primer CSS Em-based Spacing

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
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.

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.

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


Next Article
Primer CSS Extended Spacing Scale

H

harshil99
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • CSS
  • Technical Scripter 2022
  • Primer-CSS
  • Primer-CSS Support

Similar Reads

  • 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 ste
    4 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 Git
    3 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:
    2 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 hel
    3 min read
  • Primer CSS Right Aligned
    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
    2 min read
  • Primer CSS Medium Box Shadow
    Primer CSS is a free open-source CSS framework that is built upon systems that create 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 CS
    2 min read
  • Primer CSS Blankslate Variations
    Primer CSS is a free open-source CSS framework that is built upon 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 ste
    3 min read
  • Primer CSS Large Box Shadow
    Primer CSS is a free open-source CSS framework that is built upon systems that create 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 CS
    2 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
    2 min read
  • CSS word-spacing Property
    The word-spacing property adjusts the white space between words, increasing or decreasing. This CSS property can be set to normal or a specific length (positive or negative), improving readability and text formatting. Syntaxword-spacing: normal|length|initial|inherit;Property valuesNormalDefines the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences