Code Monkey home page Code Monkey logo

vscode-html-css's Introduction

Visual Studio Code CSS Intellisense for HTML

commit

HTML id and class attribute completion for Visual Studio Code.

Features

  • HTML id and class attribute completion
  • Supports completion from in file defined styles
  • Supports specifying remote and local style sheets
  • Supports any language for completion
  • Supports go to definition for selectors
  • Validates class attributes on demand

Supported Languages

Supported languages can be configured with the css.enabledLanguages global setting. By default html is enabled:

{
  "css.enabledLanguages": ["html"]
}

Extension can be configured to support any language where it makes sense such as nunjucks, twig, mustache, vue, typescript etc. You should also install corresponding language extension which registers the specific language id in VS Code.

This setting is application scoped and changing the setting requires restarting VS Code.

Specifying Style Sheets

Remote and local style sheets with optional glob patterns and variable substitutions can be specified in VS Code settings per workspace folder in .vscode/settings.json and will suggest in all configured languages within that workspace folder.

Glob patterns for local style sheets can have the following syntax:

Pattern Matches
* zero or more characters in a path segment
? one character in a path segment
** any number of path segments, including none
{} group conditions like **โ€‹/*.{css,scss}
[] a range of characters like [0-9] or negate [!0-9]

The following variable substitutions are supported for local style sheets as well:

Variable Substitution
${fileBasename} Current file's basename
${fileBasenameNoExtension} Current file's basename with no extension

Examples

Configuration depends on your layout of the project. The following most basic setup will suggest from all css files in project's src folder:

.vscode/settings.json

{
  "css.styleSheets": ["src/**/*.css"]
}

If Bootstrap npm module is used with additional scss the following can be a starting point:

.vscode/settings.json

{
  "css.styleSheets": [
    "node_modules/bootstrap/dist/css/bootstrap.css",
    "src/**/*.scss"
  ]
}

or in case of Bootstrap CDN with additional plain css:

.vscode/settings.json

{
  "css.styleSheets": [
    "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
    "src/**/*.css"
  ]
}

All of Bootstrap's class selectors with additional user defined styles in the project will be available for completion in html files.

Enable typescript or javascript in global settings depending on your usage and restart VS Code:

{
  "css.enabledLanguages": ["html", "typescript"]
}

Component's static styles will be available for completion elsewhere in the component. If you need to use some base styles in every component you can specify as follows:

.vscode/settings.json

{
  "css.styleSheets": ["src/base-styles.ts"]
}

Variable substitution can be used to refer to a related css file. If you are working on my-component.ts and your css is in my-component-css.ts then a suitable setup can be:

.vscode/settings.json

{
  "css.styleSheets": ["src/${fileBasenameNoExtension}-css.ts"]
}

Install your favorite Vue language extension from Marketplace which registers vue language id then enable vue in global settings and restart VS Code:

{
  "css.enabledLanguages": ["html", "vue"]
}

Styles defined in component's <style> section will be available for completion in component's <template> section.

Variable substitution can be used for Angular development:

.vscode/settings.json

{
  "css.styleSheets": ["app/${fileBasenameNoExtension}.css"]
}

With this setup, styles defined in e.g. app.component.css will be available in app.component.html.

Go to Definition

Go to definition for id and class selectors for local style sheets are supported. Selecting Go to Definition from context menu (F12 or โŒ˜ click) on a selector will open the local style sheet which the selector is defined.

Commands

Validate class selectors

Validates all class selectors in the active editor. Auto validation can be configured in extension settings globally or per workspace.

Clear style sheets cache

Clears style sheets cache.

Sponsor

Installation

Extension can be installed from Visual Studio Code Marketplace.

vscode-html-css's People

Contributors

abliger avatar aeschli avatar badre429 avatar benjcal avatar coliff avatar cvharris avatar dependabot[bot] avatar dvic avatar ecmel avatar grunxen avatar harry-sm avatar hornmichaels avatar jankeromnes avatar maltesa avatar michaelshorn avatar naccoll avatar negcx avatar rush1818 avatar schpet avatar soullivaneuh avatar tanhakabir avatar thecolorred avatar vignesh0025 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.