By WebNest Studio Engineering Team
CSS Tutorial
Setting Up a CSS Workflow
CSS is easiest to learn when you can see the effect of a change immediately, and easiest to work with professionally when your workflow scales past a single stylesheet. This lesson covers the practical setup: linking a stylesheet correctly, using browser DevTools to experiment with styles live, and understanding when it becomes worth introducing a preprocessor or a build step.
Why it matters
CSS does nothing until it is connected to a page, and a wrong path in the link element is the classic first bug: the page loads, unstyled, with no error on screen. Knowing how a stylesheet is linked, and how to try out changes live in DevTools before writing them down, is the routine you will repeat on every project.
Linking a Stylesheet
CSS is connected to HTML with a <link> tag inside <head>: <link rel="stylesheet" href="styles.css">. The path in href is resolved relative to the HTML file's location, so a common beginner error is an incorrect relative path when files are organized into folders.
Live-Editing Styles in DevTools
Open DevTools (F12), select an element in the Elements tab, and the Styles pane on the right shows every CSS rule applying to it, including which stylesheet and line number each rule comes from. You can toggle properties on and off, edit values, and add new declarations directly in this pane to test ideas instantly — changes here are temporary and vanish on reload, so once you find a value you like, copy it back into your actual .css file.
- Click any property value (like a color or a margin) to edit it in place and see the page update immediately.
- Use the "+" button in the Styles pane to add a brand-new rule for testing.
- The "Computed" sub-tab shows the final resolved value of every CSS property after all rules and inheritance are applied — useful when several rules are competing.
When to Introduce a Preprocessor or Build Step
For a single page or a small project, a plain linked .css file is entirely sufficient. As a project grows — multiple pages sharing colors and spacing, deeply nested component styles, or a need to split styles into many organized files — a preprocessor like Sass (.scss) becomes useful. Sass adds variables, nesting, and reusable mixins, and compiles down to plain CSS that browsers already understand, so you introduce a small build step (via a tool like Vite or the Sass CLI) that watches your .scss files and outputs .css automatically. Modern CSS has closed part of this gap natively with custom properties (variables) and nesting, so many projects now delay reaching for Sass longer than they used to.
Examples
A correctly linked stylesheet with a basic rule
<!-- index.html -->
<head>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1 class="title">Getting Started</h1>
</body>
The page loads css/styles.css relative to index.html. If styles.css contains ".title { color: teal; }", the heading text renders in teal — visible immediately, with no build step required.
A minimal Sass file compiling down to plain CSS
// styles.scss
$primary: teal;
.title {
color: $primary;
&:hover {
color: darken($primary, 15%);
}
}
/* Compiles to: */
/*
.title { color: teal; }
.title:hover { color: #0a4d4d; }
*/
Running the Sass compiler produces a plain .css file with the variable substituted and the nested &:hover rule expanded into a standard descendant-free selector, ready to link into HTML exactly like a hand-written stylesheet.
Common Mistakes
- Using an incorrect relative path in the href of the link tag after reorganizing files into subfolders, resulting in unstyled ("naked") HTML with no console error explaining why.
- Editing styles only in DevTools and forgetting to copy the final values back into the actual CSS file, losing the change on the next reload.
- Reaching for Sass and a full build pipeline on a two-page static site where a plain linked stylesheet would have been simpler and sufficient.
- Forgetting that browsers do not understand .scss files directly — they must be compiled to .css before being linked in HTML.
Exercise
The playground page already links style.css. Write your first rules: give the page a sans-serif font, make the heading teal, and limit main to a width of 600px, centred on the page.
Expected result: the content sits in a centred column and the heading is teal.
/* The page contains: <main> with an <h1>, a <p> and a <button> */
/* TODO: a sans-serif font for the whole page */
/* TODO: a teal heading */
/* TODO: main is at most 600px wide and centred */
Show hints
- Set the font on
body; text inside inherits it. - A block is centred horizontally with
margin: 0 autoonce it has a width or amax-width.
Show solution
/* The page contains: <main> with an <h1>, a <p> and a <button> */
body {
font-family: system-ui, sans-serif;
}
h1 {
color: teal;
}
main {
max-width: 600px;
margin: 0 auto;
}
Quick quiz
1. Which line correctly links an external stylesheet?
- A. <link rel="stylesheet" href="style.css">
- B. <style src="style.css">
- C. <css href="style.css">
- D. <script href="style.css">
Show answer
A. The link element goes in the head, with rel="stylesheet" and the path in href.
2. You change a colour in the Styles pane of DevTools. What happens to your CSS file?
- A. Nothing; the change lasts only until the page is reloaded
- B. It is saved automatically
- C. The file is deleted
- D. The file is locked
Show answer
A. DevTools edits the page in memory. Copy the change into the file to keep it.
3. What does a preprocessor such as Sass produce?
- A. JavaScript
- B. Plain CSS that the browser can read
- C. HTML
- D. A faster browser
Show answer
B. Browsers do not understand Sass syntax; it is compiled to CSS before the page is served.
Interview questions
What are the three ways to add CSS to a page, and which is preferred?
Show answer
An external stylesheet linked with a link element, an internal style element in the head, and inline style attributes on elements. External stylesheets are preferred: one file styles the whole site, the browser caches it, and content stays separate from presentation. Inline styles apply to a single element, cannot be reused and are hard to override.
Do you still need Sass now that CSS has variables and nesting?
Show answer
Much less than before. Native CSS now has custom properties, nesting, calc() and colour functions, which cover the most common reasons for using a preprocessor. Sass still offers mixins, functions, loops and file partials that are resolved at build time. Many new projects use plain CSS or a utility framework, while Sass remains common in existing codebases.
Key Points to Remember
- Stylesheets are linked with <link rel="stylesheet" href="..."> in the document head, with the path resolved relative to the HTML file.
- The DevTools Styles pane lets you live-edit CSS and see the source file and line number for every applied rule; the Computed tab shows final resolved values.
- A preprocessor like Sass adds variables, nesting, and mixins, compiling down to plain CSS through a small build step.
- Native CSS variables and nesting have reduced how early projects need to reach for a preprocessor.
Practice in the playground
Write and run your own code for this topic, or start from the exercise or an example. Shows a live preview of your HTML, CSS and JavaScript. Your code for each topic is kept in this browser.
Run the examples
Change an input, predict the result, then compare it with the output. Explain why the result changes.
Written by
WebNest Studio Engineering Team
Practical lessons from developers working with Java, Python, React, databases and production systems.
Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering