CSS, SCSS and Less
AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. 🎬 Watch The Story of VS Code! VS Code is now on Instagram, follow @vscode.ig for updates, tips, and more. Rewatch GitHub Copilot Day. CSS, SCSS and Less View as Markdown Ask in VS Code Ask in VS Code Insiders Visual Studio Code has built-in support for editing style sheets in CSS .css , SCSS .scss and Less .less .
In addition, you can install an extension for greater functionality. Tip: Click on an extension tile above to read the description and reviews to decide which extension is best for you. See more in the Marketplace . IntelliSense VS Code has support for selectors, properties and values. Use ⌃Space (Windows, Linux Ctrl+Space ) to get a list of context specific options. Proposals contain extensive documentation, including a list of browsers that support the property.
To see the full description text of the selected entry, use ⌃Space (Windows, Linux Ctrl+Space ) . Syntax coloring & color preview As you type, there is syntax highlighting as well as in context preview of colors. Clicking on a color preview will launch the integrated color picker which supports configuration of hue, saturation and opacity. Tip: You can trigger between different color modes by clicking on the color string at the top of the picker.
You can hide VS Code's color previews by setting the following setting : "editor.colorDecorators" : false To just disable it for css, Less and SCSS, use "[css]" : { "editor.colorDecorators" : false } Folding You can fold regions of source code using the folding icons on the gutter between line numbers and line start. Folding regions are available for all declarations (for example, rule declarations) and for multiline comments in the source code.
Additionally you can use the following region markers to define a folding region: /*#region*/ and /*#endregion*/ in CSS/SCSS/Less or // #region and // #endregion In SCSS/Less. If you prefer to switch to indentation based folding for CSS, Less and SCSS, use: "[css]" : { "editor.foldingStrategy" : "indentation" }, Emmet snippets Emmet abbreviation support is built into VS Code, suggestions are listed along with other suggestions and snippets in the editor auto-completion list.
Tip: See the CSS section of the Emmet cheat sheet for valid abbreviations. VS Code also supports User Defined Snippets . Syntax Verification & Linting There is support for CSS version <= 2.1, Sass version <= 3.2 and Less version <= 2.3. Note: You can disable VS Code's default CSS, Sass or Less validation by setting the corresponding .validate User or Workspace setting to false. "css.validate" : false Go to Symbol in file You can quickly navigate to the relevant CSS symbol in the current file by pressing ⇧⌘O (Windows, Linux Ctrl+Shift+O ) .
Hovers Hovering over a selector or property will provide an HTML snippet that is matched by the CSS rule. Go to Declaration and Find References This is supported for Sass and Less variables in the same file. CSS variables per the draft standards proposal are also supported. There is jump to definition for @import and url() links in CSS, SCSS and Less. CSS custom data You can extend VS Code's CSS support through a declarative custom data format .
By setting css.customData Open in VS Code Open in VS Code Insiders to a list of JSON files following the custom data format, you can enhance VS Code's understanding of new CSS properties, at-directives, pseudo-classes and pseudo-elements. VS Code will then offer language support such as completion & hover information for the provided properties, at-directives, pseudo-classes and pseudo-elements. You can read more about using custom data in the vscode-custom-data repository.
Formatting The CSS Languages Features extension also provides a formatter. The formatter works with CSS, LESS and SCSS. It is implemented by the JS Beautify library and comes with the following settings: css.format.enable Open in VS Code Open in VS Code Insiders - Enable/disable default CSS formatter. css.format.newlineBetweenRules Open in VS Code Open in VS Code Insiders - Separate rulesets by a blank line. css.format.newlineBetweenSelectors Open in VS Code Open in VS Code Insiders - Separate selectors with a new line. css.format.spaceAroundSelectorSeparator Open in VS Code Open in VS Code Insiders - Ensure a space character around selector separators '>', '+', '~' (for example, a > b ).
The same settings also exist for less and scss . Transpiling Sass and Less into CSS VS Code can integrate with Sass and Less transpilers through our integrated task runner . We can use this to transpile .scss or .less files into .css files. Let's walk through transpiling a simple Sass/Less file. Step 1: Install a Sass or Less transpiler For this walkthrough, let's use either the sass or less Node.js module. Note: If you don't have Node.js and the npm package manager already installed, you'll need to do so for this walkthrough.
Install Node.js for your platform . The Node Package Manager (npm) is included in the Node.js distribution. You'll need to open a new terminal (command prompt) for npm to be on your PATH. npm install -g sass less Step 2: Create a simple Sass or Less file Open VS Code on an empty folder and create a styles.scss or styles.less file. Place the following code in that file: $padding : 6px ; nav { ul { margin : 0 ; padding : $padding ; list-style : none ; } li { display : inline-block ; } a { display : block ; padding : $padding 12px ; text-decoration : none ; } } For the Less version of the above file, just change $padding to @padding .
Note: This is a very simple example, which is why the source code is almost identical between both file types. In more advanced scenarios, the syntaxes and constructs will be much different. Step 3: Create tasks.json The next step is to set up the task configuration. To do this, run Terminal > Configure Tasks and click Create tasks.json file from template . In the selection dialog that shows up, select Others . This will create a sample tasks.json file in the workspace .vscode folder.
The initial version of file has an example to run an arbitrary command. We will modify that configuration for transpiling Sass/Less instead: // Sass configuration { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version" : "2.0.0" , "tasks" : [ { "label" : "Sass Compile" , "type" : "shell" , "command" : "sass styles.scss styles.css" , "group" : "build" } ] } // Less configuration { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version" : "2.0.0" , "tasks" : [ { "label" : "Less Compile" , "type" : "shell" , "command" : "lessc styles.less styles.css" , "group" : "build" } ] } Step 4: Run the Build Task As this is the only command in the file, you can execute it by pressing ⇧⌘B (Windows, Linux Ctrl+Shift+B ) ( Run Build Task ).
The sample Sass/Less file should not have any compile problems, so by running the task all that happens is a corresponding styles.css file is created. Since in more complex environments there can be more than one build task we prompt you to pick the task to execute after pressing ⇧⌘B (Windows, Linux Ctrl+Shift+B ) ( Run Build Task ). In addition, we allow you to scan the output for compile problems (errors and warnings).
Depending on the compiler, select an appropriate entry in the list to scan the tool output for errors and warnings. If you don't want to scan the output, select Never scan the build output from the presented list. At this point, you should see an additional file show up in the file list styles.css . If you want to make the task the default build task to run execute Configure Default Build Task from the global Terminal menu and select the corresponding Sass or Less task from the presented list.
Note: If your build fails or you see a
The rest of this page is on the live site.