🏠 Home›Cheatsheets›CSS

🎨 CSS Cheatsheet

Common CSS properties and selectors

Selectors

Element Selector

p

Targets all <p> elements

p { color: blue; }

Selectors

Class Selector

.classname

Targets elements with class

.highlight { background: yellow; }

Selectors

ID Selector

#idname

Targets element with ID

#header { height: 100px; }

Selectors

Attribute Selector

[attribute]

Targets elements by attribute

input[type="text"] { width: 200px; }

Selectors

Pseudo-class

:hover, :active, :focus

Element state selectors

a:hover { color: red; }

Display

Display Flex

display: flex

Flexbox layout

.container { display: flex; gap: 10px; }

Display

Display Grid

display: grid

CSS Grid layout

.grid { display: grid; grid-template-columns: 1fr 1fr; }

Box Model

Margin

margin: 10px

Outer spacing

.box { margin: 20px auto; }

Box Model

Padding

padding: 10px

Inner spacing

.box { padding: 15px 20px; }

Box Model

Border

border: 1px solid

Border styling

.box { border: 2px solid #333; border-radius: 8px; }

Text

Font Size

font-size: 16px

Text size (px, em, rem)

p { font-size: 14px; }

Text

Font Weight

font-weight: 600

400, 600, 700, bold, normal

strong { font-weight: 700; }

Text

Text Align

text-align: center

left, center, right, justify

.heading { text-align: center; }

Text

Line Height

line-height: 1.5

Line spacing (number, px, em)

body { line-height: 1.6; }

Colors

Color

color: #333

Text color (hex, rgb, name)

p { color: #333; }

Colors

Background Color

background-color: #f9f9f9

Background (hex, rgb, name)

.box { background-color: #f0f0f0; }

Effects

Box Shadow

box-shadow: 0 2px 4px

Shadow effects

.card { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

Effects

Transform

transform: scale(1.1)

rotate, scale, translate, skew

.button:hover { transform: scale(1.05); }

Effects

Transition

transition: all 0.3s

Smooth animations

.button { transition: background 0.3s ease; }

Positioning

Position

position: relative

static, relative, absolute, fixed, sticky

.modal { position: fixed; top: 0; left: 0; }

More in this category

|🏠 Home|
|