Skip to content

CSS Properties

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.

SelectorTargetsExample
elementAll elements of that typep { }
.classElements with that class.card { }
#idThe element with that id#hero { }
A BB elements that are descendants of Anav a { }
A > BB elements that are direct children of Aul > li { }
A + BB immediately following A (adjacent sibling)h2 + p { }
A ~ BAll B siblings after Ah2 ~ p { }
[attr]Elements that have the attribute[required] { }
[attr="val"]Elements with an exact attribute value[type="email"] { }
:hoverElement under the cursora:hover { }
:focusFocused elementinput:focus { }
:activeElement being clickedbutton:active { }
:visitedVisited linksa:visited { }
:first-childFirst child of its parentli:first-child { }
:last-childLast child of its parentli:last-child { }
:nth-child(n)The nth childli:nth-child(2) { }
:not(selector)Elements that do not match:not(.active) { }
::beforeGenerated content before the elementp::before { }
::afterGenerated content after the elementp::after { }
::placeholderInput placeholder textinput::placeholder { }
A, BBoth A and B (group)h1, h2, h3 { }
PropertyCommon valuesNotes
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 lengthPrevents shrinking below this value
max-widthany lengthCommon pattern: max-width: 1200px; margin: 0 auto for centered containers
heightpx, %, rem, auto% only works if the parent has an explicit height
min-heightany length
max-heightany lengthOften 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 completely
visibilityvisible, hiddenhidden hides but the element still occupies space
overflowvisible, hidden, auto, scrollauto adds a scrollbar only when content overflows
overflow-x / overflow-ysame valuesControl 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 */
/* centered container */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1.5rem;
}
/* global box-sizing reset */
*, *::before, *::after {
box-sizing: border-box;
}
PropertyValuesNotes
positionstatic, relative, absolute, fixed, stickystatic is default — elements follow normal flow
top / right / bottom / leftpx, %, rem, autoOnly apply when position is not static
z-indexintegerHigher 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: 4px; }
/* absolute — removed from flow, positioned relative to nearest positioned ancestor */
.tooltip { position: absolute; top: 8px; right: 8px; }
/* 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; }
PropertyCommon valuesNotes
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 image
background-positioncenter, top right, 50% 50%, px
background-repeatrepeat, no-repeat, repeat-x, repeat-y
background-attachmentscroll, fixed, localfixed creates a parallax-like effect
backgroundshorthandurl(img.jpg) center / cover no-repeat
opacity0 to 1Affects the element and all its children. Use rgba() / hsl() alpha to target color only
/* color formats */
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);
/* image background */
background: url(hero.jpg) center / cover no-repeat;
PropertyCommon valuesNotes
font-familyfont name, serif, sans-serif, monospaceComma-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 preference
font-weightnormal (400), bold (700), 100900Availability depends on the loaded font
font-stylenormal, italic, oblique
fontshorthandstyle weight size/line-height family
line-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 breaks
text-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 */
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
PropertyCommon valuesNotes
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 8px 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);
/* frosted glass */
.panel {
background: rgba(255, 255, 255, 0.6);
backdrop-filter: blur(8px);
}

Apply container properties to the flex parent. Apply item properties to flex children.

PropertyCommon valuesNotes
displayflex, inline-flexinline-flex behaves like flex but shrinks to content width
flex-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-contentOnly 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
PropertyCommon valuesNotes
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-itemsOverrides align-items for this one item
orderintegerDefault 0. Lower numbers appear first regardless of source order
/* logo left, links right */
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
/* wrapping card row */
.cards {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}
.card {
flex: 1 1 280px; /* grow, shrink, never below 280px */
}
/* equal-width columns */
.columns { display: flex; gap: 2rem; }
.col { flex: 1; }
/* perfectly centered */
.hero {
display: flex;
justify-content: center;
align-items: center;
}

Apply container properties to the grid parent. Apply item properties to grid children.

PropertyCommon valuesNotes
displaygrid, inline-grid
grid-template-columnspx, fr, %, repeat(), minmax(), auto1fr = one fraction of available space
grid-template-rowssameExplicit row sizes. Rows without this are auto-sized
grid-template-areasquoted area namesNames 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
PropertyCommon valuesNotes
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
/* 3-column tour grid */
.tours {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
}
/* named-area layout */
.page {
display: grid;
grid-template-columns: 240px 1fr;
grid-template-areas:
"sidebar content";
gap: 2rem;
}
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
/* responsive grid — no media queries needed */
.auto-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1.5rem;
}
/* span multiple columns */
.featured { grid-column: 1 / -1; } /* full width */
PropertyCommon valuesNotes
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
transitionshorthandproperty duration timing delay
/* single property */
.btn { transition: background-color 200ms ease; }
/* multiple properties */
.card { transition: transform 200ms ease, box-shadow 200ms ease; }
/* hover lift pattern */
.card { transition: transform 200ms ease, box-shadow 200ms ease; }
.card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 24px 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.

PropertyCommon valuesNotes
animation-namekeyframe nameMust match a @keyframes rule
animation-durationms, sRequired — defaults to 0
animation-timing-functionsame as transitionCan 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 ends
animation-play-staterunning, pausedPause/resume via JavaScript or :hover
animationshorthandname duration timing delay count direction fill-mode
@keyframes fade-in {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: translateY(0); }
}
.hero { animation: fade-in 600ms ease forwards; }
/* staggered cards */
.card:nth-child(1) { animation-delay: 0ms; }
.card:nth-child(2) { animation-delay: 100ms; }
.card:nth-child(3) { animation-delay: 200ms; }
/* respect motion preferences — always include this */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
UnitTypeNotes
pxAbsoluteFixed size — does not scale with user settings
remRoot-relativeRelative to the <html> font-size (1rem = 16px by default). Preferred for typography and spacing
emElement-relativeRelative to the element’s own font-size. Compounds with nesting
%Parent-relativeRelative to the parent’s corresponding value
vwViewport1% of viewport width
vhViewport1% of viewport height
dvhDynamic viewportAccounts for mobile browser chrome appearing/disappearing
frGrid fractionOne fraction of remaining grid space. Grid-only
chCharacterWidth of the 0 glyph in the current font. Useful for setting readable line lengths
min()Functionmin(100%, 600px) — whichever is smaller
max()Functionmax(1rem, 16px) — whichever is larger
clamp()Functionclamp(min, preferred, max) — fluid values between a minimum and maximum
/* fluid typography with clamp */
h1 { font-size: clamp(1.75rem, 4vw, 3rem); }
p { font-size: clamp(1rem, 2vw, 1.125rem); }
/* readable line length */
.prose { max-width: 65ch; }
/* mobile-first: base styles apply to all screens */
/* @media rules layer on styles for progressively larger screens */
/* tablet and up */
@media (min-width: 600px) { }
/* desktop and up */
@media (min-width: 1024px) { }
/* large desktop */
@media (min-width: 1280px) { }
/* dark mode */
@media (prefers-color-scheme: dark) { }
/* reduced motion */
@media (prefers-reduced-motion: reduce) { }
/* print */
@media print { }
/* multiple conditions */
@media (min-width: 600px) and (max-width: 1023px) { }

STO breakpoints from the course: 600px (2-column cards), 768px (horizontal header), 1024px (3-column tour grid).

SyntaxExampleNotes
Define--color-primary: #2c4a1e;Convention: --kebab-case. Defined on :root for global scope
Usecolor: var(--color-primary);Second argument is a fallback: var(--color-primary, black)
OverrideRedefine on any selectorScoped: .dark { --color-primary: #fff; } affects that element and its children
:root {
/* STO design tokens */
--color-primary: #2c4a1e;
--color-accent: #a8c97f;
--font-heading: "Playfair Display", serif;
--font-body: "Source Sans 3", sans-serif;
--space-sm: 0.5rem;
--space-md: 1rem;
--space-lg: 2rem;
--radius: 0.5rem;
--shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
--max-width: 1200px;
}
.btn {
background-color: var(--color-primary);
font-family: var(--font-body);
border-radius: var(--radius);
box-shadow: var(--shadow);
}