You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
CSS stands for Cascading Style Sheets. It is the language used to describe the visual presentation of HTML documents — colours, fonts, spacing, layout, animations, and more. While HTML provides structure and meaning, CSS controls how that structure looks.
Before CSS, developers applied styles directly in HTML using attributes like color, font, and bgcolor. This mixed content and presentation, making pages hard to maintain. CSS was designed to solve this by separating concerns: HTML handles structure, CSS handles appearance.
This separation means you can:
CSS consists of rules. Each rule has a selector that targets HTML elements and a declaration block containing one or more property-value pairs:
selector {
property: value;
property: value;
}
A real example:
h1 {
color: navy;
font-size: 2rem;
margin-bottom: 1rem;
}
This targets all h1 elements and makes them navy, 2rem tall, with a bottom margin of 1rem.
Write CSS in a separate .css file and link it from the HTML head:
<link rel="stylesheet" href="styles.css" />
This is the best approach for maintainability. One CSS file can style an entire website.
Write CSS inside a style element in the head:
<head>
<style>
body {
background-color: #f0f0f0;
}
</style>
</head>
Useful for single-page prototypes or when you cannot use an external file.
Apply CSS directly on an element using the style attribute:
<p style="color: red; font-weight: bold;">Warning!</p>
Avoid inline styles in production code — they are hard to override and difficult to maintain.
The "Cascading" in CSS refers to how conflicting rules are resolved. CSS applies rules according to three principles:
Understanding the cascade is one of the most important skills in CSS. Most CSS bugs are cascade and specificity issues.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.