Open In App

Primer CSS Property order

Improve
Improve
Like Article
Like
Save
Share
Report

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.

Primer CSS Property Order is an important rule every developer should maintain. There are a few properties that need to be applied on priority for any class.

Syntax: This is just an order to use CSS properties on any element same goes with the classes of Primer CSS.

.element {
  // 1. Positioning
  // 2. Box model (display, float, width, etc)
  // 3. Typography (font, line-height, text-*)
  // 4. Visuals (background, border, opacity)
  // 5. Misc (CSS3 properties)
}

The below example illustrates the Primer CSS Property Order:

Example 1: In this example, we will follow the Property order but, will not use Primer CSS classes here we will use actual CSS.

HTML




<!DOCTYPE html>
<html>
<head>
    <style>
        .fixed {
            position: fixed;
            background: #cc0000;
            padding: 15px;
        }
        span {
            background: green;
            border: 1px #ffffff solid;
            padding: 5px;
        }
        pre {
            padding-top: 50px;
            height: 1200px;
            width: 200px;
        }
    </style>
</head>
<body>
    <div class="fixed">A Computer Science Portal for Geeks
        <span>Geeksforgeeks</span>
    </div>
    <pre>
            I am here to create a scrollable section
    </pre>
</body>
</html>


Output:

Primer CSS Property Order

Primer CSS Property Order

Example 2: In this example, we will achieve the same output by following the Primer CSS Property order in Primer CSS classes

HTML




<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href=
"https://unpkg.com/@primer/css@^18.0.0/dist/primer.css" />
    <style>
        /* To make the section scrollable */
        pre {
            padding-top: 50px;
            height: 1200px;
            width: 200px;
        }
    </style>
</head>
<body>
    <div class="position-fixed 
                color-bg-danger-emphasis
                p-3">
        A Computer Science Portal for Geeks
        <span class="color-bg-success-emphasis 
                     border 
                     rounded-0 
                     p-2 p-1">
            Geeksforgeeks</span>
    </div>
    <pre>
        I am here to create a scrollable section
    </pre>
</body>
</html>


Output: 

Primer CSS Property Order

Primer CSS Property Order

Reference: https://primer.style/css/principles#property-order



Last Updated : 09 May, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads