A quick lookup for CSS properties grouped by topic. Each section covers syntax, common values, and usage notes — with code examples for the concepts that need them most.
Selector Targets Example elementAll elements of that type p { }.classElements with that class .card { }#idThe element with that id #hero { }A BB elements that are descendants of A nav a { }A > BB elements that are direct children of A ul > li { }A + BB immediately following A (adjacent sibling) h2 + p { }A ~ BAll B siblings after A h2 ~ p { }[attr]Elements that have the attribute [required] { }[attr="val"]Elements with an exact attribute value [type="email"] { }:hoverElement under the cursor a:hover { }:focusFocused element input:focus { }:activeElement being clicked button:active { }:visitedVisited links a:visited { }:first-childFirst child of its parent li:first-child { }:last-childLast child of its parent li:last-child { }:nth-child(n)The nth child li:nth-child(2) { }:not(selector)Elements that do not match :not(.active) { }::beforeGenerated content before the element p::before { }::afterGenerated content after the element p::after { }::placeholderInput placeholder text input::placeholder { }A, BBoth A and B (group) h1, h2, h3 { }
Property Common values Notes box-sizingcontent-box, border-boxAlways set border-box globally — makes width and height include padding and border widthpx, %, rem, auto, min-content, max-contentDefault is auto min-widthany length Prevents shrinking below this value max-widthany length Common pattern: max-width: 1200px; margin: 0 auto for centered containers heightpx, %, rem, auto% only works if the parent has an explicit heightmin-heightany length — max-heightany length Often paired with overflow: auto marginpx, %, rem, autoShorthand: top right bottom left. auto centers block elements horizontally paddingpx, %, remShorthand: top right bottom left. % is relative to parent width on all sides borderwidth style colorShorthand: border: 1px solid #ccc border-widthpx, thin, medium, thick— border-stylesolid, dashed, dotted, double, noneRequired for a border to appear border-colorany color value — border-radiuspx, %, rem50% on equal width/height creates a circle. Individual corners: border-top-left-radius etc.outlinewidth style colorLike border but outside the box — does not affect layout. Never remove without a replacement for focus styles displayblock, inline, inline-block, flex, grid, nonenone removes the element from flow and hides it completelyvisibilityvisible, hiddenhidden hides but the element still occupies spaceoverflowvisible, hidden, auto, scrollauto adds a scrollbar only when content overflowsoverflow-x / overflow-ysame values Control horizontal and vertical overflow independently
/* shorthand margin/padding — 4, 2, or 1 value(s) */
margin: 16px 24px 16px 24px; /* top right bottom left */
margin: 16px 24px; /* top/bottom left/right */
margin: 16px; /* all sides */
/* global box-sizing reset */
Property Values Notes positionstatic, relative, absolute, fixed, stickystatic is default — elements follow normal flowtop / right / bottom / leftpx, %, rem, autoOnly apply when position is not static z-indexinteger Higher numbers stack on top. Only works on positioned elements (position not static)
/* relative — stays in flow, offsets from its own position */
.badge { position : relative ; top : 4 px ; }
/* absolute — removed from flow, positioned relative to nearest positioned ancestor */
.tooltip { position : absolute ; top : 8 px ; right : 8 px ; }
/* fixed — stays in place relative to the viewport while scrolling */
.nav { position : fixed ; top : 0 ; left : 0 ; width : 100 % ; z-index : 100 ; }
/* sticky — normal flow until scroll threshold, then sticks */
.sticky-header { position : sticky ; top : 0 ; }
Property Common values Notes colornamed, hex, rgb(), hsl() Sets text color. Also the value of the currentColor keyword background-colornamed, hex, rgb(), hsl(), transparent — background-imageurl(), linear-gradient(), radial-gradient()— background-sizecover, contain, px, %cover fills without distorting (may crop). contain shows full imagebackground-positioncenter, top right, 50% 50%, px— background-repeatrepeat, no-repeat, repeat-x, repeat-y— background-attachmentscroll, fixed, localfixed creates a parallax-like effectbackgroundshorthand url(img.jpg) center / cover no-repeatopacity0 to 1Affects the element and all its children. Use rgba() / hsl() alpha to target color only
color: #2c4a1e ; /* hex */
color: rgb(44, 74, 30 ); /* rgb */
color: rgba(44, 74, 30, 0 .5 ); /* rgba — with transparency */
color: hsl(107, 29%, 20% ); /* hsl */
color: hsl(107 29% 20% / 50%); /* modern hsl with alpha */
/* gradient background */
background-image : linear-gradient(to bottom, #2c4a1e , #a8c97f );
background: url(hero .jpg ) center / cover no-repeat ;
Property Common values Notes font-familyfont name, serif, sans-serif, monospace Comma-separated stack — browser uses first available, falls back left to right font-sizepx, rem, em, %, vwrem is preferred — scales with user’s browser font size preferencefont-weightnormal (400), bold (700), 100–900Availability depends on the loaded font font-stylenormal, italic, oblique— fontshorthand style weight size/line-height familyline-heightunitless, px, em, % Unitless (e.g. 1.5) is preferred — scales proportionally with font-size letter-spacingpx, emPositive = wider. em scales with font size. Common for headings and uppercase labels word-spacingpx, em— text-alignleft, right, center, justify— text-decorationnone, underline, line-through, overlineShorthand includes text-decoration-color and text-decoration-style text-transformnone, uppercase, lowercase, capitalize— white-spacenormal, nowrap, pre, pre-wrapnowrap prevents line breakstext-overflowclip, ellipsisRequires overflow: hidden and white-space: nowrap
/* font shorthand: style weight size/line-height family */
font : italic 700 1 .5rem / 1 .6 "Playfair Display", serif;
/* truncate long text with ellipsis */
Property Common values Notes box-shadowx y blur spread colorComma-separate multiple shadows. Add inset for inner shadow text-shadowx y blur colorNo spread value. Multiple shadows comma-separated filterblur(), brightness(), contrast(), grayscale(), drop-shadow()Applies to the element and all its contents backdrop-filterblur(), brightness() etc.Applies to content behind the element — frosted-glass effect cursorpointer, default, not-allowed, grab, crosshair—
box-shadow : 0 2px 8px rgba(0, 0, 0, 0 .15 ); /* soft drop shadow */
box-shadow : 0 2px 4px rgba(0,0,0, .1 ), 0 8 px 24px rgba(0,0,0, .08 ); /* layered */
box-shadow : inset 0 2px 4px rgba(0,0,0, .2 ); /* inner shadow */
text-shadow : 0 1px 2px rgba(0, 0, 0, 0 .4 );
background : rgba ( 255 , 255 , 255 , 0.6 );
backdrop-filter : blur ( 8 px );
Apply container properties to the flex parent . Apply item properties to flex children .
Property Common values Notes displayflex, inline-flexinline-flex behaves like flex but shrinks to content widthflex-directionrow, column, row-reverse, column-reverseSets the main axis. Default: row flex-wrapnowrap, wrap, wrap-reverseDefault nowrap — items shrink rather than wrap to a new line justify-contentflex-start, flex-end, center, space-between, space-around, space-evenlyDistributes space along the main axis align-itemsstretch, flex-start, flex-end, center, baselineAligns items along the cross axis. Default: stretch align-contentsame as justify-content Only applies when there are multiple rows (flex-wrap: wrap) gappx, remSpace between items. gap: row-gap column-gap for separate values flex-flowdirection wrapShorthand for flex-direction + flex-wrap
Property Common values Notes flex1, 0 1 auto, grow shrink basisShorthand. flex: 1 = grow to fill available space flex-grow0, 1, numberHow much of the extra space this item gets. Default 0 flex-shrink0, 1, numberWhether the item shrinks below its flex-basis. Default 1 flex-basisauto, px, %, remIdeal size before growing/shrinking. Default auto align-selfsame as align-items Overrides align-items for this one item orderinteger Default 0. Lower numbers appear first regardless of source order
/* logo left, links right */
justify-content : space-between ;
flex : 1 1 280 px ; /* grow, shrink, never below 280px */
/* equal-width columns */
.columns { display : flex ; gap : 2 rem ; }
Apply container properties to the grid parent . Apply item properties to grid children .
Property Common values Notes displaygrid, inline-grid— grid-template-columnspx, fr, %, repeat(), minmax(), auto1fr = one fraction of available spacegrid-template-rowssame Explicit row sizes. Rows without this are auto-sized grid-template-areasquoted area names Names regions for named placement grid-auto-rowspx, rem, fr, minmax()Size for implicitly created rows grid-auto-flowrow, column, denseHow auto-placed items fill the grid gappx, remSpace between rows and columns. gap: row-gap column-gap
Property Common values Notes grid-column1 / 3, span 2, 1 / -1Start / end column line. -1 = the last line grid-row1 / 3, span 2Start / end row line grid-areanamed area, or row-start / col-start / row-end / col-end — justify-selfstart, end, center, stretchAligns item horizontally within its cell align-selfstart, end, center, stretchAligns item vertically within its cell place-selfalign justifyShorthand for align-self + justify-self
grid-template-columns : repeat ( 3 , 1 fr );
grid-template-columns : 240 px 1 fr ;
.sidebar { grid-area : sidebar; }
.content { grid-area : content ; }
/* responsive grid — no media queries needed */
grid-template-columns : repeat ( auto-fill , minmax ( 280 px , 1 fr ));
/* span multiple columns */
.featured { grid-column : 1 / -1 ; } /* full width */
Property Common values Notes transition-propertyall, property nameThe CSS property to animate. Prefer specific names over all transition-durationms, sRequired — defaults to 0 transition-timing-functionease, linear, ease-in, ease-out, ease-in-out, cubic-bezier()— transition-delayms, sWait before starting transitionshorthand property duration timing delay
.btn { transition : background-color 200 ms ease ; }
/* multiple properties */
.card { transition : transform 200 ms ease , box-shadow 200 ms ease ; }
.card { transition : transform 200 ms ease , box-shadow 200 ms ease ; }
transform : translateY ( -4 px );
box-shadow : 0 8 px 24 px rgba ( 0 , 0 , 0 , 0.15 );
For smooth 60fps animation, only transition transform and opacity — they run on the compositor and do not trigger layout recalculation. Avoid animating width, height, margin, or top/left.
Property Common values Notes animation-namekeyframe name Must match a @keyframes rule animation-durationms, sRequired — defaults to 0 animation-timing-functionsame as transition Can be set per-keyframe or per-animation animation-delayms, sStagger effect: different delays per element animation-iteration-countnumber, infinite — animation-directionnormal, reverse, alternate, alternate-reverse— animation-fill-modenone, forwards, backwards, bothforwards holds the final state after the animation endsanimation-play-staterunning, pausedPause/resume via JavaScript or :hover animationshorthand name duration timing delay count direction fill-mode
from { opacity : 0 ; transform : translateY ( 16 px ); }
to { opacity : 1 ; transform : translateY ( 0 ); }
.hero { animation : fade-in 600 ms ease forwards ; }
.card:nth-child ( 1 ) { animation-delay : 0 ms ; }
.card:nth-child ( 2 ) { animation-delay : 100 ms ; }
.card:nth-child ( 3 ) { animation-delay : 200 ms ; }
/* respect motion preferences — always include this */
@media ( prefers-reduced-motion: reduce ) {
animation-duration : 0.01 ms !important ;
transition-duration : 0.01 ms !important ;
Unit Type Notes pxAbsolute Fixed size — does not scale with user settings remRoot-relative Relative to the <html> font-size (1rem = 16px by default). Preferred for typography and spacing emElement-relative Relative to the element’s own font-size. Compounds with nesting %Parent-relative Relative to the parent’s corresponding value vwViewport 1% of viewport width vhViewport 1% of viewport height dvhDynamic viewport Accounts for mobile browser chrome appearing/disappearing frGrid fraction One fraction of remaining grid space. Grid-only chCharacter Width of the 0 glyph in the current font. Useful for setting readable line lengths min()Function min(100%, 600px) — whichever is smallermax()Function max(1rem, 16px) — whichever is largerclamp()Function clamp(min, preferred, max) — fluid values between a minimum and maximum
/* fluid typography with clamp */
h1 { font-size : clamp ( 1.75 rem , 4 vw , 3 rem ); }
p { font-size : clamp ( 1 rem , 2 vw , 1.125 rem ); }
/* readable line length */
.prose { max-width : 65 ch ; }
/* mobile-first: base styles apply to all screens */
/* @media rules layer on styles for progressively larger screens */
@media ( min-width : 600 px ) { }
@media ( min-width : 1024 px ) { }
@media ( min-width : 1280 px ) { }
@media ( prefers-color-scheme: dark ) { }
@media ( prefers-reduced-motion: reduce ) { }
/* multiple conditions */
@media ( min-width : 600 px ) and ( max-width : 1023 px ) { }
STO breakpoints from the course: 600px (2-column cards), 768px (horizontal header), 1024px (3-column tour grid).
Syntax Example Notes Define --color-primary: #2c4a1e;Convention: --kebab-case. Defined on :root for global scope Use color: var(--color-primary);Second argument is a fallback: var(--color-primary, black) Override Redefine on any selector Scoped: .dark { --color-primary: #fff; } affects that element and its children
--color-primary : # 2c4a1e ;
--font-heading : " Playfair Display " , serif ;
--font-body : " Source Sans 3 " , sans-serif ;
--shadow : 0 2 px 8 px rgba ( 0 , 0 , 0 , 0.12 );
background-color : var ( --color-primary );
font-family : var ( --font-body );
border-radius : var ( --radius );
box-shadow : var ( --shadow );