How to Use Emmet in VS Code for HTML and CSS

Emmet is a powerful developer tool built directly into Visual Studio Code that dramatically accelerates HTML and CSS workflows. By using simple abbreviations and expanding them into full code snippets, Emmet allows developers to write complex markup and stylesheets in a fraction of the time. This article explains how Emmet works in VS Code, highlights essential shortcuts for HTML and CSS, and shows you how to configure its settings for maximum productivity.

How Emmet Works in VS Code

In Visual Studio Code, Emmet is enabled by default for HTML, XML, CSS, SCSS, Less, and JSX/TSX files. You do not need to install any external extensions to use it.

To use Emmet, you simply type a specific shorthand abbreviation in your editor and press the Tab or Enter key. VS Code detects the abbreviation and instantly expands it into complete, structured code.


Essential Emmet Shortcuts for HTML

Emmet uses syntax inspired by CSS selectors to generate HTML structures quickly. Here are the most common syntax patterns:

1. Child and Sibling Operators

2. Multiplication and Grouping

3. Attributes, Classes, and IDs

4. Text and Numbering


Essential Emmet Shortcuts for CSS

In CSS, Emmet uses fuzzy search and short letter sequences to generate full properties and values instantly.

1. Layout and Display

2. Box Model (Margin, Padding, and Dimensions)

Emmet automatically interprets trailing numbers as pixel values: * m10 expands to margin: 10px; * p10-20 expands to padding: 10px 20px; * w100 expands to width: 100px; * h100p expands to height: 100%; (adding ‘p’ outputs percentage)

3. Typography and Colors


Configuring Emmet Settings in VS Code

You can customize how Emmet behaves in VS Code by accessing your Settings (Ctrl + , on Windows/Linux, Cmd + , on macOS) and searching for “Emmet”.

Enable Emmet in React, Vue, and Other Languages

By default, Emmet might not expand in JSX, TSX, or Vue templates using the Tab key. You can force VS Code to recognize Emmet in these files by adding the following to your settings.json file:

"emmet.includeLanguages": {
    "javascript": "javascriptreact",
    "typescriptreact": "typescriptreact",
    "vue": "html"
}

Enable Trigger on Tab

If Emmet does not expand when you press Tab, ensure the following setting is enabled in your settings.json:

"emmet.triggerExpansionOnTab": true