Copying over from Manual talk:Coding conventions/CSS/Archive 1#CSS/Less property order proposal as it's still an unresolved topic:
It would be useful to have a coding convention for the order of the declarations in a declaration block. A consisted order improves the gzip compression and makes it easier to find or insert declarations.
The intuitive order is the alphabetical order. A alphabetical order has the disadvantage that it may disrupt declarations that belongs together, especially when there are blocks of comments.
An other possibility would be the order in the CSS specification. But CSS 2 is the last complete specification.
Is it desired to have an order for declarations? --Fomafix (talk) 11:46, 21 December 2015 (UTC)
- https://css-tricks.com/poll-results-how-do-you-order-your-css-properties/ -— Isarra ༆ 20:22, 5 January 2016 (UTC)
- I'm in favor of adding a CSS guideline for property order, especially when looking at the growing number of possible CSS properties. Here's one example where missing property order has caused unnecessary property duplication (
- This is an outcome we definitely don't want to see.
- The outcomes of the poll results at css-tricks above (45% in favor of grouped by type) are interesting and also the summaries by the author:
I think this is a bigger deal in teams. There has to be a standard otherwise the CSS project-wide looks sloppy. I know that inconsistent styles would wear on my conscience and I'd spend time fixing trivial formatting stuff rather than doing actual work.
Cognitive load factors into this. If you can always count on certain properties being in the same place, you can understand the CSS a bit faster (less scanning). Again, a bigger deal when on a team and you are looking at code you are slightly less familiar with because you didn't write it.
- I couldn't agree more with those thoughts (emphasizing done by myself).
- Therefore I'd like to come up with a new proposal for a guideline on CSS property order:
CSS/LESS property order proposal
/* ::: Generated Content ::: */
/* ::: Background/List Style, Color, Filter & Opacity ::: */
background-image: url( selector.svg ); //or:
.oo-ui-background-image-svg( /icons/circle-constructive' );
background-position: center center;
background-size: 0 0;
filter: blur( 1px );
/* ::: Display (& Flex Box properties) ::: */
clip: rect( 0, 0, 0, 0 );
/* ::: Positioning ::: */
// Float Model
// Positioning Model
/* ::: Box Model (from outside to inside) ::: */
margin: 4em 2em;
/* ::: Typography incl. Print properties ::: */
text-shadow: 0 0 1px #fff;
/* ::: Animations & Transitions ::: */
animation: orbit 3s infinite linear;
transition: opacity @transition-global;
/* ::: Others ::: */
/* ::: Stacking Context ::: */
- Generated content comes first, as content gets priority,
- Backgrounds (in alphabetical order of sub properties), colors, list-styles as similar to background-images, filter and opacity properties are next, as they are together with box sizing the most used and most altered properties and therefore should be on top of the list
- Display is next, as it is also a often used and strong property
- Box Model in order of outside in, so outline > margin > padding > border and min- & max- values before the fixed property value.
- Typographic values in alphabetical sub order
- Animations and transitions are last, as they are extending the scope of the styles applied to the element
--VEckl (WMF) (talk) 03:48, 10 January 2016 (UTC)