CSS Fundamentals
Take The Quiz
The properties you will use daily
You know how a rule is built. Here are the essential properties for colour, text, the box model and layout.
Common properties
| Property | What it controls | Example |
|---|---|---|
color | Text colour | color: #333; |
background | Background colour or image | background: #fff; |
font-size | Text size | font-size: 16px; |
margin | Space outside an element | margin: 16px; |
padding | Space inside an element | padding: 8px; |
The box model
Every element is a box: content, then padding, then border, then margin. Understanding this is the key to spacing and sizing.
.card {
padding: 16px; /* inside */
border: 1px solid #ddd;
margin: 12px; /* outside */
}Use box-sizing: border-box
It makes width include padding and border, so sizing stays predictable. Many projects set it globally: * { box-sizing: border-box; }
Modern layout: Flexbox
Flexbox arranges items in a row or column with easy alignment — ideal for navbars, cards and centring.
.row {
display: flex;
gap: 16px;
justify-content: space-between;
align-items: center;
}Avoid fixed pixels everywhere
Prefer relative units (rem, %, fr) and Flexbox/Grid so your layout adapts to any screen.
Frequently asked questions
What’s the difference between margin and padding?
Flexbox or Grid?
px, em or rem?
rem for font sizes and spacing (scales with the root font); use px only when you truly need a fixed size.