Skip to content

CSS Cheat Sheet

This CSS cheat sheet gives you a quick reference for the most useful CSS selectors, properties, units, layout patterns, typography rules, Flexbox, Grid, responsive design, animations, forms, tables, and modern CSS features. Use it as a beginner-friendly reference while building real websites and applications.

Quick Reference List

Use this list to jump directly to the section you need. It is designed for fast lookup during development, interviews, revision, and day-to-day frontend work.

  1. CSS Syntax Cheat Sheet
  2. CSS Selectors Cheat Sheet
  3. CSS Colors Cheat Sheet
  4. CSS Units Cheat Sheet
  5. CSS Typography Cheat Sheet
  6. CSS Box Model Cheat Sheet
  7. CSS Background and Border Cheat Sheet
  8. CSS Layout Cheat Sheet
  9. CSS Flexbox Cheat Sheet
  10. CSS Grid Cheat Sheet
  11. Responsive Design Cheat Sheet
  12. Effects, Transitions, and Animations Cheat Sheet
  13. Forms and Tables Cheat Sheet
  14. Modern CSS Cheat Sheet
  15. Useful CSS Cheat Sheet Examples
  16. CSS Cheat Sheet Best Practices
  17. Common CSS Mistakes to Avoid
  18. CSS Cheat Sheet and SEO

What Is a CSS Cheat Sheet?

A CSS cheat sheet is a quick reference guide that lists commonly used CSS syntax, selectors, properties, values, and examples in one place. It helps beginners remember important CSS rules and helps experienced developers work faster.

A good cheat sheet should be structured by category, include real syntax examples, and highlight modern CSS techniques like Grid, container queries, logical properties, accessibility states, and performance-friendly animation patterns.

selector {
  property: value;
}

.card {
  padding: 1rem;
  border-radius: 0.75rem;
  background-color: #ffffff;
}

CSS Syntax Cheat Sheet

Concept Syntax Purpose
CSS Rule selector { property: value; } Basic CSS rule structure.
Declaration color: blue; One CSS property and value pair.
Comment /* comment */ Adds notes inside CSS.
Class Rule .button { ... } Styles reusable class-based elements.
Media Query @media (min-width: 768px) { ... } Applies responsive CSS.

CSS Selectors Cheat Sheet

Selector Type Example Meaning
Universal*Selects all elements.
ElementpSelects all paragraph elements.
Class.cardSelects elements with class card.
ID#headerSelects element with ID header.
Grouph1, h2, h3Applies styles to multiple selectors.
Descendant.article pSelects paragraphs inside .article.
Child.nav > liSelects direct child list items.
Adjacent Siblingh2 + pSelects the next paragraph after an h2.
Attribute[type="email"]Selects elements by attribute value.
Pseudo-classa:hoverStyles an element state.
Pseudo-elementp::first-lineStyles part of an element.

CSS Colors Cheat Sheet

Color Type Example Usage
Named Colorcolor: red;Simple predefined color names.
Hex Colorcolor: #0d6efd;Common web color format.
RGBcolor: rgb(13, 110, 253);Red, green, blue color values.
RGBAbackground: rgba(0, 0, 0, 0.5);RGB color with opacity.
HSLcolor: hsl(216, 98%, 52%);Hue, saturation, lightness.
Current Colorborder-color: currentColor;Uses the current text color.
Transparentbackground: transparent;Creates transparent background.

CSS Units Cheat Sheet

Unit Example Best Use
pxborder: 1px solid;Precise small sizes and borders.
%width: 100%;Flexible parent-based sizing.
empadding: 1em;Spacing relative to current font size.
remfont-size: 1rem;Root-based typography and spacing.
vwwidth: 100vw;Viewport width sizing.
vhmin-height: 100vh;Viewport height sizing.
dvhmin-height: 100dvh;Dynamic mobile viewport height.
chmax-width: 65ch;Readable text width.
frgrid-template-columns: 1fr 2fr;CSS Grid fractional sizing.
degrotate: 45deg;Rotation angles.
mstransition-duration: 200ms;Short animation timing.
sanimation-duration: 1s;Animation timing in seconds.

CSS Typography Cheat Sheet

Property Example Purpose
font-familyfont-family: system-ui, sans-serif;Sets font family.
font-sizefont-size: 1rem;Sets text size.
font-weightfont-weight: 700;Sets text thickness.
font-stylefont-style: italic;Sets italic or normal style.
line-heightline-height: 1.6;Sets line spacing.
letter-spacingletter-spacing: 0.05em;Controls letter spacing.
text-aligntext-align: center;Aligns text.
text-decorationtext-decoration: underline;Adds underline or line-through.
text-transformtext-transform: uppercase;Changes capitalization.
white-spacewhite-space: nowrap;Controls wrapping behavior.

CSS Box Model Cheat Sheet

Property Example Purpose
widthwidth: 100%;Sets element width.
heightheight: 300px;Sets element height.
max-widthmax-width: 1200px;Limits maximum width.
min-heightmin-height: 100vh;Sets minimum height.
marginmargin: 1rem;Outside spacing.
paddingpadding: 1rem;Inside spacing.
borderborder: 1px solid #dee2e6;Element border.
border-radiusborder-radius: 0.75rem;Rounds corners.
box-sizingbox-sizing: border-box;Controls sizing calculation.
overflowoverflow: hidden;Controls overflowing content.

CSS Background and Border Cheat Sheet

Property Example Purpose
backgroundbackground: #ffffff;Background shorthand.
background-colorbackground-color: #f8f9fa;Sets background color.
background-imagebackground-image: url("/hero.jpg");Sets background image.
background-sizebackground-size: cover;Controls image size.
background-positionbackground-position: center;Controls image position.
border-widthborder-width: 1px;Sets border thickness.
border-styleborder-style: solid;Sets border style.
border-colorborder-color: #dee2e6;Sets border color.
outlineoutline: 3px solid #0d6efd;Creates focus outline.
outline-offsetoutline-offset: 3px;Adds space around outline.

CSS Layout Cheat Sheet

Property Example Purpose
displaydisplay: block;Controls element display type.
positionposition: relative;Controls positioning method.
top/right/bottom/lefttop: 0;Offsets positioned elements.
insetinset: 0;Shorthand for all offsets.
z-indexz-index: 10;Controls stacking order.
floatfloat: left;Floats an element.
clearclear: both;Prevents float overlap.
visibilityvisibility: hidden;Hides while keeping space.
opacityopacity: 0.8;Controls transparency.

CSS Flexbox Cheat Sheet

Property Example Purpose
displaydisplay: flex;Creates flex container.
flex-directionflex-direction: row;Sets main axis direction.
flex-wrapflex-wrap: wrap;Allows items to wrap.
justify-contentjustify-content: center;Aligns items on main axis.
align-itemsalign-items: center;Aligns items on cross axis.
align-contentalign-content: space-between;Aligns wrapped lines.
gapgap: 1rem;Adds spacing between items.
flexflex: 1 1 250px;Flex item shorthand.
align-selfalign-self: flex-start;Aligns one item.
orderorder: 2;Changes visual order.

CSS Grid Cheat Sheet

Property / Function Example Purpose
displaydisplay: grid;Creates grid container.
grid-template-columnsrepeat(3, 1fr)Defines columns.
grid-template-rowsauto 1fr autoDefines rows.
grid-template-areas"header header" "sidebar main"Defines named areas.
grid-columngrid-column: span 2;Controls column placement.
grid-rowgrid-row: span 2;Controls row placement.
grid-areagrid-area: main;Places item in named area.
gapgap: 1rem;Adds grid spacing.
repeat()repeat(3, 1fr)Repeats track sizes.
minmax()minmax(250px, 1fr)Sets minimum and maximum track size.
auto-fitrepeat(auto-fit, minmax(250px, 1fr))Creates responsive grids.
place-itemsplace-items: center;Aligns grid items.

Responsive Design Cheat Sheet

Technique Example Purpose
Viewport Meta<meta name="viewport" content="width=device-width, initial-scale=1.0" />Enables mobile scaling.
Mobile First@media (min-width: 768px)Enhances layouts for larger screens.
Responsive Imagemax-width: 100%; height: auto;Prevents image overflow.
Responsive Containerwidth: min(100% - 2rem, 1200px);Creates flexible page width.
Fluid Typefont-size: clamp(2rem, 6vw, 4rem);Scales text smoothly.
Responsive Gridrepeat(auto-fit, minmax(250px, 1fr))Creates adaptive card layouts.
Dynamic Viewportmin-height: 100dvh;Handles mobile browser UI changes.

CSS Effects, Transitions, and Animations Cheat Sheet

Feature Example Purpose
Box Shadowbox-shadow: 0 1rem 2rem rgba(0,0,0,.12);Adds depth.
Text Shadowtext-shadow: 1px 1px 2px rgba(0,0,0,.3);Adds text depth.
Transformtransform: translateY(-4px);Moves, scales, rotates, or skews.
Transitiontransition: transform 0.2s ease;Smoothly changes property values.
Keyframes@keyframes fadeIn { ... }Defines animation steps.
Animationanimation: fadeIn 0.4s ease;Runs keyframe animation.
Filterfilter: blur(4px);Applies visual effects.
Reduced Motion@media (prefers-reduced-motion: reduce)Supports motion-sensitive users.

CSS Forms and Tables Cheat Sheet

Feature Example Purpose
Form Controlinput, select, textarea { font: inherit; }Makes controls match typography.
Focus State:focus-visible { outline: 3px solid; }Improves keyboard accessibility.
Placeholderinput::placeholderStyles placeholder text.
Accent Coloraccent-color: #0d6efd;Styles native checkbox/radio accents.
Validationinput:invalidStyles invalid inputs.
Table Layoutborder-collapse: collapse;Creates clean table borders.
Striped Rowstr:nth-child(even)Improves table scanability.
Responsive Tableoverflow-x: auto;Allows wide tables to scroll.
Sticky Headerthead th { position: sticky; top: 0; }Keeps table headers visible.

Modern CSS Cheat Sheet

Feature Example Best Use
CSS Variablesvar(--color-primary)Design tokens and themes.
Container Queries@container (min-width: 400px)Component responsiveness.
Cascade Layers@layer base, components, utilities;CSS priority organization.
Nesting.card { &:hover { ... } }Component selector organization.
:has().card:has(img)Parent or condition-based styling.
Logical Propertiesmargin-inline: auto;International-friendly layouts.
Aspect Ratioaspect-ratio: 16 / 9;Stable media boxes.
Scroll Snapscroll-snap-type: x mandatory;Carousel and section scrolling.
Color Schemecolor-scheme: light dark;Supports browser theme behavior.

Useful CSS Cheat Sheet Examples

/* Responsive container */
.container {
  width: min(100% - 2rem, 1200px);
  margin-inline: auto;
}

/* Responsive card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

/* Accessible focus state */
:focus-visible {
  outline: 3px solid #0d6efd;
  outline-offset: 3px;
}

/* Fluid heading */
.hero-title {
  font-size: clamp(2rem, 6vw, 4.5rem);
}

CSS Cheat Sheet Best Practices

  • Use semantic HTML before adding CSS styling.
  • Prefer class selectors for reusable components.
  • Use rem, %, fr, and clamp() for responsive layouts.
  • Use Flexbox for one-dimensional layouts.
  • Use Grid for two-dimensional layouts.
  • Use visible focus states for keyboard users.
  • Use design tokens or CSS variables for colors, spacing, radius, shadows, and typography.
  • Keep selectors simple and avoid unnecessary specificity.
  • Test CSS on mobile, desktop, keyboard, zoom, and reduced motion settings.

Common CSS Mistakes to Avoid

  • Using fixed-width layouts that break on mobile.
  • Removing focus outlines without replacement styles.
  • Using !important instead of solving specificity problems.
  • Overusing deeply nested selectors.
  • Animating layout-heavy properties like width, height, top, and left.
  • Using low-contrast text and background colors.
  • Forgetting responsive images and table wrappers.
  • Relying only on hover for important interactions.

CSS Cheat Sheet and SEO

CSS does not directly create rankings, but good CSS improves readability, accessibility, mobile usability, layout stability, performance, and page experience.

  • Responsive CSS improves mobile-friendly design.
  • Readable typography improves content consumption.
  • Accessible focus and color styles support more users.
  • Performance-friendly transitions and animations improve user experience.
  • Clean CSS helps maintain long-term page quality.

Key Takeaways

  • A CSS cheat sheet gives quick access to common syntax, selectors, properties, units, and examples.
  • Most CSS work depends on selectors, typography, colors, spacing, box model, layout, Flexbox, and Grid.
  • Responsive CSS uses media queries, flexible units, fluid containers, responsive images, and modern viewport units.
  • Modern CSS features like variables, container queries, cascade layers, :has(), and clamp() improve development speed.
  • Accessible CSS includes visible focus states, readable contrast, responsive layouts, and reduced motion support.

Pro Tip

Bookmark this CSS cheat sheet and learn it by category: selectors, colors, units, typography, box model, Flexbox, Grid, responsive design, animations, forms, tables, and modern CSS.