Skip to content

CSS Style

Standards for consistent CSS style.

Follow Code Style Rules

All CSS must follow language-agnostic standards: 2-space indentation, 80-character line limit.

One Property Per Line

DON'T

css
div { margin: 0; padding: 0; border: none; }

DO

css
div {
  margin: 0;
  padding: 0;
  border: none;
}

Check for multiple properties on one line:

sh
node checks/one-property-per-line.js file.css

Order Properties by Logical Grouping

  1. Outer Layout: position, top, right, bottom, left, z-index, display
  2. Inner Layout: flex, grid, width, height, margin, padding, border, overflow
  3. Typography: font, font-size, line-height, text-align, color
  4. Visuals: background, box-shadow, opacity
  5. Motion: transform, transition, animation
  6. Interaction: cursor, pointer-events

DON'T order randomly

css
button {
  color: white;
  position: relative;
  background: blue;
  padding: 10px;
}

DO group logically

css
button {
  position: relative;
  padding: 10px;
  color: white;
  background: blue;
}

Use CSS Custom Properties

css
:root {
  --color-primary: #007bff;
  --spacing-base: 8px;
}

Use Lowercase Hex Colors

DON'T: #FF0000, #FFFFFF

DO: #ff0000, #ffffff

Check for uppercase hex colors:

sh
node checks/lowercase-hex.js file.css