Git Product home page Git Product logo

vscode-html-css's Introduction

Visual Studio Code CSS Intellisense for HTML

HTML id and class attribute completion for Visual Studio Code.

Features

  • HTML id and class attribute completion.
  • Supports linked and embedded style sheets.
  • Supports template inheritance.
  • Supports additional style sheets.
  • Supports other HTML like languages.
  • Validates CSS selectors on demand.

Usage

You can view a list of id and class attribute suggestions via ctrl + space.

Linked and Embedded Style Sheets

Linked [<link rel="stylesheet">] and embedded [<style></style>] style sheets are used in completion for id and class attributes. Links support local and remote files. Absolute local file paths are relative to the workspace folder while others are relative to HTML file:

index.html

<!DOCTYPE html>
<html>

<head>
    <!-- Remote style sheet -->
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
    
    <!-- Local style sheet relative to workspace folder -->
    <link rel="stylesheet" href="/style.css">

    <!-- Local style sheet relative to this file -->
    <link rel="stylesheet" href="style.css">
    
    <!-- Embedded style sheet -->
    <style>
        #content {
            display: block;
        }

        .internal {
            display: block;
        }
    </style>
</head>

<body>
    <div class="container external internal" id="content">
        <div class="row">
            <div class="col">1 of 2</div>
            <div class="col">2 of 2</div>
        </div>
    </div>
</body>

</html>

All local links point to the same file which is in the root of workspace folder:

style.css

.external {
    display: block;
}

Template Inheritance

Template inheritance is supported for the following tags:

{% extends "base" %}

@extends('base')

{{< base }}

{{> base }}

Styles defined in base.html will also be available for completion in home.html:

base.html

<!doctype html>
<html>

<head>
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">

    <style>
        #content {
            display: block;
        }

        .internal {
            display: block;
        }
    </style>

    <title>{{ title }}</title>
</head>

<body>
    {% block content %}{% endblock %}
</body>

</html>

home.html

{% extends "base" %}

{% block content %}
<div id="content" class="container internal">
    <h1>Home</h1>
</div>
{% endblock %}

Additional Style Sheets

If it is not possible to specify local or remote styles in HTML or via template inheritance, they can be specified in VS Code settings per workspace folder in .vscode/settings.json and will suggest for all HTML files within that workspace folder.

Example

.vscode/settings.json

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

All relative paths will be evaluated relative to the file being edited. ${fileBasenameNoExtension} will be replaced with the file name of the file being edited without extension.

Supported Languages

Supported languages can be configured with the css.enabledLanguages 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, etc. You should also install corresponding language extension which registers the language id in VS Code.

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

Commands

Validate Attributes

Validates all id and class attributes in the active editor.

Clear Cache

Clears file cache.

Installation

Extension can be installed from Visual Studio Code Marketplace.

vscode-html-css's People

Contributors

ecmel avatar dependabot[bot] avatar rush1818 avatar hornmichaels avatar thecolorred avatar tanhakabir avatar harry-sm avatar grunxen avatar badre429 avatar vignesh0025 avatar soullivaneuh avatar naccoll avatar michaelshorn avatar aeschli avatar maltesa avatar negcx avatar jankeromnes avatar dvic avatar coliff avatar cvharris avatar benjcal 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.