Skip to content

Instantly share code, notes, and snippets.

@AdamMarsden
Last active July 30, 2024 15:28
Show Gist options
  • Save AdamMarsden/fd9ec5f21016328cb6fe to your computer and use it in GitHub Desktop.
Save AdamMarsden/fd9ec5f21016328cb6fe to your computer and use it in GitHub Desktop.
CSS Declaration order

CSS Declaration Order

Related property declarations should be grouped together following the order:

  • Box
  • Border
  • Background
  • Text
  • Other

Box includes any property that affects the display and position of the box such as display, float, position, left, top, height, width and so on. These are most important because they affect the flow of the rest of the document.

Border includes border, the oft-unused border-image, and border-radius.

Background includes any property that changes the background of an element such as background, background-color, background-size etc.

Text declarations include font-family, font-size, text-transform, letter-spacing and any other CSS properties that affect the display of the type.

Anything that doesn’t fall into any of the above categories gets added to the end.

.declaration-order {
    /* Box */
    display: block;
    height: 200px;
    width: 200px;
    float: left;
    position: relative;
    top: -1px;

    /* Border */
    border: 1px solid #333;
    border-radius: 10px;

    /* Background */
    background-color: #f5f5f5;

    /* Text */
    font-size: 12px;
    text-transform: uppercase;

    /* Other */
    animation: all 0.2s ease;
    opacity: 1;
}
@HNazmul-X
Copy link

👍🏼👍🏼👍🏼👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment