Getting Started
5 snippetsBasic 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 snippetsTarget 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 snippetsDifferent 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.
Flexbox
9 snippetsModern 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 snippetsPositioning 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 snippetsSpacing 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 snippetsText 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;