Css Order

To make sure everyone uses the same order in CSS, we've created a logical order which everyone agreed with.

All properties are separated by type and grouped by related properties.

There is also a stylelint plugin to enforce this order and give errors when the erros arent set. Read more about this.

special

  1. composes
  2. content
  3. all
  4. unset
  5. system
  6. symbols
  7. suffix
  8. pad
  9. additive-symbols
  10. negative

position

  1. position
  2. top
  3. right
  4. bottom
  5. left
  6. z-index

boxmodel

  1. display
  2. flex
  3. flex-grow
  4. flex-shrink
  5. flex-basis
  6. flex-flow
  7. flex-direction
  8. flex-wrap
  9. justify-content
  10. align-content
  11. align-items
  12. align-self
  13. place-items
  14. place-content
  15. order
  16. float
  17. clear
  18. box-sizing
  19. width
  20. min-width
  21. max-width
  22. height
  23. min-height
  24. max-height
  25. inline-size
  26. min-inline-size
  27. max-inline-size
  28. block-size
  29. min-block-size
  30. max-block-size
  31. grid
  32. grid-area
  33. grid-auto-columns
  34. grid-auto-flow
  35. grid-auto-rows
  36. grid-column
  37. grid-column-end
  38. grid-column-gap
  39. grid-column-start
  40. grid-gap
  41. grid-row
  42. grid-row-end
  43. grid-row-gap
  44. row-gap
  45. grid-row-start
  46. grid-template
  47. grid-template-areas
  48. grid-template-columns
  49. grid-template-rows
  50. gap
  51. box-shadow
  52. box-decoration-break
  53. box-sizing
  54. break-before
  55. break-after
  56. break-inside

spacing

  1. margin
  2. margin-top
  3. margin-right
  4. margin-bottom
  5. margin-left
  6. margin-block
  7. margin-block-start
  8. margin-block-end
  9. padding
  10. padding-top
  11. padding-right
  12. padding-bottom
  13. padding-left
  14. padding-block
  15. padding-block-end
  16. padding-block-start
  17. padding-inline
  18. padding-inline-end
  19. padding-inline-start

contentlayout

  1. columns
  2. column-count
  3. column-fill
  4. column-gap
  5. column-rule
  6. column-rule-color
  7. column-rule-style
  8. column-rule-width
  9. column-span
  10. column-width
  11. page-break-after
  12. page-break-before
  13. page-break-inside
  14. src
  15. orphans
  16. windows

border

  1. border
  2. border-width
  3. border-style
  4. border-color
  5. border-top
  6. border-top-width
  7. border-top-style
  8. border-top-color
  9. border-right
  10. border-right-width
  11. border-right-style
  12. border-right-color
  13. border-bottom
  14. border-bottom-width
  15. border-bottom-style
  16. border-bottom-color
  17. border-left
  18. border-left-width
  19. border-left-style
  20. border-left-color
  21. border-top-left-radius
  22. border-top-right-radius
  23. border-bottom-right-radius
  24. border-bottom-left-radius
  25. border-block
  26. border-block-color
  27. border-block-end
  28. border-block-end-color
  29. border-block-end-style
  30. border-block-end-width
  31. border-block-start
  32. border-block-start-color
  33. border-block-start-style
  34. border-block-start-width
  35. border-block-style
  36. border-block-width
  37. border-end-end-radius
  38. border-end-start-radius
  39. border-start-end-radius
  40. border-start-start-radius
  41. border-radius
  42. border-image
  43. border-image-source
  44. border-image-slice
  45. border-image-width
  46. border-image-outset
  47. border-image-repeat
  48. border-collapse
  49. border-spacing
  50. border-block
  51. border-inline
  52. border-inline-color
  53. border-inline-end
  54. border-inline-end-color
  55. border-inline-end-style
  56. border-inline-end-width
  57. border-inline-start
  58. border-inline-start-color
  59. border-inline-start-style
  60. border-inline-start-width
  61. border-inline-style
  62. border-inline-width
  63. outline
  64. outline-width
  65. outline-style
  66. outline-color
  67. outline-offset

background

  1. background
  2. background-color
  3. background-image
  4. background-repeat
  5. background-position
  6. background-position-x
  7. background-position-y
  8. background-size
  9. background-clip
  10. background-origin
  11. background-attachment
  12. background-blend-mode
  13. isolation
  14. shape-image-threshold
  15. shape-margin
  16. shape-outside

visual

  1. list-style
  2. list-style-position
  3. list-style-type
  4. list-style-image
  5. table-layout
  6. empty-cells
  7. caption-side

typography

  1. color
  2. font
  3. font-weight
  4. font-size
  5. font-family
  6. font-style
  7. font-feature-settings
  8. font-variant
  9. font-variant-alternates
  10. font-variant-caps
  11. font-variant-ease-asian
  12. font-variant-ligatures
  13. font-variant-numeric
  14. font-variant-position
  15. font-variant-settings
  16. font-size-adjust
  17. font-stretch
  18. font-effect
  19. font-emphasize
  20. font-emphasize-position
  21. font-emphasize-style
  22. font-smooth
  23. font-kerning
  24. font-language-override
  25. font-optical-sizing
  26. line-break
  27. line-height
  28. letter-spacing
  29. white-space
  30. direction
  31. text-align
  32. text-align-last
  33. text-transform
  34. text-decoration
  35. text-decoration-color
  36. text-decoration-line
  37. text-decoration-style
  38. text-emphasis
  39. text-emphasis-color
  40. text-emphasis-style
  41. text-emphasis-position
  42. text-indent
  43. text-justify
  44. text-outline
  45. text-wrap
  46. text-overflow
  47. text-overflow-ellipsis
  48. text-overflow-mode
  49. text-orientation
  50. text-shadow
  51. text-combine-upright
  52. vertical-align
  53. word-wrap
  54. word-break
  55. word-spacing
  56. tab-size
  57. hyphens
  58. hanging-punctuation
  59. unicode-bidi
  60. unicode-range
  61. writing-mode

transform

  1. backface-visibility
  2. perspective
  3. perspective-origin
  4. translate
  5. rotate
  6. scale
  7. transform
  8. transform-box
  9. transform-origin
  10. transform-style

visibility

  1. overflow
  2. overflow-x
  3. overflow-y
  4. overflow-wrap
  5. visibility
  6. filter
  7. backdrop-filter
  8. appearance
  9. clip
  10. clip-path
  11. mask
  12. mask-clip
  13. mask-composite
  14. mask-image
  15. mask-mode
  16. mask-origin
  17. mask-position
  18. mask-repeat
  19. mask-size
  20. mask-type
  21. mix-blend-mode
  22. opacity

animation

  1. transition
  2. transition-delay
  3. transition-timing-function
  4. transition-duration
  5. transition-property
  6. animation
  7. animation-name
  8. animation-duration
  9. animation-play-state
  10. animation-timing-function
  11. animation-delay
  12. animation-iteration-count
  13. animation-direction
  14. animation-fill-mode
  15. will-change

media

  1. object-fit
  2. object-position
  3. fill
  4. fill-rule
  5. clip-rule
  6. stroke
  7. image-orientation
  8. image-rendering
  9. speak-as

scroll

  1. scroll-behavior
  2. scroll-margin
  3. scroll-margin-block
  4. scroll-margin-block-end
  5. scroll-margin-block-start
  6. scroll-margin-bottom
  7. scroll-margin-inline
  8. scroll-margin-inline-end
  9. scroll-margin-inline-start
  10. scroll-margin-left
  11. scroll-margin-right
  12. scroll-margin-top
  13. scroll-padding
  14. scroll-padding-block
  15. scroll-padding-block-end
  16. scroll-padding-block-start
  17. scroll-padding-bottom
  18. scroll-padding-inline
  19. scroll-padding-inline-end
  20. scroll-padding-inline-start
  21. scroll-padding-left
  22. scroll-padding-right
  23. scroll-padding-top
  24. scroll-snap-align
  25. scroll-snap-stop
  26. scroll-snap-type
  27. scrollbar-color
  28. scrollbar-width

misc

  1. cursor
  2. caret-color
  3. counter-reset
  4. counter-increment
  5. resize
  6. user-select
  7. nav-index
  8. nav-up
  9. nav-right
  10. nav-down
  11. nav-left
  12. pointer-events
  13. quotes
  14. touch-action
  15. zoom
  16. min-zoom
  17. max-zoom

Stylelint

To use the order and get checked on it. You can add stylelint to your project. This enforces the order.

npm install stylelint stylelint-order stylelint-logical-order

Add the settings to your package.json

{
    "stylelint": {
        "rules": {
            "at-rule-no-unknown": [
                true,
                {
                    "ignoreAtRules": [
                        "if",
                        "for",
                        "else",
                        "each",
                        "mixin",
                        "extend",
                        "include",
                        "content",
                        "at-root",
                        "function"
                    ]
                }
            ],
            "order/order": [
                "custom-properties",
                "dollar-variables",
                "declarations",
                "rules"
            ]
        },
        "extends": ["stylelint-logical-order"]
    }
}

OR create a .stylelintrc.json file

{
    "plugins": ["stylelint-order"],
    "rules": {
        "at-rule-no-unknown": [
            true,
            {
                "ignoreAtRules": [
                    "if",
                    "for",
                    "else",
                    "each",
                    "mixin",
                    "extend",
                    "include",
                    "content",
                    "at-root",
                    "function"
                ]
            }
        ],
        "order/order": [
            "custom-properties",
            "dollar-variables",
            "declarations",
            "rules"
        ]
    },
    "extends": ["stylelint-logical-order"]
}

And add stylelint to your scripts:

{
    "scripts": {
        "stylelint": "stylelint 'src/scss/**/*.scss'",
        "stylelint:fix": "stylelint 'src/scss/**/*.scss' --fix"
    }
}

Or when you use it with Vue files;

{
    "scripts": {
        "stylelint": "stylelint '**/*.vue' '**/*.scss'",
        "stylelint:fix": "stylelint '**/*.vue' '**/*.scss' --fix"
    }
}