This is the CSS convention I learned while doing web publishing at a previous company. I used to follow it from memory, but I figured writing it down once would help—both for explaining it to teammates and for sharing it with people who are just getting started.
These days more friends without a CS background are getting into development, so I hope this also helps people who are just starting on the web. This is very subjective, so please treat it as one practical approach rather than the definitive answer.
The table below lists each property and its description. When writing CSS, write the properties in the order shown from top to bottom.
| Property | Description |
| display | Defines how an element is rendered, so it belongs at the top of the declaration. e.g. block, inline-block, flex
|
| opacity, visibility | Controls the visibility of an element. e.g. opacity: 0; visibility: hidden; |
| overflow | Defines how content that overflows its element is handled. e.g. hidden, scroll, auto |
| position | Defines how an element is positioned on the page. e.g. relative, absolute, fixed
|
| float | Specifies that an element should be taken out of normal flow and placed along the left or right side of its container. e.g. right, left, unset |
| width, height | Defines the size of an element.
|
| margin | Defines the outer spacing of an element.
e.g. top → right → bottom → left |
| padding | Defines the inner spacing of an element.
e.g. top → right → bottom → left |
| border | Defines the border of an element.
|
| background | Defines the background of an element.
|
| font, text, line, color | Defines the typography of an element.
e.g. font-size: 14px; text-align: center; line-height: 14px; color: black;
|
| transform | Applies effects such as rotation, scaling, skewing, and translation. |
| transition | Defines the duration of the element's animation. |
That should be enough to follow the convention in practice.
In short:
Think of it as writing styles in order of importance to the element's structure, working from the outside in.
I might come back and revise this later.
Compared to writing CSS without any rules, a convention noticeably improves both writing speed and maintenance.
For example, when you need to change a CSS property on an element, you can tell at a glance where the property you want should live. And because styles are applied from the outside in, you can almost visualize the result just by reading the CSS. Anyway, it's felt smoother since I adopted this.
Even tedious publishing work gets easier with a convention like this.