Web Development
HTML Course
CSS Course
JavaScript Course
PHP Course
Python Course
SQL Course
SEO Course

CSS - Brief Introduction

What is CSS?

CSS stands for Cascading Style Sheet. This course is an introduction to the CSS styling language, and to follow it, you need to be familiar with the HTML markup language. CSS is used to create the design of web pages — for example, to change the font, color, size, and spacing of content, for animations, and other decorative presentation features.

How does CSS work?

When a browser displays a document, it needs to combine the content of the document with its styling information. The document is processed in two stages:

  1. The browser transforms HTML and CSS into the DOM (Document Object Model) and CSSOM (CSS Object Model), then combines the two structures in the computer's memory.
  2. The browser displays the DOM content.

How CSS works

The DOM has a tree-like structure. Each element, attribute, and text sequence in the markup language becomes a node in the DOM, forming the tree structure. Nodes are defined by their relationship to other DOM nodes. Some elements are parent elements, others are of course child elements, and child elements have siblings. Understanding the DOM helps you design, debug, and maintain CSS, because the DOM is where CSS and document content meet and work together.

Let’s see in the following example how HTML and CSS work together:

<p>
 Use:
 <span>Style</span>
 <span>Sheets</span>
 <span>Cascade</span>
</p>

In this small DOM, the p element is a parent. Its children are a text node "Use:" and the nodes corresponding to the span elements. The span nodes, which are siblings, are also parents themselves to the text they contain.

P
├─ "Use:"
├─ SPAN
|  └─ "Style"
├─ SPAN
|  └─ "Sheets"
└─ SPAN
   └─ "Cascade"

See the result below:

🔧 Unstyled DOM

Let’s see what happens after we add a bit of CSS to our document to change its appearance. We add:

span {
  border: 1px solid black;
  background-color: orange;
}

The browser will analyze the HTML code and create a DOM, then analyze the CSS and create a CSSOM. It combines the two structures into a final DOM that will be "painted" by the browser on the screen. Since there is a single rule applied to a single selector (), we will have three colored blocks, one for each piece of text contained in each span element in the DOM.

See the result below:

🔧 Styled DOM

Inserting CSS into an HTML Document

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

 <link rel="stylesheet" href="style.css">
<style>
span {
  border: 1px solid black;
  background-color: orange;
}
</style>
 <p style="color: blue; background-color: yellow; border: 1px solid black;">Inline CSS Example</p>

Using inline CSS should be avoided, except in situations where there is no other option, because structural information will be mixed with presentation information, making the HTML document very difficult to read and maintain.

You should use this method only when you don’t have access to the external CSS file.

Below you can see the three methods of inserting CSS into a document. Remove the comments to see exactly what happens.

🔧 CSS Insertion Methods

🧠 Final Quiz – CSS Introduction

Top