dev.rean.me
css

Complete CSS Reference — Properties, Selectors, Units & Best Practices

Complete CSS reference guide covering all CSS properties, selectors, combinators, pseudo-classes, pseudo-elements, units, variables, flexbox, grid, animations, transitions, media queries, and best practices.

2026-09-19 · 22 min read

Share:

Hello my friend! Welcome to the Complete CSS Reference on dev.rean.me! This page is your one-stop reference for every important CSS property, selector, unit, and modern feature — organized clearly by category so you can find what you need in seconds!

Bookmark this page and use it every time you write CSS! Let's go!


1. 🎯 Selectors Reference

Basic Selectors

SelectorExampleDescription
Universal*Selects all elements
Type / Elementh1Selects all <h1> elements
Class.cardSelects elements with class="card"
ID#navbarSelects element with id="navbar"
Attribute[type="text"]Selects elements with matching attribute

Combinator Selectors

SelectorExampleDescription
Descendantdiv pSelects <p> anywhere inside <div>
Childul > liSelects <li> that is a direct child of <ul>
Adjacent Siblingh2 + pSelects <p> immediately after <h2>
General Siblingh2 ~ pSelects all <p> siblings after <h2>

Attribute Selectors

SelectorDescription
[attr]Has this attribute
[attr="val"]Attribute exactly equals value
[attr^="val"]Attribute starts with value
[attr$="val"]Attribute ends with value
[attr*="val"]Attribute contains value anywhere
[attr~="val"]Attribute contains value in space-separated list

Pseudo-Class Selectors

Pseudo-ClassDescription
:hoverElement is being hovered by mouse
:focusElement has keyboard/mouse focus
:focus-visibleElement has focus via keyboard (not mouse)
:focus-withinElement or descendant has focus
:activeElement is being clicked/pressed
:visitedVisited hyperlink
:linkUnvisited hyperlink
:checkedChecked checkbox or radio button
:disabledDisabled form element
:enabledEnabled form element
:requiredInput with required attribute
:optionalInput without required attribute
:validInput passing validation
:invalidInput failing validation
:user-validInput valid after user interaction
:user-invalidInput invalid after user interaction
:placeholder-shownInput currently showing placeholder text
:emptyElement with no children or text
:rootRoot element — <html> (use for CSS variables)
:not(selector)Elements that do NOT match the selector
:is(a, b)Matches any selector in list (lower specificity)
:where(a, b)Like :is() but zero specificity
:has(selector)Parent selector — element containing a match
:first-childFirst child of its parent
:last-childLast child of its parent
:nth-child(n)The nth child (odd, even, 2n+1, etc.)
:nth-last-child(n)nth child counting from the end
:first-of-typeFirst element of that type in its parent
:last-of-typeLast element of that type in its parent
:nth-of-type(n)nth element of that type
:only-childElement with no siblings
:only-of-typeOnly element of that type in its parent

Pseudo-Element Selectors

Pseudo-ElementDescription
::beforeInserts content before the element
::afterInserts content after the element
::first-lineStyles the first line of text
::first-letterStyles the first letter of text
::placeholderStyles the input placeholder text
::selectionStyles the user's selected/highlighted text
::markerStyles list item bullet or number
::file-selector-buttonStyles file input browse button
::backdropStyles the <dialog> backdrop overlay

💡 Tip: Use :is() to shorten long selector lists! Instead of h1 a, h2 a, h3 a write :is(h1, h2, h3) a — cleaner and more maintainable!


2. 📦 Box Model Properties

Every HTML element is a rectangular box. The box model defines how its size is calculated.

PropertyDescriptionExample
widthElement content widthwidth: 300px
heightElement content heightheight: 200px
min-widthMinimum widthmin-width: 200px
max-widthMaximum widthmax-width: 1200px
min-heightMinimum heightmin-height: 100px
max-heightMaximum heightmax-height: 500px
paddingInner spacing (inside the border)padding: 16px
padding-top/right/bottom/leftIndividual padding sidespadding-top: 8px
marginOuter spacing (outside the border)margin: 0 auto
margin-top/right/bottom/leftIndividual margin sidesmargin-bottom: 24px
borderShorthand for width, style, colorborder: 1px solid #ccc
border-widthBorder thicknessborder-width: 2px
border-stylesolid, dashed, dotted, double, noneborder-style: dashed
border-colorBorder colorborder-color: red
border-radiusRounds cornersborder-radius: 8px
border-top/right/bottom/leftIndividual border sidesborder-top: 2px solid blue
box-sizingHow width/height is calculatedbox-sizing: border-box
outlineOutline outside border (no layout space)outline: 2px solid blue
outline-offsetGap between border and outlineoutline-offset: 4px

💡 Tip: Always set box-sizing: border-box on all elements! This makes width and height include padding and border — preventing elements from overflowing their containers:

*, *::before, *::after { box-sizing: border-box; }

3. 🎨 Color & Background Properties

PropertyDescriptionExample
colorText colorcolor: #333
backgroundShorthand for all background propertiesbackground: #f5f5f5
background-colorSolid background colorbackground-color: rgba(0,0,0,0.5)
background-imageBackground image or gradientbackground-image: url('bg.jpg')
background-sizecover, contain, or exact sizebackground-size: cover
background-positionImage positionbackground-position: center
background-repeatrepeat, no-repeat, repeat-x/ybackground-repeat: no-repeat
background-attachmentscroll or fixed (parallax)background-attachment: fixed
background-originWhere background startsbackground-origin: border-box
background-clipWhere background is clippedbackground-clip: text
opacityElement transparency 0 (invisible) to 1 (solid)opacity: 0.5

Color Value Formats:

FormatExample
Named Colorred, blue, tomato, coral
Hex#ff5733 or short #f53
RGBrgb(255, 87, 51)
RGBArgba(255, 87, 51, 0.8)
HSLhsl(14, 100%, 60%)
HSLAhsla(14, 100%, 60%, 0.8)
oklchoklch(65% 0.2 25) — modern perceptual color space
currentColorInherits the current color value
transparentFully transparent

4. 📝 Typography / Font Properties

PropertyDescriptionExample
font-familyFont name with fallbacksfont-family: 'Inter', sans-serif
font-sizeText sizefont-size: 16px
font-weight100–900, bold, normalfont-weight: 700
font-stylenormal, italic, obliquefont-style: italic
font-variantnormal or small-capsfont-variant: small-caps
fontShorthand — style, variant, weight, size/line-height, familyfont: 700 16px/1.5 'Inter', sans-serif
line-heightSpace between lines of textline-height: 1.6
letter-spacingSpace between charactersletter-spacing: 0.05em
word-spacingSpace between wordsword-spacing: 4px
text-alignleft, right, center, justify, start, endtext-align: center
text-decorationunderline, line-through, overline, nonetext-decoration: none
text-decoration-colorColor of the text decoration linetext-decoration-color: red
text-decoration-thicknessThickness of the decoration linetext-decoration-thickness: 2px
text-underline-offsetGap between text and underlinetext-underline-offset: 4px
text-transformuppercase, lowercase, capitalize, nonetext-transform: uppercase
text-indentFirst-line indentationtext-indent: 2em
text-overflowclip or ellipsis for overflow texttext-overflow: ellipsis
text-shadowShadow behind texttext-shadow: 2px 2px 4px rgba(0,0,0,0.3)
white-spacenormal, nowrap, pre, pre-wrapwhite-space: nowrap
word-breaknormal, break-all, keep-allword-break: break-word
overflow-wrapnormal or break-wordoverflow-wrap: break-word
vertical-alignInline element vertical alignmentvertical-align: middle
directionltr or rtl text directiondirection: rtl
unicode-bidiBidirectional text overrideunicode-bidi: embed

5. 📐 Display & Layout Properties

PropertyValuesDescription
displayblock, inline, inline-block, flex, grid, none, contentsControls element rendering type
visibilityvisible, hidden, collapseHide without removing space
positionstatic, relative, absolute, fixed, stickyPositioning method
top / right / bottom / leftLength valuesOffset from positioned ancestor
z-indexIntegerStacking order (higher = on top)
floatleft, right, noneFloat element to left/right
clearleft, right, both, noneClear floated elements
overflowvisible, hidden, scroll, autoContent overflow behavior
overflow-xSame as overflowHorizontal overflow only
overflow-ySame as overflowVertical overflow only
clip-pathShape valuesClip element to a shape
object-fitfill, contain, cover, scale-down, noneHow <img> or <video> fits its box
object-positionPosition valuesPosition of <img> within its box
aspect-ratioe.g. 16/9Lock width-to-height ratio

6. 📏 Units Reference

Absolute Units

UnitDescription
pxPixels — most common absolute unit
ptPoints — 1pt = 1.33px (print media)
cmCentimeters
mmMillimeters
inInches

Relative Units

UnitRelative To
emParent element's font-size
remRoot (<html>) element's font-size
%Parent element's size
vw1% of the viewport width
vh1% of the viewport height
vmin1% of the smaller of vw or vh
vmax1% of the larger of vw or vh
svhSmall viewport height (excludes mobile browser chrome)
dvhDynamic viewport height (updates as mobile chrome shows/hides)
chWidth of the 0 character in the current font
exHeight of the x character in the current font
frFraction unit — only used inside CSS Grid
lhCurrent element's line-height
rlhRoot element's line-height

💡 Tip: Use rem for font sizes and em for spacing that should scale with its component's font size. Use px only for borders and very small values that should NOT scale!


7. 🔄 Flexbox Properties

Container Properties (display: flex)

PropertyValuesDescription
displayflex / inline-flexEnable flexbox
flex-directionrow, row-reverse, column, column-reverseMain axis direction
flex-wrapnowrap, wrap, wrap-reverseAllow items to wrap to next line
flex-flow<direction> <wrap>Shorthand for direction + wrap
justify-contentflex-start, flex-end, center, space-between, space-around, space-evenlyAlign items on main axis
align-itemsstretch, flex-start, flex-end, center, baselineAlign items on cross axis
align-contentSame as justify-contentAlign wrapped lines
gapLengthGap between flex items (row and column)
row-gapLengthGap between rows
column-gapLengthGap between columns

Item Properties

PropertyValuesDescription
flex<grow> <shrink> <basis>Shorthand for all three below
flex-growNumber (default: 0)How much item grows relative to others
flex-shrinkNumber (default: 1)How much item shrinks relative to others
flex-basisLength or autoInitial main-axis size before flex
align-selfSame as align-itemsOverride alignment for this item only
orderIntegerVisual order of items (default: 0)

💡 Tip: flex: 1 is shorthand for flex: 1 1 0% — makes an item grow to fill all available space equally. Very useful for making columns the same width!


8. ▦ CSS Grid Properties

Container Properties (display: grid)

PropertyDescriptionExample
displayEnable griddisplay: grid
grid-template-columnsDefine column track sizesgrid-template-columns: 1fr 2fr 1fr
grid-template-rowsDefine row track sizesgrid-template-rows: auto 1fr
grid-template-areasNamed area layout mapsee example below
grid-templateShorthand for rows + columns + areas
grid-auto-columnsSize of implicit columnsgrid-auto-columns: 200px
grid-auto-rowsSize of implicit rowsgrid-auto-rows: minmax(100px, auto)
grid-auto-flowrow, column, denseHow auto-placed items fill the grid
gapRow and column gap togethergap: 16px
row-gapSpace between rowsrow-gap: 24px
column-gapSpace between columnscolumn-gap: 16px
justify-itemsAlign items horizontally in their celljustify-items: center
align-itemsAlign items vertically in their cellalign-items: stretch
place-itemsShorthand for align + justify itemsplace-items: center
justify-contentAlign the whole grid horizontallyjustify-content: center
align-contentAlign the whole grid verticallyalign-content: start
place-contentShorthand for align + justify contentplace-content: center

Grid Item Properties

PropertyDescriptionExample
grid-columnSpan columns (start / end)grid-column: 1 / 3
grid-rowSpan rows (start / end)grid-row: 1 / 4
grid-areaReference a named grid areagrid-area: header
justify-selfOverride horizontal alignmentjustify-self: start
align-selfOverride vertical alignmentalign-self: end

Grid Template Areas Example:

.container {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 250px 1fr;
}
.header  { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main    { grid-area: main; }
.footer  { grid-area: footer; }

Useful Grid Functions:

FunctionDescription
repeat(3, 1fr)Repeat track 3 times
minmax(200px, 1fr)Min 200px, max fills remaining space
auto-fillFill as many tracks as possible
auto-fitFill and collapse empty tracks
fit-content(400px)Max width of 400px but shrinks to fit content

💡 Tip: grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) creates a fully responsive card grid that adjusts column count automatically — no media queries needed!


9. 🎬 Transitions & Animations

Transitions

PropertyDescriptionExample
transitionShorthand for all transition propertiestransition: all 0.3s ease
transition-propertyWhich property to animatetransition-property: opacity, transform
transition-durationHow long the transition takestransition-duration: 0.3s
transition-timing-functionSpeed curvetransition-timing-function: ease-in-out
transition-delayWait before startingtransition-delay: 0.1s

Timing Functions:

ValueDescription
easeSlow start, fast middle, slow end (default)
linearConstant speed throughout
ease-inSlow start, fast end
ease-outFast start, slow end
ease-in-outSlow start and end, fast middle
cubic-bezier(x1,y1,x2,y2)Custom speed curve
steps(4, end)Jumps in discrete steps

Animations (@keyframes)

/* Define the animation */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Apply it */
.card {
  animation: fadeInUp 0.5s ease-out forwards;
}
PropertyDescriptionExample
animationShorthand for all animation propertiesanimation: slide 1s ease infinite
animation-nameName of the @keyframes blockanimation-name: fadeInUp
animation-durationHow long one cycle takesanimation-duration: 0.5s
animation-timing-functionSpeed curve (same as transition)animation-timing-function: ease
animation-delayWait before first playanimation-delay: 0.2s
animation-iteration-count1, 3, or infiniteanimation-iteration-count: infinite
animation-directionnormal, reverse, alternate, alternate-reverseanimation-direction: alternate
animation-fill-modenone, forwards, backwards, bothanimation-fill-mode: forwards
animation-play-staterunning or pausedanimation-play-state: paused

10. 🔄 Transform Properties

FunctionDescriptionExample
translate(x, y)Move elementtransform: translate(50px, 20px)
translateX(x)Move horizontallytransform: translateX(-50%)
translateY(y)Move verticallytransform: translateY(-50%)
translateZ(z)Move on Z-axis (3D)transform: translateZ(100px)
scale(x, y)Scale elementtransform: scale(1.2)
scaleX(x)Scale horizontallytransform: scaleX(2)
scaleY(y)Scale verticallytransform: scaleY(0.5)
rotate(angle)Rotate elementtransform: rotate(45deg)
rotateX(angle)Rotate on X-axis (3D flip)transform: rotateX(180deg)
rotateY(angle)Rotate on Y-axis (3D flip)transform: rotateY(180deg)
skew(x, y)Skew/shear elementtransform: skew(10deg, 5deg)
matrix(...)Combined 2D transformation matrixtransform: matrix(...)
perspective(n)Set 3D perspective depthperspective: 1000px

Related Properties:

PropertyDescription
transform-originPoint the transform rotates/scales from
transform-style: preserve-3dEnable 3D space for children
backface-visibilityShow or hide back face of 3D flip
will-change: transformHint GPU optimization for animated property

11. 📱 Media Queries & Responsive Design

/* Mobile first — apply styles for all screen sizes first */
.container { padding: 16px; }

/* Tablet — 768px and above */
@media (min-width: 768px) {
  .container { padding: 24px; }
}

/* Desktop — 1024px and above */
@media (min-width: 1024px) {
  .container { padding: 32px; }
}

/* Large desktop */
@media (min-width: 1280px) {
  .container { max-width: 1200px; margin: 0 auto; }
}

Common Media Feature Reference:

FeatureExampleDescription
min-width(min-width: 768px)Viewport at least 768px wide
max-width(max-width: 767px)Viewport at most 767px wide
min-height(min-height: 600px)Viewport at least 600px tall
orientation(orientation: landscape)Device in landscape mode
prefers-color-scheme(prefers-color-scheme: dark)User prefers dark mode
prefers-reduced-motion(prefers-reduced-motion: reduce)User wants fewer animations
hover(hover: hover)Device supports hover (e.g., mouse)
pointer(pointer: coarse)Coarse pointer (touchscreen)
display-mode(display-mode: standalone)App is running as installed PWA
print@media print { }Print-specific styles

Container Queries (Modern):

.card-container { container-type: inline-size; }

@container (min-width: 400px) {
  .card { display: flex; }
}

💡 Tip: Always design mobile-first — start with styles for small screens, then add min-width media queries as screen gets larger. This is better than designing for desktop and overriding with max-width queries!


12. 🎨 CSS Custom Properties (Variables)

/* Define variables on :root for global scope */
:root {
  --color-primary: #6366f1;
  --color-bg: #ffffff;
  --color-text: #1a1a2e;
  --font-size-base: 16px;
  --radius: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  --spacing-md: 16px;
}

/* Use with var() */
.button {
  background: var(--color-primary);
  border-radius: var(--radius);
  padding: var(--spacing-md);
  font-size: var(--font-size-base);
}

/* Dark mode overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f0f1a;
    --color-text: #e5e5f0;
  }
}

/* Fallback value */
color: var(--color-brand, #6366f1);

💡 Tip: CSS variables are reactive — changing a variable on :root instantly updates every element using it. Perfect for building consistent design systems and dark mode themes!


13. 💡 Useful CSS Functions

FunctionDescriptionExample
var()Reference a CSS custom propertycolor: var(--primary)
calc()Mathematical calculationwidth: calc(100% - 48px)
clamp(min, val, max)Value clamped between min and maxfont-size: clamp(1rem, 2.5vw, 2rem)
min(a, b)Picks the smallest valuewidth: min(90%, 600px)
max(a, b)Picks the largest valuepadding: max(16px, 4vw)
rgb() / rgba()Define color with red, green, bluecolor: rgb(100, 200, 100)
hsl() / hsla()Define color with hue, saturation, lightnesscolor: hsl(200, 80%, 50%)
oklch()Perceptual color model (modern)color: oklch(65% 0.2 250)
linear-gradient()Linear color gradientbackground: linear-gradient(to right, #f00, #00f)
radial-gradient()Radial color gradientbackground: radial-gradient(circle, #f00, #00f)
conic-gradient()Conic (pie-chart) gradientbackground: conic-gradient(red, blue, red)
url()Reference an external filebackground-image: url('photo.jpg')
attr()Use element's attribute value in CSScontent: attr(data-label)
counter()Display CSS counter valuecontent: counter(section)
env()Access browser environment variablepadding: env(safe-area-inset-bottom)
format()Font format hint inside @font-faceformat('woff2')

14. 🎭 Pseudo & Special Properties

::before & ::after Pattern

.icon-check::before {
  content: "✓";
  color: green;
  margin-right: 8px;
}

/* Clear float hack */
.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

content Property Values

ValueDescription
""Empty string (used for decorative elements)
"text"Literal text string
url('icon.svg')Insert an image
attr(data-label)Use attribute value
counter(section)Display counter
open-quote / close-quoteInsert quotation mark
noneRemove the pseudo-element

CSS Scroll & Scroll Snap

PropertyDescription
scroll-behavior: smoothSmooth scrolling when navigating to anchors
scroll-snap-typeEnable snap points (x mandatory, y proximity)
scroll-snap-alignSnap alignment (start, center, end)
scroll-paddingOffset the snap scroll position (e.g., for fixed headers)
overflow-anchorControl scroll anchoring behavior

15. ✅ CSS Best Practices Checklist

  • ✅ Use box-sizing: border-box on everything — *, *::before, *::after
  • ✅ Design mobile-first — base styles for small screens, min-width queries for larger
  • ✅ Use CSS Custom Properties (--var) for colors, spacing, and radii
  • ✅ Use rem for font sizes — scales with the user's browser font preference
  • ✅ Prefer gap over margin for spacing inside Flex and Grid layouts
  • ✅ Use transition on hover states for smooth, polished interactions
  • ✅ Add prefers-reduced-motion media query to disable animations for accessibility
  • ✅ Use aspect-ratio to maintain image ratios and prevent layout shift
  • ✅ Use object-fit: cover on <img> inside a sized container for clean cropping
  • ✅ Avoid deeply nested selectors — keep specificity low and predictable
  • ✅ Use will-change: transform sparingly — only on elements you know will animate
  • ✅ Use clamp() for fluid typography instead of multiple breakpoints
  • ✅ Use @layer to manage CSS specificity in large projects
  • ✅ Lint and format your CSS with Stylelint and Prettier


Hope this complete CSS reference guide helps you write better, cleaner, and more modern CSS every day! Bookmark this page and share it with your developer friends! 🎨✨

← Back to css
Share: