AI Skill Report Card
Enforcing CSS Style Conventions
Quick Start15 / 15
Given any CSS/Sass/Less snippet, apply these transformations in order:
CSS/* BEFORE */ .selector{ margin-top : 10px; padding-left:15px; color: #FEFEFE; opacity: .5; background-color: rgba(0,0,0,0.5) } #special{padding:15px} /* AFTER */ .selector { margin-top: 10px; padding-left: 15px; color: #fefefe; opacity: 0.5; background-color: rgba(0, 0, 0, 0.5); } .normal.special { padding: 15px; }
Key fixes applied: trailing semicolons, 2-space indent, space before {, no space before : / one space after, lowercase+shortened hex, leading zero kept, comma-separated values spaced, no id selector.
Recommendation▾
Add an example showing a stylelint config snippet to operationalize the 'wire up stylelint' best practice
Workflow14 / 15
Progress checklist when reviewing/writing a stylesheet:
- Formatting: semicolons, 2-space indent, brace spacing, colon spacing, combinator spacing, comma spacing, comment spacing
- Structure: one selector per line (multi-selector lists), one declaration per line, closing
}on its own line, line length ≤100 chars - Selectors: no
#idselectors, quoted attribute selector values, selector nesting/specificity kept low, chains ≤3 elements - Values: shortest lowercase hex,
0without units, leading zero kept for decimals, no!important - Property order: positioning → box model → typography → appearance → other
- Shorthand: use shorthand (
margin,font,background, etc.) only when setting all/most sub-values; otherwise use longhand - No
@importin CSS files (use<link>instead) - Preprocessor-specific (Sass/Less, if applicable): operator spacing, mixin call formatting,
@import→variables→styles ordering, mixin-call-before-nested-selector ordering, nesting depth ≤3, prefer@mixin/@includeover@extend
Recommendation▾
Include a Less-specific example (currently only Sass is shown) to fully justify the Less mention in the description
Formatting Rules (CSS)
- Semicolons: every declaration ends with
;, including the last one. - Indentation: 2 spaces, never tabs or 4 spaces.
- Brace spacing: one space before
{; selector and{on same line;}alone on its own line. - Colon spacing: no space before
:, one space after (margin-top: 10px;). - Combinators: one space around
>,+,~,||. - Comma-separated values: one space after
,(e.g.,rgba(0, 0, 0, 0.5), multi-valuebox-shadow). - Comments: one space inside
/* comment */; blank line above a comment unless it's the first line in a block or follows another comment. - One declaration per line, even if the block has only one declaration.
- Line length: max 100 chars, except for
url()values or values that cannot be split (no spaces/commas). - Multiple selectors: each selector on its own line, separated by
,.
Selector Rules
- Never use ID selectors (
#foo). Convert to class-based specificity, e.g.#special→.normal.special. - Quote attribute selector values:
[type="text"], not[type=text]. - Performance/maintainability: prefer classes over element/tag selectors; avoid attribute selectors like
[class^="..."]on frequently-rendered components; keep each selector chain to ≤3 combined parts. Efficiency order (best→worst): ID > class > element > adjacent sibling > child > descendant > universal > attribute > pseudo-class/element (still avoid ID despite its efficiency, per the no-ID rule).
Value & Property Rules
- Hex colors: shortest form, lowercase (
#fffnot#FFFFFF). - Zero lengths: omit units (
margin-top: 0;not0px). - Decimals: keep leading zero (
0.5, not.5) — this is the recommended default, prioritizing readability/consistency over the one saved character. - No
!important— resolve specificity conflicts structurally instead. - Shorthand properties (
margin,padding,font,background,border,border-radius): only use when setting all/most sides or sub-values. For a single side, use longhand:margin-bottom: 10px;notmargin: 0 0 10px;.
Property declaration order
Group and order declarations as:
- Positioning (
position,top/right/bottom/left,z-index) - Box model (
display,float,width,height,margin,padding,border) - Typography (
font,color,line-height,text-align) - Appearance (
background,box-shadow, etc.) - Other (
opacity,transition,cursor, etc.)
CSS.declaration-order { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; display: block; float: right; width: 100px; height: 100px; border: 1px solid #e5e5e5; font: normal 13px "Helvetica Neue", sans-serif; line-height: 1.5; color: #333; text-align: center; background-color: #f5f5f5; opacity: 1; }
Sass / Less Specific Rules
- Operators: space around arithmetic operators —
$default-width / 2, not$default-width/2. - Mixin calls: no space between name and
(; no space before,, one space after —.size(30px, 20px);,.clearfix();(not.clearfix ()). - File organization order:
@importstatements → global variable declarations → style rules. - Declaration order inside a rule: standard properties (following the CSS order above) → mixin includes (
@include, Less mixin calls) → nested child selectors last, preceded by a blank line.
SCSS.btn { background: #ccc; font-weight: bold; @include transition(background 0.5s ease); .icon { margin-right: 10px; } }
- Nesting depth: max 3 levels. Deeper nesting couples CSS to HTML structure and inflates specificity.
- Comments:
//is fine for source-only notes (stripped on compile); use/* */only when the comment must survive in compiled CSS. - Code reuse: prefer
@mixin/@includeover@extend.@extendis fragile with nested selectors and load-order dependent; rely on gzip to handle any resulting duplication.
Other
- Never use
@importin CSS (adds a network round-trip in the critical rendering path). Use<link rel="stylesheet">in HTML instead. - Consider whether a preprocessor is even needed for new projects — PostCSS is the recommended alternative, offering plugin extensibility without the maintenance overhead of Sass/Less across teams.
Examples17 / 20
Example 1: Input:
CSS#header{ margin:0 0 10px; background-color:rgba(0,0,0,0.5); opacity:.5 }
Output:
CSS.header { margin-bottom: 10px; background-color: rgba(0, 0, 0, 0.5); opacity: 0.5; }
Example 2: Input:
SCSS.container{ .header{ .user-name{ .avatar{ color: red; } } } }
Output (flag nesting depth violation and flatten):
SCSS.container .header .user-name { color: inherit; } .avatar { color: red; }
Recommendation▾
Show a 'bad outcome' example where an incorrect fix is applied (e.g., misapplied shorthand) to reinforce pitfalls with contrast
Best Practices
- Wire up
stylelint(e.g.,stylelint-config-ali) so these rules are enforced automatically rather than manually checked every review. - When in doubt about shorthand vs. longhand, ask "am I setting all sides/values intentionally?" — if no, use longhand.
- Keep selectors resilient to markup changes; avoid over-nesting and ID-based hooks.
Common Pitfalls
- Don't drop the leading zero on decimals (
.5should be0.5). - Don't use shorthand just to set one value — it silently resets the others.
- Don't use
!importantas a quick fix — it compounds into worse specificity wars. - Don't nest Sass/Less selectors more than 3 levels deep "just because you can."
- Don't use
@importin plain CSS for production stylesheets. - Don't mix tabs and spaces, or use 4-space indentation.