Show navigation

Development teams often have coding standards in order to increase code quality, and make collaboration faster and easier. Even if you're coding solo, knowing the principles of consistent, readable code will help you write more maintainable code, faster!





Further Reading:

I love good documentation, so I wanted to call out two free, open-source tools that make documentation for larger projects simple and manageable.



Other popular CSS Methodologies:
Oscar icon
Oscar the Grouch
Oscar
You know… I think… I still love trash.
Elmo icon
Elmo & Oscar
Oscar and Elmo
Trash is the best

This:

.card {
  width: 20em;
  border-radius: calc(20em / 20);
  box-shadow: 0 0 0.5em #777777;
  border: 5px solid #eeeeee;
}
.card--collab {
  border-color: #eb0237;
  box-shadow: 0 0 0.5em #eb0237;
}
.card__header {
  display: flex;
  align-items: center;
  padding: 0.5em 1em;
}
.card__icon {
  background: green;
  border-radius: 50%;
  width: 3em;
  margin: 0.25em;
}
.card__title {
  font-size: 1.125em;
  font-weight: 900;
  margin: 0.5em;
  color: #555555;
}
.card__image {
  display: block;
  width: 100%;
  height: auto;
}
.card__caption {
  color: #555555;
  padding: 1em;
}
.card__cta {
  background: #eeeeee;
  padding: 1em;
  display: flex;
}
.card--collab .card__cta {
  background: #88a070;
}
.card__button {
  display: block;
  color: #555555;
  text-decoration: none;
  margin-right: 1em;
  padding: 0.5em 0.75em;
  background: #6667fe;
  color: #ffffff;
  box-shadow: 0 1px 2px #777777;
  font-size: 0.75em;
  border-radius: 0.125em;
}
.card__button:last-child {
  margin-right: 0;
}
.card__button:hover {
  box-shadow: 0 0 6px #777777;
  color: #ffffff;
}
.card__button--disabled {
  background: #777777;
  box-shadow: none;
  color: #eeeeee;
}
.card__button--disabled:hover {
  box-shadow: none;
  pointer-events: none;
}

…becomes this:

$colour-elmo: #eb0237;
$colour-oscar: #88a070;
$card-width: 20em;
$colour-gray-light: #eeeeee;
$colour-gray-dark: #777777;
$colour-text-default: #555555;
$box-shadow-default: 0 0 0.5em;
$border-radius-default: 1em;
 
.card {
  width: $card-width;
  border-radius: calc(#{$card-width} / 20);
  box-shadow: $box-shadow-default $colour-gray-dark;
  border: 5px solid $colour-gray-light;
 
  &--collab {
    border-color: $colour-elmo;
    box-shadow: $box-shadow-default $colour-elmo;
  }
 
  &__header {
    display: flex;
    align-items: center;
    padding: 0.5em 1em;
  }
 
  &__icon {
    background: green;
    border-radius: 50%;
    width: 3em;
    margin: 0.25em;
  }
 
  &__title {
    font-size: 1.125em;
    font-weight: 900;
    margin: 0.5em;
    color: $colour-text-default;
  }
 
  &__image {
    display: block;
    width: 100%;
    height: auto;
  }
 
  &__caption {
    color: $colour-text-default;
    padding: 1em;
  }
 
  &__cta {
    background: $colour-gray-light;
    padding: 1em;
    display: flex;
 
    .card--collab & {
      background: $colour-oscar;
    }
  }
 
  &__button {
    display: block;
    color: $colour-text-default;
    text-decoration: none;
    margin-right: 1em;
    padding: 0.5em 0.75em;
    background: #6667fe;
    color: #ffffff;
    box-shadow: 0 1px 2px $colour-gray-dark;
    font-size: 0.75em;
    border-radius: 0.125em;
 
    &:last-child {
      margin-right: 0;
    }
 
    &:hover {
      box-shadow: 0 0 6px $colour-gray-dark;
      color: #ffffff;
    }
 
    &--disabled {
      background: $colour-gray-dark;
      box-shadow: none;
      color: $colour-gray-light;
 
      &:hover {
        box-shadow: none;
        pointer-events: none;
      }
    }
  }
}

Table of ContentsWhy Do Teams Have Coding Standards?Elements of Coding StandardsDesign PatternsThe Constructor PatternCSS MethodologiesBEM