EthicsComputerCourses
Join training +91 90532 10052

Installing VS Code for CSS Development

CSS · Lesson 5 of 240 Beginner 12 min read Updated

By the end of this lesson you will have VS Code ready for writing CSS: a practice folder with an HTML file linked to a separate style sheet, the editor's built-in CSS helpers switched on, and the browser's developer tools open beside your page. You will also know which extensions are worth adding and which you can skip.

If you have not installed VS Code yet, follow Installing VS Code & Development Setup first. It covers downloading VS Code, saving files, opening pages in the browser and live preview extensions. General editor settings and extension safety are in VS Code Extensions for HTML. This lesson adds only what is special about CSS.

Step 1: create a CSS practice folder

Keep your CSS in its own file from day one. A separate .css file can be shared by every page of a site, and VS Code gives you the most help inside it.

  1. Create a folder called css-practice and open it in VS Code with File > Open Folder.
  2. Create a file called index.html.
  3. Create a folder called css and, inside it, a file called style.css.

Your Explorer panel should now look like this:

Text
css-practice/
  index.html
  css/
    style.css

Type ! in index.html and press Tab to get a starter page. Then add one line inside <head> to connect the style sheet. The href is the path from the HTML file to the CSS file.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS Practice</title>
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <h1>Isha's Chai Corner</h1>
  <p class="offer">Masala chai ₹20, ginger chai ₹25</p>
</body>
</html>

Now put a test rule in style.css and save both files:

CSS
body {
  font-family: system-ui, sans-serif;
  background-color: #fdf3e7;
}

.offer {
  color: #8b3a00;
  font-weight: bold;
}

Open index.html in your browser. If the background is pale orange and the offer line is brown and bold, the link works. You will learn more about linking style sheets in External CSS.

If you cannot install anything right now, this single-file version shows what you should see. It puts the CSS in a <style> element instead, because the Try-it editor runs one file at a time.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CSS Practice</title>
  <style>
    body {
      font-family: system-ui, sans-serif;
      background-color: #fdf3e7;
    }
    .offer {
      color: #8b3a00;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <h1>Isha's Chai Corner</h1>
  <p class="offer">Masala chai ₹20, ginger chai ₹25</p>
</body>
</html>

Step 2: use the built-in CSS helpers

VS Code understands CSS without any extension. Open style.css and try each of these.

FeatureWhat it doesHow to use it
IntelliSenseSuggests properties and values, with a short description and browser support notesStart typing, or press Ctrl+Space
Colour preview and pickerShows a small coloured square before every colour valueClick the square to open the picker
HoverShows an HTML example the selector matches, and its specificityRest the mouse on a selector
EmmetExpands short abbreviations into full declarationsType an abbreviation and press Tab
Lint warningsUnderlines likely mistakes, such as unknown propertiesHover over the wavy line
Format DocumentFixes spacing and indentationShift+Alt+F
Go to SymbolJumps to any selector in a long fileCtrl+Shift+O

The colour picker

Next to #8b3a00 you should see a small brown square. Click it. A picker opens where you can drag to choose a new colour. Click the colour value at the top of the picker to switch between formats such as hex, rgb() and hsl(). This is handy when a designer gives you a colour in one format and your project uses another.

Hover and specificity

Rest your mouse on the selector .offer. VS Code shows a tiny HTML example, <element class="offer">, and a line like Selector Specificity: (0, 1, 0). The three numbers count IDs, classes and element names. You will learn what they mean in CSS Specificity; for now, just know where to look.

Emmet for CSS

You may know Emmet from HTML. It works in CSS too. Inside a rule, type an abbreviation and press Tab:

You typeVS Code writes
m10margin: 10px;
p10-20padding: 10px 20px;
dfdisplay: flex;
w100pwidth: 100%;
fz18font-size: 18px;
bgcbackground-color: #fff;
bdrs8border-radius: 8px;

The pattern is the first letters of the property, then the value. A p after a number means percent. Emmet is built in, so never install a separate Emmet extension.

Built-in lint warnings

A linter is a tool that reads your code and points out likely mistakes. VS Code has a small CSS linter built in. Type these two rules at the end of style.css:

CSS
.price {
  colr: green;
}

.empty {
}

Wavy underlines appear. Hover over them to read the messages:

Output
Unknown property: 'colr'
Do not use empty rulesets

The browser would silently ignore both mistakes, so catching them in the editor saves you real debugging time. Fix the spelling to color and delete the empty rule.

Step 3: a few CSS settings

Open the Command Palette (Ctrl+Shift+P), run Preferences: Open User Settings (JSON) and add these keys inside the outer braces:

JSON
{
  "editor.formatOnSave": true,
  "css.lint.duplicateProperties": "warning",
  "css.lint.zeroUnits": "warning",
  "[css]": {
    "editor.defaultFormatter": "vscode.css-language-features"
  }
}
  • editor.formatOnSave tidies the file every time you save.
  • css.lint.duplicateProperties warns when one rule sets the same property twice, a common copy-paste mistake. It is off by default.
  • css.lint.zeroUnits suggests writing 0 instead of 0px, since zero needs no unit.
  • The [css] block chooses VS Code's own CSS formatter for .css files.

Step 4: add only the extensions you need

The built-in features are enough for the whole of Level 1. These well-known extensions are worth adding as your projects grow. Search for them by their exact ID in the Extensions view (Ctrl+Shift+X).

ExtensionIDWhy
Live Server or Live Previewritwickdey.LiveServer or ms-vscode.live-serverReloads the page when you save CSS; pick one (see the setup lesson)
Prettier - Code formatteresbenp.prettier-vscodeFormats HTML, CSS and JS the same way for a whole team
Stylelintstylelint.vscode-stylelintA much stronger CSS linter; needs Stylelint installed in the project

If you install Prettier, change the [css] formatter to "esbenp.prettier-vscode" so only one formatter runs. Stylelint needs a small project setup, which you will do in Stylelint Configuration. If you add it, the Stylelint extension suggests turning off the built-in check with "css.validate": false to avoid duplicate warnings.

Step 5: browser DevTools for CSS

VS Code is where you write CSS. The browser's developer tools (DevTools) are where you find out why it does or does not work. Open your page, right-click any element and choose Inspect (or press F12). In Chrome and Edge, the Styles pane on the right lists every rule that matches the selected element. Firefox calls it the Rules view.

Run this page and inspect the heading and the paragraph. It contains three deliberate problems.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>DevTools practice</title>
  <style>
    body { font-family: system-ui, sans-serif; padding: 1rem; }
    h1 { color: darkgreen; }
    h1 { color: darkred; }
    .timing {
      background-color: #e8f0fe;
      padding: 10 px;
      colr: navy;
      border-left: 4px solid #4a6fa5;
    }
  </style>
</head>
<body>
  <h1>Rohtak Cricket Academy</h1>
  <p class="timing">Nets practice: 6 am to 8 am, Monday to Saturday</p>
</body>
</html>

Here is what to look for:

  1. Overridden values. Select the heading. color: darkgreen is shown crossed out, because the later darkred rule wins.
  2. Invalid values. Select the paragraph. padding: 10 px and colr: navy are crossed out with a warning icon. Fix the padding to 10px right in DevTools and watch the box grow.
  3. Live editing. Click any value and use the Up and Down arrow keys to change numbers. Untick the checkbox beside a declaration to switch it off. Click a colour swatch to open the colour picker.

Two more tools are useful early. The Computed tab shows the final value of every property and the box model diagram. The :hov button lets you force states such as :hover, so you can style a hover effect without keeping the mouse on it. You will use DevTools in depth in CSS Debugging & DevTools.

Remember that DevTools changes the browser's copy of the page, not your file. When a change works, copy it back into style.css in VS Code and save.

Common mistakes

  • Wrong path in href. If style.css is in a css folder, the link must be css/style.css. Check the Network tab in DevTools for a red 404 entry.
  • Styles not updating. The browser may be using an old cached copy of your CSS. Press Ctrl+Shift+R (or Ctrl+F5) for a hard reload.
  • Forgetting to save the CSS file. A white dot on the editor tab means unsaved changes.
  • Two formatters fighting. Set one editor.defaultFormatter for CSS, not Prettier and the built-in formatter at once.
  • Installing an Emmet or colour picker extension. Both are built into VS Code already.

Interview questions

1. Why keep CSS in a separate file instead of a <style> element?

A separate file can be shared by every page, so one change updates the whole site. The browser can also cache it, so later pages load faster. Editors and linters give the most help in a dedicated .css file.

2. How do you find out why a CSS declaration is not working?

Inspect the element in DevTools and look at the Styles pane. A crossed-out declaration means it was overridden by another rule; a crossed-out declaration with a warning icon means the property or value is invalid. If the rule is missing completely, the selector does not match or the file did not load.

3. What is the difference between a linter and a formatter?

A formatter, such as Prettier, changes how code looks: spacing, line breaks and indentation. A linter, such as Stylelint or VS Code's built-in CSS checks, reports likely mistakes, such as unknown properties or duplicate declarations. Teams usually use one of each.

4. Your CSS change does not show in the browser. What do you check?

First check that the file is saved and that the href path is correct, using the Network tab to spot a 404. Then do a hard reload to skip the cached copy. Finally, inspect the element to see whether another rule is overriding yours.

Key points

  • Keep CSS in its own file, such as css/style.css, linked from <head>.
  • VS Code has built-in CSS IntelliSense, colour pickers, Emmet, hover specificity and lint warnings.
  • Emmet abbreviations like m10 and df expand into full declarations with Tab.
  • Add extensions only when needed: a live preview, Prettier and Stylelint cover most projects.
  • DevTools shows every matching rule, crossed-out values and the computed result.
  • DevTools edits are temporary; copy working changes back into your CSS file.

Exercise

Create a folder notice-board with index.html and css/style.css for Meera's school notice board in Pune. Link the style sheet and add a heading and three notices as paragraphs with the class notice. In style.css, use Emmet abbreviations to write at least four declarations (for example p10-20, bgc, bdrs8 and fz18), then change the background colour with the colour picker. Open the page in a browser, inspect a notice in DevTools, change its padding there, and copy the value you like back into your file.

Show solution
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>School Notice Board</title>
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <h1>Notice Board</h1>
  <p class="notice">Sports day on Saturday, report by 8 am.</p>
  <p class="notice">Library books are due by the 15th.</p>
  <p class="notice">Parent-teacher meeting on Monday at 10 am.</p>
</body>
</html>
CSS
body {
  font-family: system-ui, sans-serif;
}

.notice {
  padding: 12px 20px;
  background-color: #fff8d6;
  border-radius: 8px;
  font-size: 18px;
}

The four declarations in .notice started as p10-20, bgc, bdrs8 and fz18. The padding was then adjusted to 12px 20px in DevTools and copied back, and the colour picker turned #fff into a pale yellow.

Quick Quiz

1. Where should the <link rel="stylesheet"> element go?

2. In VS Code, what does the Emmet abbreviation df expand to inside a CSS rule?

3. In the DevTools Styles pane, a declaration is crossed out with a warning icon. What does that mean?

4. You edited a colour in DevTools and it looks perfect. What happens when you reload the page?

Learn CSS with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call