My Tech Blog

CSS Basics

Published on September 17, 2025

Welcome to the CSS Basics tutorial! In this post, we'll cover the fundamental concepts you need to start styling web pages.

What is CSS?

CSS (Cascading Style Sheets) is a language used to describe the presentation of a document written in HTML or XML. It controls layout, colors, fonts, and more.

Applying CSS

There are three ways to apply CSS to an HTML document:

Example: Inline vs External

// Inline style
<h1 style="color: #3b82f6;">Hello World</h1>

// External stylesheet (styles.css)
h1 {
    color: #3b82f6;
}

Selectors

Selectors target the HTML elements you want to style. Common selectors include:

Box Model

Every element is a rectangular box consisting of:

Visualization

+-----------------------+
|       Margin          |
| +-------------------+ |
| |     Border        | |
| | +---------------+ | |
| | |   Padding    | | |
| | | +-----------+ | | |
| | | | Content   | | | |
| | | +-----------+ | | |
| | +---------------+ | |
| +-------------------+ |
+-----------------------+

Next Steps

Now that you understand the basics, try experimenting with:

Happy styling!