CheatsheetCss
CSS Cheatsheet
A quick CSS reference you can scan in a few minutes.

π Basic Syntaxπ― CSS Selectorsπ UnitsποΈ Font Propertiesπ Text Propertiesπ List Stylingπ PositionπΌοΈ Background Propertiesπ¦ Box Model & Propertiesβ‘ Transitionsπ¬ Animationsπ 2D Transformsπ 3D TransformsποΈ CSS Variables (Custom Properties)π«οΈ Filter & Backdrop FilterβοΈ Clip-Path Examplesπ FlexboxπΈοΈ Gridπ¨ Colorsπ± Media QueriesβοΈ Misc Propertiesπ Best Practicesπ Resources
CSS Cheatsheet
The CSS I keep looking up: selectors, units, layout with flexbox and grid, and a few modern properties. Skim it when you forget something.
π Basic Syntax
Snippet
selector {
property: value;
}π― CSS Selectors
*β Universal selectorelementβ All elements of that type (p,h1).classβ Class selector#idβ ID selectorelement.classβ Type + classparent childβ Descendant selectorparent > childβ Direct childelement + siblingβ Adjacent sibling[attr=value]β Attribute selectorelement:hover,:focus,:activeelement:first-child,:last-child,:nth-child(n)element::before,::afterβ Pseudo-elements
π Units
- Absolute:
px,cm,mm,in - Relative:
%,em,rem - Viewport:
vh,vw - Fractional:
fr(Grid) - Time:
s,ms
ποΈ Font Properties
Snippet
font-family: Arial, sans-serif;
font-size: 16px;
font-style: italic;
font-weight: bold;
line-height: 1.5;
letter-spacing: 2px;π Text Properties
Snippet
text-align: left | center | right | justify;
text-transform: uppercase | lowercase | capitalize;
text-decoration: underline | none | line-through;
text-shadow: 1px 1px 2px gray;
white-space: nowrap | normal;
word-break: break-word;π List Styling
Snippet
list-style-type: disc | circle | square | none;
list-style-position: inside | outside;
list-style-image: url('bullet.png');π Position
Snippet
position: static | relative | absolute | fixed | sticky;
top, right, bottom, left: values;
z-index: 100;πΌοΈ Background Properties
Snippet
background-color: #f0f0f0;
background-image: url('image.jpg');
background-size: cover | contain;
background-position: center | top right;
background-repeat: no-repeat | repeat-x | repeat-y;
background-clip: border-box | padding-box | content-box;
background-attachment: fixed | scroll;π¦ Box Model & Properties
Snippet
width, height: values;
max-width, min-height: values;
padding, margin: values;
border: 2px solid #333;
border-radius: 8px;
box-sizing: border-box;
box-shadow: 2px 2px 10px rgba(0,0,0,0.2);β‘ Transitions
Snippet
transition-property: none | all | color | background | transform;
transition-duration: 0.3s | 500ms;
transition-timing-function: ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(n,n,n,n);
transition-delay: 0s | 200ms;
transition: property duration timing-function delay;π¬ Animations
Snippet
animation-name: slideIn | none;
animation-duration: 1s;
animation-timing-function: ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(n,n,n,n);
animation-delay: 0s;
animation-iteration-count: 1 | infinite | number;
animation-direction: normal | alternate;
animation-fill-mode: none | forwards | backwards | both;
animation-play-state: running | paused;
@keyframes slideIn {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
.element {
animation: slideIn 1s ease-in-out 0s infinite alternate;
}Shorthand:
Snippet
animation: name duration timing-function delay iteration-count direction;π 2D Transforms
Snippet
transform: translate(x, y); /* Move element */
transform: rotate(angle); /* Rotate element */
transform: scale(x, y); /* Scale element */
transform: skew(x-angle, y-angle); /* Skew element */
transform: skewX(angle); /* Skew along X-axis */
transform: skewY(angle); /* Skew along Y-axis */π 3D Transforms
Snippet
transform: translate3d(x, y, z); /* Move element in 3D */
transform: rotateX(angle); /* Rotate around X-axis */
transform: rotateY(angle); /* Rotate around Y-axis */
transform: rotateZ(angle); /* Rotate around Z-axis */
transform: scale3d(x, y, z); /* Scale in 3D */
transform: perspective(value); /* Perspective view */ποΈ CSS Variables (Custom Properties)
Snippet
:root {
--main-color: #3498db;
--padding: 10px;
}
.box {
color: var(--main-color);
padding: var(--padding);
}
/* Fallback value */
color: var(--secondary-color, #333);π«οΈ Filter & Backdrop Filter
Snippet
filter: blur(5px) | brightness(1.2) | contrast(150%) | grayscale(100%) | sepia(80%) | hue-rotate(90deg);
backdrop-filter: blur(10px) | brightness(1.1) | saturate(120%);βοΈ Clip-Path Examples
Snippet
clip-path: circle(50%);
clip-path: ellipse(60% 40%);
clip-path: inset(10px 20px 30px 40px);
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);π Flexbox
Snippet
.container {
display: flex;
flex-direction: row | column;
justify-content: center | space-between | space-around | flex-start | flex-end;
align-items: center | flex-start | flex-end | stretch;
flex-wrap: nowrap | wrap;
gap: 10px;
}πΈοΈ Grid
Snippet
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto;
gap: 10px;
justify-items: center;
align-items: start;
}π¨ Colors
- Named:
red,blue - Hex:
#ff0000 - RGB:
rgb(255,0,0) - RGBA:
rgba(255,0,0,0.5) - HSL:
hsl(0, 100%, 50%)
π± Media Queries
Snippet
@media (max-width: 768px) {
body { background-color: lightblue; }
}βοΈ Misc Properties
Snippet
cursor: auto | default | pointer | move | text | wait | not-allowed | grab | grabbing;
opacity: 0.8;
overflow: visible | hidden | auto | scroll;
object-fit: fill | contain | cover | none | scale-down;π Best Practices
- Use classes for reusable styles.
- Use external
.cssfiles. - Prefer
remandemoverpxfor responsiveness. - Use Flexbox and Grid for modern layouts.
- Utilize CSS variables for consistency.
π Resources
- MDN CSS Reference
- CSS Tricks
- Can I Use
- W3C CSS Validation Service
- Flexbox Guide - CSS Tricks
- Grid Guide - CSS Tricks
TIP
Use browser dev tools for live CSS editing.

Written by
Imtiyaz Nandasaniya
I'm a full-stack developer from Ahmedabad. I post what I learn about code on Instagram as code.clash, in the simplest language I can.
Subscribe to code.clash.
I will email you when I publish a new post. No spam, and you can unsubscribe whenever.
Related Writing.

APIOct 5, 20258M READ
Free APIs Every Developer Should Know
A list of 25+ free APIs for learning, side projects and trying out ideas.

CheatsheetAug 3, 20258M READ
ReactJS Cheatsheet
JSX, components, hooks, state and performance tips, plus the newer React 18 features.

CheatsheetJul 23, 20256M READ
JavaScript Cheatsheet
Core JavaScript in one page: ES6 features, data types, functions, the event loop and DOM basics.
Comments (0)
Leave a Comment
No account needed. Anonymous comments are welcome.