This gist briefly goes over semantics, and then establishes CSS guidelines.
Here is deeper dive into semantics.
Some general rules to follow:
- Use
section
,article
,figure
, etc... instead ofdiv
andspan
- Try to avoid using
div
tags where possible
- Do not use
float
- Avoid using
px
as units (userem
orem
) - Do not use
margin
orpadding
to center stuff (unless you are doingmargin: auto
and you have given the element a width) - Do not use
z-index
orposition
properties unless you absolutely have to - Try to use
flex
orgrid
to position stuff, withgrid
being the preference - Order your CSS class names as they appear in the HTML (e.g., I should not see a class name at the top of the CSS file, and then it being used at the end of the HTML file)
- Media queries should be at the end of the file, but try as much as possible to avoid writing media queries (choosing proper units and using the grid system will greatly help you avoid writing media queries)
- Do not under any circumstance use the
!important
flag - Prefer hex codes over rgb, and definitely do not use color names
- Use
em
for margin/padding - Use
rem
for font-size and anywhere you would usually usepx
(unless it is very minor like1px
borders, then using pixels is fine)