CSS (Cascading Style Sheets) is the language used to style the visual presentation of web pages.
It works alongside HTML, which provides structure, while CSS controls color, layout, and typography.
- CSS separates content from presentation.
- One stylesheet can style many pages.
A selector targets the HTML elements you want to style.
You can select by tag, class, id, or attribute.
p { color: navy; }
.button { padding: 8px; }
- Tag selectors target every element of a type.
- Class selectors are reusable.
Every element is a rectangular box made of content, padding, border, and margin.
div { padding: 16px; border: 1px solid; }
Understanding the box model is key to controlling spacing.
The position property controls how an element sits in the document flow.
.box { position: absolute; }
Values include static, relative, absolute, fixed, and sticky.
Responsive design lets one site adapt to any screen size.
@media (min-width: 768px) { }
Media queries apply styles based on the device.
- Use relative units for fluid layouts.