Logo ASILTECHSOFTBY ÜNAL
Blog CSS

CSS Fundamentals: From Basics to Practice

CSS Fundamentals: From Basics to Practice

What is CSS and Why is it Needed?

Building a web page without CSS is like laying bricks without mortar. HTML delivers the content, CSS beautifies and organizes it. Everything you see on a web page — colors, sizes, positions, animations — that's all CSS's work.

Speaking from 10+ years of experience in software development: a developer who learns CSS fundamentals correctly will progress much faster down the road. The transformation from an ordinary web page to a flawless design starts with CSS.

Selector: The Language CSS Speaks

A selector is the pattern you use to select HTML elements. For example:

p { color: blue; }

This colors all <p> tags blue. But what if you want to color only a specific paragraph?

  • Class selector: .heading { color: red; } — selects elements with class="heading" in HTML
  • ID selector: #menu { background: gray; } — selects the element with id="menu" in HTML
  • Attribute selector: input[type="email"] { border: 2px solid blue; } — selects elements with a specific attribute

When managing a project in the studio, I mostly use classes. IDs are rarely needed, and I try to avoid global style rules. Keeping code modular is healthier.

Cascade and Specificity: The Hierarchy of Rules

Where does the "Cascading" in CSS come from? Rules flow downward — the rule at the bottom is applied last. But if two rules have different specificity, the more specific one wins.

Specificity is calculated like this:

  • Element selector (p, div): 1 point
  • Class selector (.heading): 10 points
  • ID selector (#menu): 100 points
  • Inline style (style attribute in HTML): 1000 points

Example:

p { color: blue; }        /* 1 point */
.text { color: red; }     /* 10 points — this wins */
#main { color: green; }   /* 100 points — this wins most */

From experience: getting into specificity wars is tedious. Good organization solves most problems beforehand. I usually save IDs for JavaScript, rarely using them for styling.

Box Model: The Architecture of the Page

Every HTML element is actually a box. It consists of four layers from inside to outside:

  • Content: The area where text, images, etc. are located
  • Padding: The space between content and border
  • Border: The frame of the box
  • Margin: The distance the box keeps from other elements

In practice it looks like this:

.card {
  width: 300px;
  padding: 20px;
  border: 1px solid #ccc;
  margin: 10px;
}

It seems confusing at first, but once you draw it on paper, things become clear. I always recommend to new developers: learn the box model visually, not through formulas.

Extra Tips: What Worked for Me in Practice

My approach to learning CSS: less theory, more practice. When you adapt a page's design and write it yourself, that's when you understand. Open the browser's developer tools (F12), select elements, change styles live. Fear of making mistakes is pointless; CSS doesn't break anything.

Before moving on to modern layout tools like CSS Flexbox and Grid, understand the Box Model well. Otherwise, advanced topics get confusing.

Conclusion

CSS fundamentals — selectors, cascade, specificity, box model — once you sit down and learn them properly, the rest follows naturally. Be patient, reinforce it over weeks, apply it in real projects. By the time you finish this article, tomorrow's CSS users will be moving around comfortably.

Ünal Kaya
Ünal Kaya Asil Tech Soft · Software & Hardware Developer About
Get new posts by email

A few posts a month; no spam, unsubscribe in one click.

Your email is used only to send you new posts. Privacy notice

More Posts

All →
Can — Assistant