CSS Reference
Essential CSS properties and selectors for beginners and web developers.
Text & Fonts
color
Changes text color.
color: red;font-size
Changes text size.
font-size: 24px;font-family
Sets font style.
font-family: Arial;font-weight
Makes text bold.
font-weight: bold;font-style
Makes text italic.
font-style: italic;text-align
Aligns text.
text-align: center;text-decoration
Adds underline or removes links underline.
text-decoration: none;line-height
Controls line spacing.
line-height: 1.5;letter-spacing
Changes spacing between letters.
letter-spacing: 2px;text-transform
Uppercase or lowercase text.
text-transform: uppercase;Backgrounds & Colors
background
Sets background color or image.
background: blue;background-color
Background color.
background-color: black;background-image
Adds background image.
background-image: url(image.jpg);background-size
Controls image size.
background-size: cover;background-position
Moves background image.
background-position: center;opacity
Changes transparency.
opacity: 0.5;Spacing
margin
Outer spacing.
margin: 20px;padding
Inner spacing.
padding: 20px;margin-top
Top margin.
margin-top: 10px;padding-left
Left padding.
padding-left: 15px;gap
Space between grid/flex items.
gap: 20px;Sizing
width
Element width.
width: 300px;height
Element height.
height: 200px;max-width
Maximum width.
max-width: 100%;min-height
Minimum height.
min-height: 100vh;Borders & Effects
border
Adds border.
border: 1px solid black;border-radius
Rounded corners.
border-radius: 10px;box-shadow
Adds shadow.
box-shadow: 0 0 10px gray;outline
Outline around element.
outline: 2px solid blue;Display & Layout
display
Controls layout type.
display: flex;display: block
Block element.
display: block;display: inline
Inline element.
display: inline;display: grid
Grid layout.
display: grid;overflow
Controls overflow content.
overflow: hidden;Flexbox
flex-direction
Row or column layout.
flex-direction: column;justify-content
Horizontal alignment.
justify-content: center;align-items
Vertical alignment.
align-items: center;flex-wrap
Wrap flex items.
flex-wrap: wrap;flex-grow
Grow flex item.
flex-grow: 1;Positioning
position
Sets positioning mode.
position: absolute;top
Moves element down.
top: 20px;left
Moves element right.
left: 50px;z-index
Controls layer order.
z-index: 10;CSS Grid
grid-template-columns
Creates grid columns.
grid-template-columns: 1fr 1fr;grid-template-rows
Creates grid rows.
grid-template-rows: auto;place-items
Centers grid items.
place-items: center;Transitions & Animation
transition
Smooth animation effect.
transition: 0.3s;transform
Moves or scales element.
transform: scale(1.2);animation
Runs CSS animation.
animation: fade 2s;@keyframes
Defines animation.
@keyframes fade {}Selectors
.class
Selects class.
.box {}#id
Selects ID.
#header {}*
Selects everything.
* { margin:0; }:hover
Mouse hover effect.
button:hover {}:focus
Focused input style.
input:focus {}::before
Adds content before element.
::before {}::after
Adds content after element.
::after {}