← Web design from scratch

What is CSS?

You already know how to use HTML to create the structure of a page. Now you will learn to use CSS to control its appearance and turn that structure into a design.

Level · Beginner Time · 20–25 min Path · Web design

01

What is CSS?

CSS stands for Cascading Style Sheets.

It is the language we use to control the visual appearance of HTML elements.

With CSS we can change colours, fonts, sizes, spacing, backgrounds, borders and the layout of elements on a page.

A simple way to understand it: HTML creates the page structure, while CSS determines how that structure looks.

02

HTML and CSS work together.

Imagine we have this heading in HTML:

<h1>Welcome to my website</h1>

Without CSS, the browser uses its default styles.

We can use CSS to change it:

h1 {
  font-size: 48px;
  text-align: center;
}

The content stays the same. Only its presentation changes.

03

How to write a CSS rule.

A basic CSS rule contains a selector, a property and a value.

p {
  font-size: 18px;
}
01

Selector

p identifies which HTML element we want to change.

02

Property

font-size identifies the characteristic we want to change.

03

Value

18px is the value we want to apply.

04

Create your styles.css file.

Return to the folder you created in the previous lesson:

my-first-website

It should already contain:

index.html

Now create a second file named:

styles.css

Your project will now contain two files:

my-first-website/
├── index.html
└── styles.css

05

Connect CSS to HTML.

Creating `styles.css` is not enough. We need to tell the HTML document to use that file.

Inside the <head> of `index.html`, add:

<link rel="stylesheet" href="styles.css">

The beginning of your document will look like this:

<head>
  <meta charset="UTF-8">
  <title>My first website</title>
  <link rel="stylesheet" href="styles.css">
</head>
If `index.html` and `styles.css` are in the same folder, `href="styles.css"` is enough.

06

Change the font and text size.

Open `styles.css` and write:

body {
  font-family: Arial, sans-serif;
}

h1 {
  font-size: 48px;
}

p {
  font-size: 18px;
  line-height: 1.7;
}

Save the file and refresh the page in your browser.

You should already notice a difference in appearance.

07

Add colours.

CSS also lets you control colours.

body {
  background: #f7f5f0;
  color: #222222;
}

In this example:

01

background changes the page background.

02

color changes the text colour.

08

Understand margin and padding.

Spacing is a fundamental part of web design.

MARGIN

Outer spacing.

Creates space around an element, separating it from other elements.

PADDING

Inner spacing.

Creates space between the content and the element's borders.

For example:

section {
  margin: 40px 0;
  padding: 60px 30px;
}

09

Style your first page.

Let's apply several styles together.

In `styles.css`, try:

body {
  margin: 0;
  padding: 60px 30px;
  font-family: Arial, sans-serif;
  background: #f7f5f0;
  color: #222222;
}

h1 {
  font-size: 48px;
  margin-bottom: 20px;
}

h2 {
  font-size: 30px;
  margin-top: 50px;
}

p {
  max-width: 650px;
  font-size: 18px;
  line-height: 1.7;
}

Save the file and reload `index.html`.

The HTML structure you created in the previous lesson should now look much more polished.

10

CSS does not change the meaning of content.

This is an important concept.

If an element is a main heading, it remains an h1 whether CSS makes it large, small, black or any other colour.

First, we must build a correct HTML structure. Then we use CSS to style it.

Do not choose HTML tags based on their appearance. Use them according to the meaning and structure of the content.

What you have learned.

  • CSS controls the appearance of HTML elements.
  • A CSS rule contains a selector, property and value.
  • Styles can be saved in `styles.css`.
  • HTML and CSS are connected using the link tag.
  • CSS can change fonts and sizes.
  • It can also control colours and backgrounds.
  • Margin creates outer spacing.
  • Padding creates inner spacing.
  • HTML defines the structure and CSS its presentation.

Style your first website.

Open the project you started in the previous lesson and make these changes:

  1. Create `styles.css`.
  2. Connect it to `index.html`.
  3. Change the page font.
  4. Change the background colour.
  5. Change the h1 size.
  6. Increase paragraph line spacing.
  7. Add padding to the body.

Then experiment with different values. The best way to start understanding CSS is to observe what happens when you change each property.

Do not aim for a perfect design yet. The goal is to understand the relationship between HTML and CSS. In the next lessons, we will build a more complete structure.

PREVIOUS LESSON

← 03 · What is HTML?