AI Generate CSS docs instantly

CSS Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

5 snippets

Basic CSS syntax and selectors

Element Selector

p { color: blue; }

Class Selector

.class-name { font-size: 16px; }

ID Selector

#unique-id { background: red; }

Universal Selector

* { margin: 0; padding: 0; }

Comment

/* This is a comment */

Selectors

7 snippets

Target specific elements

Descendant

div p { color: blue; }

Child

div > p { color: blue; }

Adjacent Sibling

h1 + p { margin-top: 0; }

General Sibling

h1 ~ p { color: gray; }

Attribute

a[href] { color: blue; }
input[type="text"] { border: 1px solid; }

Pseudo-class

a:hover { text-decoration: underline; }
li:first-child { font-weight: bold; }

Pseudo-element

p::first-line { font-weight: bold; }
p::before { content: "→ "; }

Colors

6 snippets

Different ways to define colors

Named Colors

color: red;
background: blue;

Hex

color: #ff0000;
background: #00f;

RGB

color: rgb(255, 0, 0);
background: rgb(0, 0, 255);

RGBA

background: rgba(255, 0, 0, 0.5);

HSL

color: hsl(0, 100%, 50%);

HSLA

background: hsla(240, 100%, 50%, 0.5);

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Flexbox

9 snippets

Modern flexible box layout

Container Setup

display: flex;
display: inline-flex;

Direction

flex-direction: row;
flex-direction: row-reverse;
flex-direction: column;
flex-direction: column-reverse;

Justify Content

justify-content: flex-start;
justify-content: flex-end;
justify-content: center;
justify-content: space-between;
justify-content: space-around;
justify-content: space-evenly;

Align Items

align-items: stretch;
align-items: flex-start;
align-items: flex-end;
align-items: center;
align-items: baseline;

Flex Wrap

flex-wrap: nowrap;
flex-wrap: wrap;
flex-wrap: wrap-reverse;

Gap

gap: 1rem;
row-gap: 1rem;
column-gap: 2rem;

Flex Item

flex: 1;
flex: 0 1 auto;
flex-grow: 1;
flex-shrink: 0;
flex-basis: 200px;

Align Self

align-self: auto;
align-self: flex-start;
align-self: flex-end;
align-self: center;
align-self: stretch;

Order

order: 0;
order: 1;
order: -1;

Layout

6 snippets

Positioning and display

Display

display: block;
display: inline;
display: inline-block;
display: none;

Position

position: static;
position: relative;
position: absolute;
position: fixed;
position: sticky;

Float

float: left;
float: right;
float: none;
clear: both;

Z-Index

z-index: 1;
z-index: 999;
z-index: -1;

Grid Container

display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1rem;
grid-template-rows: auto;

Grid Item

grid-column: 1 / 3;
grid-row: 1 / 2;
grid-area: header;

Box Model

5 snippets

Spacing and sizing

Margin

margin: 10px;
margin: 10px 20px;
margin: 10px 20px 10px 20px;
margin-top: 10px;

Padding

padding: 10px;
padding: 10px 20px;
padding-left: 15px;

Border

border: 1px solid black;
border-radius: 5px;
border-top: 2px dashed red;

Width & Height

width: 100px;
height: 50px;
min-width: 200px;
max-width: 100%;

Box Sizing

box-sizing: content-box;
box-sizing: border-box;

Typography

6 snippets

Text styling

Font Family

font-family: Arial, sans-serif;
font-family: 'Times New Roman', serif;

Font Size

font-size: 16px;
font-size: 1.2rem;
font-size: 150%;

Font Weight

font-weight: normal;
font-weight: bold;
font-weight: 700;

Text Align

text-align: left;
text-align: center;
text-align: right;
text-align: justify;

Text Decoration

text-decoration: none;
text-decoration: underline;
text-decoration: line-through;

Line Height

line-height: 1.5;
line-height: 24px;

More Cheat Sheets

FAQ

Frequently asked questions

What is a CSS cheat sheet?

A CSS cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in CSS. It helps developers quickly look up syntax without searching through documentation.

How do I learn CSS quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important CSS concepts?

Key CSS concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my CSS code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your CSS code using AI.

Code Conversion Tools

Convert CSS to Other Languages

Easily translate your CSS code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate CSS Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week