Ekstensi visual studio code untuk html

Visual Studio Code provides basic support for HTML programming out of the box. There is syntax highlighting, smart completions with IntelliSense, and customizable formatting. VS Code also includes great Emmet support.

IntelliSense

As you type in HTML, we offer suggestions via HTML IntelliSense. In the image below, you can see a suggested HTML element closure </div> as well as a context specific list of suggested elements.

Ekstensi visual studio code untuk html

Document symbols are also available for HTML, allowing you to quickly navigate to DOM nodes by id and class name.

You can also work with embedded CSS and JavaScript. However, note that script and style includes from other files are not followed, the language support only looks at the content of the HTML file.

You can trigger suggestions at any time by pressing ⌃Space (Windows, Linux Ctrl+Space).

You can also control which built-in code completion providers are active. Override these in your user or workspace settings if you prefer not to see the corresponding suggestions.

// Configures if the built-in HTML language suggests HTML5 tags, properties and values.
"html.suggest.html5": true

Close tags

Tag elements are automatically closed when > of the opening tag is typed.

Ekstensi visual studio code untuk html

The matching closing tag is inserted when / of the closing tag is entered.

Ekstensi visual studio code untuk html

You can turn off autoclosing tags with the following setting:

"html.autoClosingTags": false

Auto update tags

When modifying a tag, the linked editing feature automatically updates the matching closing tag. The feature is optional and can be enabled by setting:

"editor.linkedEditing": true

Color picker

The VS Code color picker UI is now available in HTML style sections.

Ekstensi visual studio code untuk html

It supports configuration of hue, saturation and opacity for the color that is picked up from the editor. It also provides the ability to trigger between different color modes by clicking on the color string at the top of the picker. The picker appears on a hover when you are over a color definition.

Hover

Move the mouse over HTML tags or embedded styles and JavaScript to get more information on the symbol under the cursor.

Ekstensi visual studio code untuk html

Validation

The HTML language support performs validation on all embedded JavaScript and CSS.

You can turn that validation off with the following settings:

// Configures if the built-in HTML language support validates embedded scripts.
"html.validate.scripts": true,

// Configures if the built-in HTML language support validates embedded styles.
"html.validate.styles": true

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 HTML elements for multiline comments in the source code.

Additionally you can use the following region markers to define a folding region: <!-- #region --> and

"html.autoClosingTags": false
0

If you prefer to switch to indentation based folding for HTML use:

"[html]": {
    "editor.foldingStrategy": "indentation"
},

Formatting

To improve the formatting of your HTML source code, you can use the Format Document command ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I) to format the entire file or Format Selection ⌘K ⌘F (Windows, Linux Ctrl+K Ctrl+F) to just format the selected text.

The HTML formatter is based on js-beautify. The formatting options offered by that library are surfaced in the VS Code settings:

  • "html.autoClosingTags": false
    
    1: Maximum amount of characters per line.
  • "html.autoClosingTags": false
    
    2: List of tags that shouldn't be reformatted.
  • "html.autoClosingTags": false
    
    3: List of tags, comma separated, where the content shouldn't be reformatted.
  • "html.autoClosingTags": false
    
    4: List of tags that should have an extra newline before them.
  • "html.autoClosingTags": false
    
    5: Whether existing line breaks before elements should be preserved.
  • "html.autoClosingTags": false
    
    6: Maximum number of line breaks to be preserved in one chunk.
  • "html.autoClosingTags": false
    
    7: Indent
    "html.autoClosingTags": false
    
    8 and
    "html.autoClosingTags": false
    
    9 sections.
  • "editor.linkedEditing": true
    
    0: Wrapping strategy for attributes:
    • "editor.linkedEditing": true
      
      1: Wrap when the line length is exceeded
    • "editor.linkedEditing": true
      
      2: Wrap all attributes, except first
    • "editor.linkedEditing": true
      
      3: Wrap all attributes, except first, and align attributes
    • "editor.linkedEditing": true
      
      4: Wrap all attributes
    • "editor.linkedEditing": true
      
      5: Wrap when line length is exceeded, align attributes vertically
    • "editor.linkedEditing": true
      
      6: Preserve wrapping of attributes
    • "editor.linkedEditing": true
      
      7: Preserve wrapping of attributes but align
  • "editor.linkedEditing": true
    
    8: Alignment size when using
    "editor.linkedEditing": true
    
    9 and
    // Configures if the built-in HTML language support validates embedded scripts.
    "html.validate.scripts": true,
    
    // Configures if the built-in HTML language support validates embedded styles.
    "html.validate.styles": true
    
    0 in
    "editor.linkedEditing": true
    
    0 or
    // Configures if the built-in HTML language support validates embedded scripts.
    "html.validate.scripts": true,
    
    // Configures if the built-in HTML language support validates embedded styles.
    "html.validate.styles": true
    
    2 to use the default indent size.
  • // Configures if the built-in HTML language support validates embedded scripts.
    "html.validate.scripts": true,
    
    // Configures if the built-in HTML language support validates embedded styles.
    "html.validate.styles": true
    
    3: Honor django, erb, handlebars and php templating language tags.
  • // Configures if the built-in HTML language support validates embedded scripts.
    "html.validate.scripts": true,
    
    // Configures if the built-in HTML language support validates embedded styles.
    "html.validate.styles": true
    
    4: Keep text content together between this string.

Tip: The formatter doesn't format the tags listed in the

"html.autoClosingTags": false
2 and
"html.autoClosingTags": false
3 settings. Embedded JavaScript is formatted unless 'script' tags are excluded.

The Marketplace has several alternative formatters to choose from. If you want to use a different formatter, define

// Configures if the built-in HTML language support validates embedded scripts.
"html.validate.scripts": true,

// Configures if the built-in HTML language support validates embedded styles.
"html.validate.styles": true
7 in your settings to turn off the built-in formatter.

Emmet snippets

VS Code supports Emmet snippet expansion. Emmet abbreviations are listed along with other suggestions and snippets in the editor auto-completion list.

Ekstensi visual studio code untuk html

Tip: See the HTML section of the Emmet cheat sheet for valid abbreviations.

If you'd like to use HTML Emmet abbreviations with other languages, you can associate one of the Emmet modes (such as

// Configures if the built-in HTML language support validates embedded scripts.
"html.validate.scripts": true,

// Configures if the built-in HTML language support validates embedded styles.
"html.validate.styles": true
8,
// Configures if the built-in HTML language support validates embedded scripts.
"html.validate.scripts": true,

// Configures if the built-in HTML language support validates embedded styles.
"html.validate.styles": true
9) with other languages with the
"[html]": {
    "editor.foldingStrategy": "indentation"
},
0 setting. The setting takes a and associates it with the language ID of an Emmet supported mode.

For example, to use Emmet HTML abbreviations inside JavaScript:

{
  "emmet.includeLanguages": {
    "javascript": "html"
  }
}

We also support User Defined Snippets.

HTML custom data

You can extend VS Code's HTML support through a declarative custom data format. By setting

"[html]": {
    "editor.foldingStrategy": "indentation"
},
1 to a list of JSON files following the custom data format, you can enhance VS Code's understanding of new HTML tags, attributes and attribute values. VS Code will then offer language support such as completion & hover information for the provided tags, attributes and attribute values.

You can read more about using custom data in the vscode-custom-data repository.

HTML extensions

Install an extension to add more functionality. Go to the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and type 'html' to see a list of relevant extensions to help with creating and editing HTML.

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.