Chapter 1 of 17 · CSS for Beginners — Complete Free Tutorial
Introduction to CSS
Welcome to the CSS for Beginners tutorial series on Scriptly. By the end of these 17 chapters you will be able to style any web page from scratch: readable typography, tidy layouts with Flexbox and Grid, responsive designs that work on phones, and smooth animations — all with hand-written CSS and no frameworks. This first chapter explains what CSS is and how a browser turns your rules into pixels.
What is CSS?
CSS stands for Cascading Style Sheets. If HTML is the skeleton and content of a page, CSS is the skin, the clothing, and the furniture arrangement — it controls how things look: colours, spacing, fonts, and layout.
- Cascading — when several rules target the same element, the browser follows a defined order to pick a winner. You will master this in the variables and specificity chapter.
- Style Sheets — plain text files of rules. A stylesheet is nothing more than a list of "for this element, use these styles".
Anatomy of a CSS rule
Every CSS rule has two parts: a selector that picks the elements, and a declaration block of property–value pairs.
/* selector */
p {
color: navy; /* property: value */
font-size: 1.125rem; /* another declaration */
line-height: 1.6;
}
| Part | Name | Job |
|---|---|---|
p | Selector | Chooses which elements the rule applies to |
color | Property | The aspect you want to change |
navy | Value | The setting you give it |
{ … } | Declaration block | Container for one or more declarations |
Expected output: every paragraph on the page becomes navy, slightly larger than normal, with comfortable line spacing.
How a browser applies CSS
When a page loads, the browser performs a small pipeline on every visit:
- It parses the HTML into the DOM (Document Object Model).
- It parses your CSS into the CSSOM (CSS Object Model).
- It combines both into a render tree — the list of visible nodes and their styles.
- It performs layout (calculates size and position), then paint (fills in pixels), then composites.
This is why an unstyled page flashes white before styles arrive — a topic you will fix properly in Adding CSS to HTML.
Why CSS matters
- One file, every page — change your brand colour once and it updates across the whole site.
- Responsive design — the same HTML can look right on a 360 px phone and a 27" monitor.
- Accessibility — good CSS respects user font-size settings, supports keyboard focus, and keeps contrast readable.
- Performance — a small cached stylesheet loads once and styles every page instantly.
A first complete example
Here is a full, tiny page. Save it as index.html and open it in your browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My styled page</title>
<style>
body { font-family: system-ui, sans-serif; background: #f4f6fb; }
h1 { color: #4f46e5; letter-spacing: -0.02em; }
.card {
background: white;
padding: 1.5rem;
border-radius: 1rem;
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}
</style>
</head>
<body>
<div class="card">
<h1>Hello, CSS!</h1>
<p>This card has padding, rounded corners and a soft shadow.</p>
</div>
</body>
</html>
Expected output: a light blue-grey page containing a white card with rounded corners and a soft shadow; the heading is indigo and tight-looking.
Common mistakes
- Styling by tag only — styling every
<div>makes future changes painful. Prefer classes; you will see why in CSS Selectors. - Learning properties before the box model — spacing surprises come from misunderstanding the box model, so keep The Box Model on your shortlist.
- Skipping structure — real stylesheets are organised: base styles, components, utilities. Even a comment header helps.
Practice checklist
- Create
index.htmlwith the example above and change the heading colour to a hex value you pick. - Add one more declaration to
.card— tryborder: 2px dashed #4f46e5;. - Open your browser's developer tools (F12 or right-click → Inspect) and toggle a style off to see the page change live.
Next: learn the three ways to attach CSS to a page and which one you should always use — Adding CSS to HTML.
Frequently Asked Questions
CSS (Cascading Style Sheets) is the language that controls how HTML content looks — colours, fonts, spacing, layout, responsiveness and animation. HTML provides structure and meaning; CSS provides presentation. One stylesheet can restyle an entire website at once.
The fundamentals (selectors, box model, Flexbox, media queries) take about 2–3 weeks of daily practice. Grid, animations and architecture come with a little more practice. This 17-chapter series is designed for 3–4 weeks at a relaxed pace — faster if you type out every example.
Yes. HTML first, then CSS, then JavaScript. CSS and HTML together let you build complete, good-looking static pages, and almost every JavaScript framework assumes you already know CSS layout and selectors.
No — CSS is a styling language with selectors and property-value declarations, not variables, loops or conditionals. You can get far without any programming logic, and JavaScript adds the behaviour later.
Flexbox distributes space along one axis (a row or a column) and is ideal for components — toolbars, navbars, card rows. Grid controls rows and columns together and is ideal for page structure and card grids. They are complementary: many layouts use a grid page shell with flex components inside.
Usually one of three reasons: the selector does not match (check class names), a more specific rule wins (use the browser inspector to see computed styles and specificity), or the file is not linked/loads in the wrong order. The specificity chapter explains how the cascade decides.
Every element is a box of four layers: content, padding (inner space), border, and margin (outer space). With box-sizing: border-box, the width you set includes padding and border — the universal reset every project uses.
Use relative units, flexible grids like repeat(auto-fit, minmax(260px, 1fr)), images with max-width: 100%, and mobile-first media queries. The goal is zero horizontal scrolling from 320px up — the responsive chapters show the full workflow.
Not to learn. Frameworks are productivity tools built on the same CSS you are learning here; understanding the fundamentals makes any framework easier to use (and to debug when it fights you). Learn vanilla CSS first, then evaluate frameworks with an informed eye.
JavaScript for interactivity, then a build tool and version control (Git). With HTML, CSS and JavaScript you can build complete websites; after that, frameworks like React or server-side tools like Laravel Blade build on these fundamentals.