Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • 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 Margin Center elements
Next article icon

Primer CSS Margin Center elements

Last Updated : 16 May, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Primer CSS is a free and open-source CSS framework that is built using the GitHub design system for providing support to the broad spectrum of GitHub websites. It helps in creating the foundation of the basic style elements such as spacing, components, typography, color, etc. 

In this article, we'll see about Primer CSS Margin Center elements. Margin center elements utilities are used to center block elements with equal margins on all sides of the element.

Primer CSS Margin Center elements classes:

  • mx-auto: This class is used to center block elements with a set width.
  • mt-auto: This class is used to provide a directional margin of the top.
  • mb-auto: This class is used to provide a directional margin of the bottom.
  • ml-auto: This class is used to provide a directional margin on the left.
  • mr-auto: This class is used to provide a directional margin on the right.

Syntax:

<div class="color-bg-success">    <div class="mx-auto color-bg-subtle text-center"       style="max-width: 500px;">.mx-auto text</div>  </div>

Example 1: Below example demonstrates margin center elements.

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" />     <title>Primer</title>     <link href= "https://unpkg.com/@primer/css@^19.0.0/dist/primer.css"          rel="stylesheet"/> </head> <body>     <div class="m-4">         <h1 style="color: green">GeeksforGeeks</h1>         <h2>Primer CSS Margin Center Elements</h2>     </div>     <div class="color-bg-success">         <div class="mx-auto color-bg-success-emphasis                      text-center color-fg-on-emphasis"              style="max-width: 500px;">             Welcome to GeeksforGeeks         </div>     </div> </body> </html> 

Output:

 

Example 2: Below example demonstrates all directional auto margins in center elements.

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@^19.0.0/dist/primer.css"         rel="stylesheet" /> </head>  <body>     <div class="m-4">         <h1 style="color: green;">             GeeksforGeeks         </h1>                  <h2>Primer CSS Margin Center Elements</h2>     </div>      <div class="d-flex border mb-4 color-bg-success">         <div style="height:100px;"></div>         <div class="border mt-auto color-bg-success-emphasis              color-fg-on-emphasis">Box at the bottom.</div>         <div class="border mb-auto color-bg-success-emphasis              color-fg-on-emphasis">Box at the top.</div>     </div>     <div class="d-flex flex-column border color-bg-success">         <div class="border ml-auto color-bg-success-emphasis              color-fg-on-emphasis">Box in the right.</div>         <div class="border mr-auto color-bg-success-emphasis              color-fg-on-emphasis">Box in the left.</div>     </div> </body>  </html> 

Output:

 

Reference: https://primer.style/css/utilities/margin#center-elements


Next Article
Primer CSS Margin Center elements

T

tarunsinghwap7
Improve
Article Tags :
  • Web Technologies
  • CSS
  • Primer-CSS
  • Primer-CSS Utilities

Similar Reads

    CSS | Centering Elements
    Sometimes we face problems with centering an element in a web page. Is it really so hard? It is not too difficult to center an element. There so many different ways of doing it. One thing we need to know is that, which technique is for which purpose. Once you understand the problem, picking up the b
    4 min read
    Primer CSS Margin
    Primer CSS is a free and open-source CSS framework that is built using the GitHub design system for providing support to the broad spectrum of GitHub websites. It helps in creating the foundation of the basic style elements such as spacing, components, typography, color, etc.In this article, we'll s
    3 min read
    CSS margin-left Property
    The margin-left property in CSS is used to set the width of the margin on the left of the desired element. Negative values of this property are allowed.A positive value is used when it is desired that the margin is farther away from its neighbors.A negative value is used when it is desired that the
    3 min read
    Primer CSS Grid Centering a Column
    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 Margin Naming Convention
    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. It is highly reusable and flexible. It is created with GitHub’s design system. Margins are required to set each tag position. Prime
    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