DEV Community

Cover image for Learn the Basics of CSS and How it Works
khaled Alshibani - FE dev
khaled Alshibani - FE dev

Posted on

Learn the Basics of CSS and How it Works

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?
2. CSS vs. CSS3. How do they differ?
3. Is there a CSS2?
4. Is CSS a programming language?
5. Who should learn CSS?
6. How CSS works?


1. What is CSS?

What is CSS?
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;
}
Enter fullscreen mode Exit fullscreen mode

2. CSS vs. CSS3. How do they differ?

CSS vs. CSS3. How do they differ?
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?

Is there a CSS2?
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?

Is CSS a programming language?
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?

Who should learn CSS?
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?

How CSS works?
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.

Top comments (0)