Learn CSS from Start to Finish – Part 01

CSS is the language for styling HTML. It is supported in all browsers and stands for Cascading Style Sheets. Without CSS, every website would look like a plain black-and-white text document. With it, you control colors, fonts, spacing, layouts, and responsive mobile designs.

Styling using CSS comes down to two simple steps: 1. Select the HTML element you want to change, and 2. Style it with properties and values.

The Anatomy of a CSS Rule

Every CSS rule follows this basic pattern:

/* 1. Select the element */
h1 {
  /* 2. Style it with property: value pairs */
  color: #2563eb;
  font-size: 36px;
  text-align: center;
}

3 Ways to Select Elements

  1. Element Selector: Targets all tags of a specific type (e.g., p { ... } styles every paragraph).
  2. Class Selector: Targets any element with a matching class attribute using a dot (e.g., .btn-primary { ... }). You can reuse classes across multiple elements.
  3. ID Selector: Targets one unique element with a matching id attribute using a hash (e.g., #main-header { ... }).

How to Connect CSS to HTML

The cleanest way to use CSS is by creating a separate style.css file and linking it inside the <head> of your HTML document:

<head>
  <link rel="stylesheet" href="style.css">
</head>

In Part 02, we will explore the CSS Box Model, spacing (margin and padding), and how to position elements on the page.

Share your love