CSS Cheat Sheet

Reference and Guide for all CSS levels (Fundamentals to Advanced) Utilizing only HTML and CSS without anything froo froo fancypants. Thats all.

Salvation is in Jesus Christ alone;
Repent and trust in Jesus Christ alone
for forgiveness of sin and salvation today!
The Gospel Message


Section A – CSS Fundamentals

Note: This section introduces the core building blocks of how CSS works — including syntax, rules, and how style declarations are applied to HTML elements.

Section B – Selectors

Note: Selectors are patterns used to target HTML elements and apply styles.

Section C – Box Model

Note: Every HTML element is a rectangular box composed of content, padding, border, and margin. This section explains how layout space is calculated and adjusted using the box model.

Section D – Display & Positioning

Note: This section explains how elements behave in the layout flow using display and how to explicitly control their location using the position property and offsets.

Section E – Flexbox

Note: Flexbox is a one-dimensional layout system that allows elements to align and distribute space within a container along a single axis (row or column).

Section F – Grid

Note: CSS Grid enables two-dimensional layouts, allowing you to control both rows and columns in a container. It is powerful for creating complex web layouts.

Section G – Typography

Note: This section covers how to control fonts, sizes, spacing, alignment, decoration, and other properties that affect text appearance.

Section H – Colors

Note: CSS provides multiple ways to define and manipulate color, including named keywords, hexadecimal, RGB(A), HSL(A), and modern color spaces like LAB and LCH.

Section I – Units & Values

Note: CSS uses units to express length, time, angle, and more. This section details unit types and common value formats used in style declarations.

Section J – Backgrounds

Note: CSS backgrounds define the fill behind an element’s content and can include color, images, gradients, and layered effects.

Section K – Borders & Outlines

Note: Borders form part of the element box and control thickness, color, and style. Outlines are external indicators, useful for accessibility and focus states.

Section L – Sizing

Note: CSS sizing properties allow control over the rendered dimensions of elements, including width, height, and constraints like min/max values.

Section M – Spacing

Note: CSS spacing properties control both internal space (padding) and external space (margin) around elements. Logical spacing respects writing direction.

Section N – Layout Strategies

Note: CSS layout strategies provide ways to arrange elements on the page using different models like block, flexbox, grid, and absolute positioning. Choosing the right strategy is key for responsive, maintainable layouts.

Section O – Media Queries

Note: Media queries apply conditional CSS rules depending on the viewport or device. They're essential for creating responsive and accessible designs.

Section P – Transforms

Note: CSS transforms let you manipulate elements in 2D or 3D space. Transformed elements remain in the same flow but can be visually moved, rotated, scaled, or skewed.

Section Q – Transitions & Animations

Note: CSS transitions animate changes between property values, while animations allow control over multiple stages via keyframes.

Section R – Custom Properties (Variables)

Note: CSS variables allow you to define and reuse consistent values across your stylesheet. They can be scoped to elements and updated dynamically.

Section S – Pseudo-Classes & Pseudo-Elements

Note: Pseudo-classes target elements based on behavior, position, or user interaction. Pseudo-elements create abstract parts of elements to style or populate.

Section T – Z-Index & Stacking

Note: The `z-index` property determines the stack order of elements along the Z axis. Higher values appear on top. Only works on positioned or flex/grid children.

Section U – Overflow & Clipping

Note: CSS overflow controls whether content that exceeds its container is visible, hidden, clipped, or scrollable. Clipping provides finer control over visible regions.

Section V – Visibility & Opacity

Note: These properties control whether an element is visible, how it participates in layout, and its visual transparency without affecting DOM structure.

Section W – Cursors & User Interaction

Note: These properties define how the pointer appears when hovered over an element, and whether users can interact or select its content.

Section X – Print Styles

Note: CSS print styles ensure documents are formatted correctly when printed, removing unnecessary elements and managing layout breaks across pages.

Section Y – Accessibility (A11y)

Note: While semantic HTML is key for accessibility, CSS can assist with focus visibility, motion control, color contrast, and screen reader-friendly practices.

Section Z – Shorthand Properties

Note: Shorthand properties group related CSS properties into a single declaration, reducing repetition and improving maintainability. However, omitted values reset to their defaults.

Section AA – Best Practices

Note: These are established techniques for writing clean, robust, and forward-compatible CSS in production environments.

Section AB – Common Pitfalls

Note: These are mistakes developers often make when writing CSS. Understanding them helps avoid bugs, layout inconsistencies, and accessibility issues.

Section AC – Debugging Tools

Note: Debugging CSS effectively requires visual inspection, layout tracing, and clear indicators of how styles are applied and inherited.

Section AD – Cheat Sheet Structure

Note: This section explains the foundational layout, code organization, and logic behind building the cheat sheet for consistent long-term scalability.

Section AE – Reference Section

Note: This glossary-style section allows quick access to recurring CSS concepts, unit types, common keywords, and external documentation.

Section AG – Container Queries

Note: Container Queries allow elements to style themselves based on the width, height, or inline size of their parent. Useful for responsive components and layout blocks.

Section AH – Environment Variables

Note: Environment variables are accessed using the env() function. They adjust layout based on device conditions like notches, navigation bars, and system UI constraints.

Section AI – Logical Properties

Note: Logical properties automatically adapt styles based on writing direction (like Arabic or vertical Japanese) and support internationalization better than physical properties like left or top.

Section AJ – Cascade Layers (@layer)

Note: @layer introduces a new way to control the cascade — before specificity and order — allowing cleaner overrides between resets, base styles, utilities, and component-specific rules.

Section AK – Modern Color Spaces

Note: Use modern color spaces to achieve better contrast, uniform perceptual shifts, and improved accessibility on wide-gamut displays.

Section AL – Scroll Behavior

Note: CSS scroll behavior controls how scrolling transitions occur, including anchor jumps and programmatic scrolling. Use it for a smoother user experience in single-page layouts or in-page navigation.

Section AM – Aspect Ratio (Deep Dive)

Note: aspect-ratio maintains a consistent ratio between width and height. Ideal for images, videos, containers, and placeholders in responsive layouts.

Section AN – Form Styling

Note: Form controls require careful styling for consistency across browsers, accessibility, and responsive layout. CSS enables full control over layout, spacing, colors, focus, and states.

Section AO – Masking & Clipping

Note: Use clip-path and mask to show only portions of elements, apply decorative cutouts, or reveal content selectively. Both support basic shapes, paths, and gradients.

Section AP – CSS-Only UI Components

Note: With creative use of selectors like :checked, :focus-within, and :target, you can build functional UI components entirely in CSS. These are ideal for minimal environments or performance-critical apps.

Section AQ – Layered Animations

Note: Layered animations coordinate multiple CSS effects using animation, @keyframes, transition-delay, and stacking logic. These techniques produce complex motion sequences without JavaScript.

Section AR – Filter Effects

Note: CSS filters modify the appearance of content without changing layout. They are ideal for hover effects, modal backdrops, or stylized visuals in UI/UX.

Section AS – Blend Modes & Isolation

Note: mix-blend-mode and background-blend-mode define how an element or its background interacts with what's underneath. isolation lets you prevent blending with unrelated layers.

Section AT – Backdrop & Glassmorphism

Note: backdrop-filter applies effects to the background behind an element. Glassmorphism combines this with transparency and subtle borders for a frosted-glass look.

Section AU – Advanced Compositing

Note: Compositing governs how layered elements mix visually. Mastering isolation, filters, masks, and stacking order enables clean, predictable, high-performance visuals.

Section AV – Writing Robust Utility Classes

Note: Utility-first CSS emphasizes composability, where small, atomic classes apply specific rules (e.g. .text-center, .mt-4, .bg-blue). This reduces the need for verbose selectors and improves consistency.

Section AW – CSS-Only Interactivity

Note: You can build toggles, dropdowns, accordions, tabs, and lightboxes using only CSS selectors and states. No JavaScript needed when behavior relies on checkboxes, radio buttons, and URL targets.

Section AX – Custom Scrollbars

Note: CSS allows you to override the native scrollbar appearance in WebKit-based browsers and partially in Firefox. These are often used for dark mode support or UI branding. Use sparingly and test thoroughly.

Section AY – Forced Colors & Media Features

Note: Use media queries like forced-colors, prefers-color-scheme, and prefers-reduced-motion to respond to the user's system or browser settings. These improve usability, accessibility, and compliance.

Section AZ – Feature Queries (@supports)

Note: @supports lets you apply styles only if the browser supports a given property-value pair. This is essential for fallbacks and modern enhancements (e.g. grid, gap, container queries).

Section BA – Interactivity Without JavaScript

Note: CSS-only interaction patterns can replicate many common UI behaviors. Combine form elements, selectors, and pseudo-classes like :checked and :target to manage UI state without scripts.

Section BB – CSS Naming Conventions

Note: Following clear and systematic naming conventions improves maintainability, especially in large or team-based CSS projects. Common strategies include BEM, OOCSS, SMACSS, and utility-based systems.

Section BC – State Machine Logic (CSS-Only)

Note: CSS-only state logic allows the UI to change behavior based on form input states. This technique simulates "machines" where user input defines the current visual/interactive state — all without scripting.

Section BD – GPU Performance & Containment

Note: GPU optimization minimizes layout thrashing and repaints by isolating animations and render operations. The contain property and hardware acceleration techniques like transform: translateZ(0) improve rendering and animation smoothness.

Section BE – Framework Compatibility Notes

Note: Frameworks ship with opinionated styles, variables, and class structures. Custom CSS must be scoped and structured carefully to avoid unexpected overrides or conflicts.

Section BF – Dark/Light Mode Switching

Note: CSS supports both automatic and manual dark/light mode theming. Use prefers-color-scheme to detect system preference and toggle CSS variables or themes manually — all without JavaScript.

Section BG – Safe Area Insets (Mobile)

Note: On mobile browsers with dynamic display regions (e.g., iPhones with notches), environment variables help prevent content overlap with OS UI. Use env(safe-area-inset-*) to dynamically pad UI.

Section BH – CSS Hacks & Escape Techniques

Note: CSS hacks should be used sparingly and only when necessary, ideally with fallback strategies. Most hacks target legacy browsers, specificity collisions, or unsupported features.

Section BI – Accessibility & Reduced Motion Handling

Note: CSS can help make your UI more inclusive by supporting reduced motion, visible focus states, high contrast, and semantic structure. Always test for screen reader and keyboard navigation support.

Section BJ – Print & Pagination Features (@page)

Note: Use print-specific styles and the @page at-rule to optimize documents for printing. Print CSS helps eliminate unnecessary elements, format content, and handle page breaks.

Section BK – Experimental & Deprecated Features

Note: Use experimental features with caution and behind feature detection. Avoid deprecated properties in production unless absolutely necessary for legacy support.

Section BL – Unit Reference Table

Note: Always choose units based on context — use relative units (like em, rem, %) for fluid layouts, and viewport units (vw, vh) for responsive scaling.

Unit Type Description Common Use
px Absolute Pixel — fixed size on screen, not scalable Fine control of borders, spacing, layout
em Relative Relative to the font-size of the parent Font sizing, spacing, nested elements
rem Relative Relative to the root html font-size Consistent sizing across entire document
% Relative Percentage of containing block Fluid width/height, responsive layout
vw Viewport 1% of the viewport width Hero sections, responsive typography
vh Viewport 1% of the viewport height Full-screen layouts, vertical centering
vmin Viewport Smaller of vw and vh Scale elements based on smaller dimension
vmax Viewport Larger of vw and vh Responsive UI with maximum expansion
ch Relative Width of the "0" character in current font Text boxes, monospace control
ex Relative Height of the lowercase "x" Font-based vertical sizing
lh Relative Line-height unit, relative to the element’s line-height Typography control, spacing
fr Grid-specific Fractional unit for CSS Grid layout Distribute space in grid columns/rows
cm / mm / in Absolute Physical dimensions — rarely used Print CSS or exact physical layouts
pt / pc Absolute Point and pica — for print typography Legacy typesetting or PDFs

Best practices:

Section BM – Snippet Library

Note: These CSS-only code snippets provide quick solutions for layout, utility classes, helpers, and responsive design — all usable without JavaScript.

Section BN – CSS Functions Index

Note: CSS functions allow for dynamic styling, filtering, responsive math, and logic-based property control. Most are usable in any modern browser.

Function Purpose Example
calc() Performs math in CSS width: calc(100% - 2rem);
min() Returns the smallest value width: min(400px, 100%);
max() Returns the largest value height: max(2rem, 10vh);
clamp() Constrains a value within a range font-size: clamp(1rem, 2vw, 2rem);
var() Access a CSS custom property color: var(--primary);
url() References external assets background: url("image.jpg");
rgba(), hsla() Define colors with transparency color: rgba(0, 0, 0, 0.5);
attr() Access HTML attributes in content content: attr(data-label);
env() Access device environment values padding: env(safe-area-inset-top);
round() (future) Rounding math — limited support margin: round(33.33%, 5%);
color-mix() Mixes two colors color: color-mix(in srgb, red 50%, blue);
image-set() Responsive image loading background-image: image-set("low.jpg" 1x, "high.jpg" 2x);
linear-gradient() Creates gradients background: linear-gradient(to right, #000, #fff);

Best practices:

Section BO – Visual Debug Patterns

Note: Use debug patterns to visualize box model behavior, stacking context, z-index issues, or layout anomalies. These should be removed or toggled off before deployment.

Section BP – Cross-Browser Compatibility Practices

Note: Different browsers render styles with subtle (or major) differences. Use these practices to minimize issues and ensure a consistent UI.

Section BQ – Layered Responsive Design Patterns

Note: These patterns leverage multiple CSS technologies layered together for resilient, responsive, and scalable UIs.

Best Practices:

Section BR – Color Accessibility & Contrast Optimization

Note: Use high contrast and semantic colors to ensure readability for all users. WCAG guidelines recommend a contrast ratio of at least 4.5:1 for normal text.

Best Practices:

Section BS – Browser Engine Quirks

Note: Even with standards-based CSS, different engines have quirks. Knowing them prevents bugs and improves stability across platforms.

Best Practices:

Section BT – Production Deployment and Minification

Note: Production-ready CSS must be compact, fast-loading, and clean. This step involves optimizing output for browsers while preserving visual fidelity and responsive behavior.

Best Practices: