What CSS is
CSS is the language that controls how HTML content is presented: its colors, type, spacing, and layout. Learning it lets you turn a plain document into a clear, branded interface without changing what the content means.
✓ What you will learn in this topic
- Explain the key idea: CSS controls visual presentation while HTML provides the document structure.
- Apply the concept: The demo receives dark-blue text, a pale-blue background, and breathing room inside its edges.
- Avoid this common mistake:
Concept explanation
Think of HTML as the meaning and structure of a room: its doors, labels, and furniture. CSS is the paint, spacing, and arrangement that make the room comfortable. The browser reads CSS rules and applies them to matching HTML elements.
CSS does not replace good HTML. A heading should still be a heading even when CSS changes its size. This separation makes a page easier to maintain and lets the same content take on different presentations.
Syntax
A CSS rule has a selector followed by declarations. Each declaration is a property and a value; the braces group the declarations that apply to matching elements.
.demo {
color: #17324d;
background-color: #eaf3ff;
padding: 1rem;
}Example 1: a small page element
Use this HTML as the target and place the CSS in a stylesheet linked to the page, or inside a <style> element while experimenting.
<main class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></main>.demo {
color: #17324d;
background-color: #eaf3ff;
padding: 1rem;
}Expected result: The demo receives dark-blue text, a pale-blue background, and breathing room inside its edges.
Example 2: a practical interface card
The same idea can style a reusable card on a course page. The class selector keeps the rule attached to this component rather than changing every element of that type.
<section class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></section>.card {
color: #17324d;
background: #fff;
border: 1px solid #d6e2f0;
border-radius: 0.75rem;
padding: 1.25rem;
box-shadow: 0 0.5rem 1.5rem rgb(23 50 77 / 10%);
}Expected result: The course update reads as a distinct interface card, and its content follows the spacing, color, and layout choices in the rule.
Common mistake
A stylesheet can be syntactically valid yet appear to do nothing when its selector does not match the page or the file is not connected.
Best practice
Keep structure in HTML and presentation in CSS. Prefer a named class for a component that may be reused.
Practice exercise
Create a small profile card and style its heading, paragraph, and link. Change one declaration at a time and note what it controls. Apply it to the example above and inspect the result at a narrow and a wide viewport.
Section summary
- CSS controls visual presentation while HTML provides the document structure.
- Keep structure in HTML and presentation in CSS. Prefer a named class for a component that may be reused.
Knowledge check
What is CSS primarily responsible for in a web page?
Reveal the explanation
CSS controls presentation. HTML remains responsible for the document structure and meaning.
Finish the module lessons, then take the server-scored module quiz to check your understanding.
Practical example
css.demo {
color: #17324d;
background-color: #eaf3ff;
padding: 1rem;
}
Expected result:
The demo receives dark-blue text, a pale-blue background, and breathing room inside its edges.
Hands-on practice task
Create a small profile card and style its heading, paragraph, and link. Change one declaration at a time and note what it controls.
In this section
Other lessons in Introduction to CSS
Broaden your knowledge
Related learning topics
HTML
Learn to structure accessible, meaningful web pages with a complete HTML course from first document to professional application patterns.
JavaScript
Build strong JavaScript foundations with browser examples, focused practice, beginner projects, and module quizzes.