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 ofdivandspan - Try to avoid using
divtags where possible
- Do not use
float - Avoid using
pxas units (useremorem) - Do not use
marginorpaddingto center stuff (unless you are doingmargin: autoand you have given the element a width) - Do not use
z-indexorpositionproperties unless you absolutely have to - Try to use
flexorgridto position stuff, withgridbeing 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
!importantflag - Prefer hex codes over rgb, and definitely do not use color names
- Use
emfor margin/padding - Use
remfor font-size and anywhere you would usually usepx(unless it is very minor like1pxborders, then using pixels is fine)