*
Browse / CSS 3 Quick Reference Cheatsheet
CSS 3 Quick Reference Cheatsheet
A comprehensive cheat sheet covering essential CSS3 selectors, properties, values, units, layout techniques, and best practices for modern web design.
Selectors & Basic Styling
Basic Selectors
|
Selects all elements. |
|
Selects elements of a specific type (e.g., |
|
Selects elements with a specific class (e.g., |
|
Selects the element with a specific ID (e.g., |
|
Selects elements with a specific attribute (e.g., |
|
Selects elements with a specific attribute and value. |
|
Selects elements whose attribute value contains a specified word. |
|
Selects elements whose attribute value starts with the specified word followed by a hyphen. |
|
Selects elements whose attribute value begins with a specified value. |
|
Selects elements whose attribute value ends with a specified value. |
|
Selects elements whose attribute value contains a specified value. |
Combinators
|
Descendant Selector: Selects B inside A. |
|
Child Selector: Selects direct children B of A. |
|
Adjacent Sibling Selector: Selects B immediately following A. |
|
General Sibling Selector: Selects B anywhere after A within the same parent. |
|
|
|
|
Pseudo-Classes & Pseudo-Elements
|
Selects an element when you mouse over it. |
|
Selects the active link/element. |
|
Selects an element that has focus. |
|
Selects links that have been visited. |
|
Selects unvisited links. |
|
Selects the first child of its parent. |
|
Selects the last child of its parent. |
|
Selects the n-th child of its parent (e.g., |
|
Selects elements that do NOT match the selector. |
|
Selects checked input elements (radio or checkbox). |
|
Inserts content before an element. |
|
Inserts content after an element. |
|
Selects the first line of a block-level element. |
|
Selects the first letter of a block-level element. |
Box Model (Block)
|
Sets how an element is displayed ( |
|
Sets the width and height of an element. |
|
Shorthand for |
|
Shorthand for |
|
Shorthand for |
|
Defines how the total width and height of an element are calculated ( |
|
|
Colors & Backgrounds
|
Sets the text color. |
|
Sets the background color of an element. |
|
Sets the background image ( |
|
Sets how a background image repeats ( |
|
Sets the starting position of a background image ( |
|
Sets the size of the background image ( |
|
Sets whether a background image scrolls with the page or is fixed ( |
|
Shorthand for all background properties. |
Color Formats: |
|
Layout & Positioning
Display & Positioning
|
Starts on a new line, takes full width. |
|
Does not start on new line, takes width based on content, cannot set |
|
Does not start on new line, takes width based on content, CAN set |
|
Element is completely removed from the layout. |
|
Default positioning; element is positioned according to normal flow. |
|
Positioned relative to its normal position. |
|
Positioned relative to its nearest positioned ancestor (instead of the viewport). Removed from normal flow. |
|
Positioned relative to the viewport. Stays in place even when scrolling. Removed from normal flow. |
|
Positioned based on the user’s scroll position. Behaves like |
|
Used with |
|
Specifies the stack order of a positioned element (higher number is higher in stack). |
Flexbox (Container)
|
Makes the element a flex container, its direct children become flex items. |
|
Defines the direction of flex items ( |
|
Specifies if flex items should wrap ( |
|
Aligns items along the main axis ( |
|
Aligns items along the cross axis ( |
|
Aligns flex lines when there’s extra space in cross axis (only if |
|
Sets the gaps (gutters) between rows and columns in flex and grid layouts. |
Tips: |
Flexbox is great for 1D layouts (row or column). Use for navbars, centering items, distributing space. |
Flexbox (Items)
|
Specifies the order of a flex item ( |
|
Specifies how much a flex item will grow relative to the rest ( |
|
Specifies how much a flex item will shrink relative to the rest ( |
|
Specifies the initial size of a flex item before flexing ( |
|
Shorthand for |
|
Aligns the individual flex item along the cross axis (overrides |
CSS Grid (Container)
|
Makes the element a grid container, its direct children become grid items. |
|
Defines the columns in the grid ( |
|
Defines the rows in the grid. Example: |
|
Defines grid layout using named areas. Example: |
|
Sets the gaps between grid rows and columns. |
|
Aligns items inside grid cells along the inline (row) axis ( |
|
Aligns items inside grid cells along the block (column) axis ( |
|
Aligns the grid itself along the inline axis inside the container ( |
|
Aligns the grid itself along the block axis inside the container ( |
|
Specifies the size of implicitly created columns. |
|
Specifies the size of implicitly created rows. |
Tips: |
Grid is powerful for 2D layouts (rows and columns simultaneously). Use for page layouts, complex components. |
CSS Grid (Items)
|
Assigns an item to a named grid area, or specifies its position using row/column start/end lines. |
|
Specifies which column lines the item starts and ends at ( |
|
Specifies which row lines the item starts and ends at ( |
|
Shorthand for |
|
Shorthand for |
|
Aligns the individual grid item inside its cell along the inline axis (overrides |
|
Aligns the individual grid item inside its cell along the block axis (overrides |
Floats & Clearing
|
Element floats to the left within its container. Text and inline elements wrap around it. |
|
Element floats to the right within its container. |
|
Element does not float (default). |
|
Element moves below any floated elements on its left side. |
|
Element moves below any floated elements on its right side. |
|
Element moves below any floated elements on both sides. |
The “clearfix” hack: |
|
Typography & Advanced Styling
Fonts
|
Specifies the font(s) to use (comma-separated, with generic fallback). |
|
Sets the size of the text ( |
|
Sets how thick or thin characters are ( |
|
Sets the style of the font ( |
|
Sets whether or not text should be displayed in a small-caps font ( |
|
Sets the spacing between lines ( |
|
Shorthand for |
|
Rule for defining custom fonts to load. |
Text Styling & Effects
|
Aligns the text inside its container ( |
|
Adds decoration lines ( |
|
Controls the capitalization of text ( |
|
Specifies the indentation of the first line of text. |
|
Increases or decreases the space between characters. |
|
Increases or decreases the space between words. |
|
Controls how whitespace is handled ( |
|
Adds shadow to text ( |
|
|
Lists & Tables
|
Sets the type of list item marker ( |
|
Sets an image as the list item marker ( |
|
Specifies the position of the list item marker ( |
|
Shorthand for all list style properties. |
|
Specifies if table borders should be collapsed into a single border ( |
|
Specifies the distance between the borders of adjacent cells (when |
|
Specifies the position of the table caption ( |
|
Shows or hides borders and background on empty cells in a table ( |
|
Common reset for lists and basic table styling. |
Units
Absolute Units (Physical Size) |
|
Relative Units (Relative to Parent/Viewport/Root) |
|
Viewport Units (Relative to Viewport Size) |
|
Flex/Grid Units |
|
Function Units |
|
|
|
Best Practice: |
Use |
Custom Properties (Variables)
Define a custom property (variable) in a selector. |
|
Use a custom property. |
|
|
|
Tips: |
Makes CSS more maintainable. Useful for themes, consistent spacing, colors, etc. Can be updated dynamically with JavaScript. |
Responsive Design & Interaction
Media Queries
Apply styles only when the screen width is 600px or less. |
Apply styles only when printing the page. |
Common Media Features:
|
Logical Operators:
|
|
Tips:
|
Transitions
|
Specifies the CSS property to transition ( |
|
Specifies how long the transition will take ( |
|
Specifies the speed curve of the transition ( |
|
Specifies a delay before the transition starts ( |
|
Shorthand for all transition properties (e.g., |
|
|
Tips: |
Transition properties that browsers can animate efficiently ( |
Transformations (2D)
|
Moves an element from its current position. |
|
Moves an element horizontally. |
|
Moves an element vertically. |
|
Rotates an element ( |
|
Changes the size of an element (1 is original size). |
|
Changes the width of an element. |
|
Changes the height of an element. |
|
Skews an element along the X and Y axes. |
|
Specifies the point around which a transform is performed (default is |
Other Useful Properties
|
Sets the transparency level of an element (0 is fully transparent, 1 is fully opaque). |
|
Adds shadow to an element’s box ( |
|
Adds rounded corners to an element. |
|
Draws an outline around an element (outside the border). Use |
|
Specifies the mouse cursor to be displayed ( |
|
Hides or shows an element without affecting layout ( |
|
Specifies how to handle content that overflows an element’s box ( |
|
Controls whether an element can be the target of mouse events ( |