Catalog / CSS Cheatsheet
CSS Cheatsheet
A comprehensive CSS cheat sheet covering selectors, properties, units, and more, with practical examples for quick reference.
Selectors & Specificity
Basic Selectors
|
Selects all elements.
|
|
Selects all elements of the given type.
|
|
Selects all elements with the given class.
|
|
Selects the element with the given ID. IDs should be unique within a document.
|
Combinators
|
Selects all B elements that are descendants of A.
|
|
Selects all B elements that are direct children of A.
|
|
Selects the first B element that immediately follows A.
|
|
Selects all B elements that are siblings of A (A and B share the same parent).
|
Attribute Selectors
|
Selects elements with the specified attribute.
|
|
Selects elements with the specified attribute and value.
|
|
Selects elements with the specified attribute containing the value.
|
|
Selects elements with the specified attribute starting with the value.
|
|
Selects elements with the specified attribute ending with the value.
|
Properties
Text Properties
|
Sets the color of the text.
|
|
Specifies the font family for the text.
|
|
Sets the size of the text.
|
|
Sets the line height of the text.
|
|
Specifies the horizontal alignment of the text.
|
Box Model Properties
|
Sets the margin around an element. Can be one value (all sides), two values (top/bottom, left/right), or four values (top, right, bottom, left).
|
|
Sets the padding inside an element. Can be one, two, or four values like margin.
|
|
Sets the border around an element. Shorthand for
|
|
Sets the width of an element.
|
|
Sets the height of an element.
|
Background Properties
|
Sets the background color of an element.
|
|
Sets the background image of an element.
|
|
Specifies how the background image is repeated.
|
|
Specifies the position of the background image.
|
Units & Values
Absolute Length Units
|
Relative to the viewing device.
|
|
1pt is equal to 1/72 of an inch.
|
|
1pc is equal to 12 points.
|
|
Specifies length in inches.
|
|
Specifies length in centimeters.
|
|
Specifies length in millimeters.
|
Relative Length Units
|
Relative to the font size of the element. E.g., if the element’s font size is 16px, then
|
|
Relative to the font size of the root element (html).
|
|
Relative to 1% of the viewport’s height.
|
|
Relative to 1% of the viewport’s width.
|
|
Percentage of the parent element.
|
Color Values
|
Using hex codes (e.g.,
|
|
Using
|
|
Using
|
|
Using
|
|
Using
|
Layout
Display Property
|
The element behaves like a block-level element; it takes up the full width available and starts a new line.
|
|
The element behaves like an inline element; it only takes up as much width as necessary.
|
|
The element is formatted as an inline element, but you can set a width and height.
|
|
The element is displayed as a block-level flex container.
|
|
The element is displayed as a block-level grid container.
|
|
The element is completely removed from the document.
|
Flexbox Properties
|
Specifies the direction of the flexible items inside a flex container.
|
|
Aligns the flexible items when the items do not use all available space on the main axis.
|
|
Aligns the flexible items when the items do not use all available space on the cross axis.
|
|
A shorthand property for
|
Grid Layout Properties
|
Defines the number and size of columns in a grid layout.
|
|
Defines the number and size of rows in a grid layout.
|
|
Specifies the size of the gap between rows and columns in a grid layout.
|
|
Specifies a grid item’s size and location in a grid layout.
|
|
Specifies a grid item’s size and location in a grid layout.
|