Codeloft
0 0 XP

CSS reference

Short entries with an example for each. When you need every detail, each entry links to the official documentation.

CSS

font-size and font-family

Set the size and typeface of text. Always end the font list with a generic family.

p { font-size: 20px; font-family: Georgia, serif; }

Class and id selectors

A dot selects a class, a # selects an id.

.note { color: gray; }
#top { color: crimson; }

background

Sets the background color or image of an element.

.hero { background: #fef3c7; padding: 20px; }

padding

Space inside an element's border.

.card { padding: 20px; background: #eef2ff; }

margin

Space outside an element's border.

.card { margin: 24px; background: #eef2ff; }

border and border-radius

Draw a line around a box and round its corners.

.card { border: 2px solid navy; border-radius: 12px; padding: 12px; }

display: flex

Lays out an element's children in a row (or a column).

.row { display: flex; gap: 12px; }

display: grid

Places children in rows and columns.

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

gap

Space between the items in a flex or grid container.

.row { display: flex; gap: 24px; }

@media

Applies styles only when the screen matches a condition, such as a narrow width.

@media (max-width: 600px) {
  body { background: lightyellow; }
}

:hover

Matches an element while the mouse pointer is over it.

a:hover { color: crimson; }

transition

Animates a change in a property over time.

.btn { transition: transform 0.3s; }
.btn:hover { transform: scale(1.2); }