Learn the Basics of CSS and How it Works
Tags: css, frontend, tutorial
Published: 2023-07-15 13:52:02

CSS, short for Cascading Style Sheets, is an essential part of web development that allows you to control the visual appearance of your web pages.

## In this CSS beginner's guide, I will explore the fundamental concepts:
[1. What is CSS?](#chapter-1)
[2. CSS vs. CSS3. How do they differ?](#chapter-2)
[3. Is there a CSS2?](#chapter-3)
[4. Is CSS a programming language?](#chapter-4)
[5. Who should learn CSS?](#chapter-5)
[6. How CSS works?](#chapter-6)

--------------------------------

### 1. What is CSS? <a name="chapter-1"></a>
![What is CSS?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj02q2d9clm5lg528i82.png)
CSS is a language used to describe the presentation and styling of HTML documents. With it, you can define the styles of HTML elements, such as **colors**, **fonts**, **sizes**, and spacings. CSS achieves this by using **selectors**, **properties**, and **values**.

**Selectors** target specific HTML elements that you want to style, and they can be based on element types (`<h1>`, `<p>`, `<div>`), class names (`.class-name`), IDs (`#an-id`), or other attributes.

**Properties** represent the aspects or characteristics of element styles that you want to modify. such as `color`, `font-size`, `background-color`, and `margin`.

**Values** are assigned to properties and define how the selected elements should appear. For instance, the value of the `color` property can be `blue`, and the value of the `font-size` can be `18px`.

By combining these three parts, you create CSS **rules** that instruct the browser on how to style elements. **Here's an example:**
```
h1 { /* The Selector */
  color /* The Property */: blue  /* The Value*/;
  font-size: 18px;
}
```

### 2. CSS vs. CSS3. How do they differ? <a name="chapter-2"></a>
![CSS vs. CSS3. How do they differ?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ksqlyivgad5lvkfsk9l.png)
**CSS3** is an updated version of CSS that introduces new and improved features for web styling.

With CSS3, you can achieve advanced effects like gradients, shadows, and animations. These enhancements provide greater flexibility and creative possibilities for designing modern and creative websites.

CSS, on the other hand, refers to the earlier versions of CSS before CSS3. While CSS3 has become the most popular and widely used version of CSS, understanding the basic concepts of CSS is still essential as it forms the foundation for CSS3.

### 3. Is there a CSS2? <a name="chapter-3"></a>
![Is there a CSS2?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lkof8nfbvoim1y68t260.png)
**Yes**, there is a CSS2. It is a previous version of CSS that expanded the capabilities of CSS.
CSS2 introduced important features like positioning, floats, and advanced selectors, which have influenced the development of CSS3.
Although CSS2 has been largely replaced by CSS3, understanding its concepts is still valuable for maintaining and updating older web projects.

### 4. Is CSS a programming language? <a name="chapter-4"></a>
![Is CSS a programming language?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bd8jcueh63jkk5j0czva.png)
It's important to clarify that CSS is a styling language, not a programming language.
While programming languages involve logic and calculations, CSS focuses solely on the visual presentation of web elements. CSS complements HTML by specifying how elements should appear on the screen.


### 5. Who should learn CSS? <a name="chapter-5"></a>
![Who should learn CSS?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v881wx4iwddmb2q82tmu.png)
CSS is a crucial skill for web developers and designers. By learning CSS, you gain the ability to customize the visual aspects of web pages and create engaging user experiences.

If you're involved in front-end development or want to design and develop web pages, learning CSS is a must.


### 6. How CSS works? <a name="chapter-6"></a>
![How CSS works?](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g70z0nobycm9wfm4i2st.png)
Understanding how CSS works allows you to optimize your stylesheets and make informed decisions when it comes to styling and layout. **Here is the process of how CSS works:**

**1. HTML Parsing & Loading:** The browser parses the HTML document, creating a structured representation known as the Document Object Model (DOM).
This step sets up the basic structure of the web page, including elements and their relationships.

**2. CSS Loading:** The browser loads external CSS files referenced in the HTML document, as well as any embedded or inline styles.
These CSS files contain the instructions for styling the HTML elements.

**3. CSS Parsing:** The browser interprets the CSS code, ensuring its syntax is correct and valid.
The parsed CSS is then transformed into a structured representation known as the CSS Object Model (CSSOM), which the browser can understand.
This representation organizes the CSS rules and properties.

**4. CSS Rule Matching:** Once the CSS rules are matched with the HTML elements, the browser combines the DOM structure, CSS styles, and any additional rendering instructions to generate the final layout of the web page.
The browser calculates the size, position, and appearance of each element, taking into account the CSS properties specified.

**5. Rendering:** After matching the CSS rules with the HTML elements, the browser proceeds to render the web page.
It combines the DOM structure, CSS styles, and any additional rendering instructions to generate the final layout.
This process includes calculating the size, position, and appearance of each element, including margins, paddings, borders, and backgrounds.

**6. Viewing:** Once the rendering is complete, the fully styled web page is displayed on the screen, allowing users to view and interact with it.
At this stage, users can experience the visual design, interact with interactive elements, and explore the functionality provided by the web page.

-----------------------------

**In conclusion**, CSS is an essential language for web developers and designers, allowing them to control the visual appearance of web pages.
It provides the ability to style HTML elements using selectors, properties, and values.

**And remember that,** _CSS is not a programming language but focuses on styling rather than functionality._