CSS Complete Cheatsheet & Notes
Selectors
*— Universal selectorelement— Type selector (e.g., div, p).classname— Class selector#id— ID selector[attr]— Attribute selector:hover,:focus— Pseudo-classes::before,::after— Pseudo-elementsdiv > p— Child selectordiv p— Descendant selectordiv + p— Adjacent sibling selector
Colors & Backgrounds
color— Text colorbackground-color— Background fillbackground-image— Add an imagebackground-repeat— repeat | no-repeat | repeat-xbackground-size— cover | contain | autoopacity— 0 → 1 transparencygradient— linear-gradient(), radial-gradient()
Fonts & Text
font-family— Arial, Verdana, etc.font-size— px, em, rem, %font-weight— normal | bold | 100–900line-height— space between linestext-align— left | center | right | justifytext-transform— uppercase | lowercasetext-decoration— none | underlineletter-spacing,word-spacing
Box Model
width/heightpadding— space inside bordermargin— space outside borderborder— width style colorbox-sizing— content-box | border-boxoverflow— hidden | scroll | autodisplay— block | inline | inline-block | flex
Flexbox
display: flex;flex-direction— row | columnjustify-content— center | space-between | space-aroundalign-items— center | flex-start | flex-endflex-wrap— wrap | nowrapgap— spacing between itemsalign-self— override individual alignment
CSS Grid
display: grid;grid-template-columns— repeat(3, 1fr)grid-template-rowsgap— grid spacingjustify-items,align-itemsgrid-column,grid-rowplace-items— shorthand for align + justify
Positioning
position— static | relative | absolute | fixed | stickytop,right,bottom,leftz-index— stack orderfloat— left | rightclear— none | left | right | both
Animation & Transition
transition— property duration timing-function@keyframes— define animationsanimation-name,animation-durationanimation-iteration-count— infinite | 1animation-delayanimation-timing-function— ease | linear
Responsive Design
@media (max-width: 600px)— for mobile<meta name="viewport" content="width=device-width, initial-scale=1">flexandgridfor layoutsrelative units— em, rem, %, vw, vhobject-fit,aspect-ratiofor images
CSS Variables
:root { --main-color: #333; }color: var(--main-color);- Custom reusable design tokens