Comments
Prefer line comments (//
) to block comments.
Prefer comments on their own line. Avoid end-of-line comments.
Write detailed comments for code that isn't self-documenting:
Uses of z-index
Compatibility or browser-specific hacks
Use tabs for indentation
Use dashes over camelCasing in class names.
Prefer to not use ID selectors
When using multiple selectors in a rule declaration, give each selector its own line.
Put a space before the opening brace {
in rule declarations
In properties, put a space after, but not before, the :
character.
Put closing braces }
of rule declarations on a new line
Put blank lines between rule declarations, but not in nesting selectors.
Put nesting after all properties.
Try to not use !important
.
Lowercase, always :)
blockquote {
.clearfix ;
margin: .5em 0;
& : first-child {
margin-top : 0 ;
}
& : last-child {
margin-bottom : 0 ;
}
padding-left : 10px ;
position : relative;
& : before {
content : ' ' ;
width : 4px ;
position : absolute;
border-radius : 2px ;
left : 0 ;
top : -1px ;
bottom : -1px ;
}
}
.login-terms {
font-size : smaller;
width : 520px ;
padding : 10px ;
max-width : 100% ;
margin : auto;
a {
font-weight : bold !important ;
text-decoration : underline;
}
}
blockquote {
.clearfix ;
margin: .5em 0;
padding- left: 10px;
position: relative;
& : first-child {
margin-top : 0 ;
}
& : last-child {
margin-bottom : 0 ;
}
& ::before {
content : ' ' ;
width : 4px ;
position : absolute;
border-radius : 2px ;
left : 0 ;
top : -1px ;
bottom : -1px ;
}
}
.login-terms {
font-size : smaller;
width : 520px ;
padding : 10px ;
max-width : 100% ;
margin : auto;
a {
font-weight : bold;
text-decoration : underline;
}
}
Create an empty line before selectors
.class {
border : 0 ;
}
.second-class : {
text-align : right;
}
.class {
border : 0 ;
}
.second-class : {
text-align : right;
}
Use a single space after selectors
Add an empty line before nested selectors
.class {
border : 0 ;
& .another-class {
color : # ffffff ;
}
}
.class {
border : 0 ;
& .another-class {
color : # ffffff ;
}
}
Use an empty line before non-nested selectors
.class {
border : 0 ;
& .another-class {
color : # ffffff ;
}
}
.logo {
display : block;
}
.class {
border : 0 ;
& .another-class {
color : # ffffff ;
}
}
.logo {
display : block;
}
Don’t add whitespaces inside of the brackets within attribute selectors
.input [ type = "text" ] {
border : 0 ;
}
.input [type = "text" ] {
border : 0 ;
}
Don’t add a whitespace between operators within attribute selectors
.input [type = "text" ] {
border : 0 ;
}
.input [type = "text" ] {
border : 0 ;
}
Always use a single space between the combinators of selectors
.class > .button {
font-size : 1rem ;
}
.class > .button {
font-size : 1rem ;
}
Add a newline after the commas of selector lists
.class , .another , .another-class {
padding : 1.5rem ;
}
.class ,
.another ,
.another-class {
padding : 1.5rem ;
}
Don’t add a whitespace inside of the parentheses within pseudo-class selectors
.class : not ( .another ) {
margin : 5px ;
}
.class : not (.another ) {
margin : 5px ;
}
Double colon for applicable pseudo-elements
.class : before {
border-width : 2px ;
}
.class : first-child {
color : # 000000 ;
}
.class ::before {
border-width : 2px ;
}
.class : first-child {
color : # 000000 ;
}
Don’t add empty line in first/last property or in between properties
.room-list {
border : 0 ;
padding-left : 0 ;
color : # ddfc32 ;
}
.room-list {
border : 0 ;
padding-left : 0 ;
color : # ddfc32 ;
}
Don't add properties in single-line. Use one property per line
.sumbit {color : # ffffff ; background-color : # 000000 ;}
.sumbit {
color : # ffffff ;
background-color : # 000000 ;
}
Longhand properties must be combined into one shorthand property
.class {
padding-left : 12px ;
padding-top : 5px ;
padding-bottom : 8px ;
}
.class {
padding : 5px auto 8px 12px ;
}
Don’t use shorthand properties that override related longhand properties
.class {
border-color : # ffffff ;
border : 1px solid # 000000 ;
}
Always add a trailing semicolon in the end of a declaration
.another-class {
color : # ffffff ;
padding : 2px
}
.another-class {
color : # ffffff ;
padding : 2px ;
}
Add a newline after the colon of declarations
.another-class {
box-shadow : 0 0 0 1px # 5b9dd9, 0 0 2px 1px rgba (30 , 140 , 190 , 0.8 );
}
.another-class {
box-shadow :
0 0 0 1px # 5b9dd9,
0 0 2px 1px rgba (30 , 140 , 190 , 0.8 );
}
Don’t duplicate properties within declaration blocks
.another-class {
display : block;
margin-top : 2rem ;
display : inline-block;
}
.another-class {
margin-top : 2rem ;
display : inline-block;
}
Don’t duplicate selectors along the file
.some-class {
display : block;
}
.another-class {
position : absolute;
}
.some-class {
margin-top : 2rem ;
display : inline-block;
}
.some-class {
display : block;
margin-top : 2rem ;
display : inline-block;
}
Add a whitespace before bang (!) declaration
.class {
margin-left : 12px !important ;
}
.class {
margin-left : 12px !important ;
}
Use spaces around calc operators
.class {
width : calc (~ "200px-1rem" );
}
.class {
width : calc (~ "200px - 1rem" );
}
Remove units for zero lengths
.button {
padding : 10px 0px 0px 2px ;
}
.button {
padding : 10px 0 0 2px ;
}
Use a leading zero for fractional numbers css than 1
.message-form {
margin-right : .5rem ;
}
.message-form {
margin-right : 0.5rem ;
}
Don’t add trailing zeros in numbers
.flex-tab {
padding-bottom : 1.500rem ;
}
.flex-tab {
padding-bottom : 1.5rem ;
}
Don’t add newlines in strings
.nav-link ::before {
content : "sample
text" ;
}
.nav-link ::before {
content : "sample text" ;
}
.another-class {
background-color : # FFF ;
}
.another-class {
background-color : # ffffff ;
}