How to Use Emmet in VS Code to Write HTML and CSS Faster

Write HTML and CSS with Emmet abbreviations in VS Code. Learn the most useful shortcuts, how to expand abbreviations, use filters, and extend Emmet to other file types.

5 min read

Emmet is a built-in VS Code feature that expands short abbreviations into full HTML and CSS. You type a CSS selector-like expression, press one key, and VS Code produces the complete markup or style.

No extension is required. Emmet is active by default in HTML, CSS, SCSS, Less, JSX, XML, Pug, Haml, and Slim files. For more on VS Code editing features, see how to use multiple cursors. If you want to create your own abbreviations, check out custom code snippets.

Your first abbreviation

Open an HTML file. Type ! and press Tab or Enter. VS Code expands it into a full HTML5 document skeleton.

Now type ul>li*5 and expand it.

htmlhtml
<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

The expression means an unordered list containing a list item, repeated 5 times.

Essential Emmet syntax

Emmet abbreviations use a small set of operators. Learn these and you can produce most markup:

SyntaxMeaningExampleResult
>Child elementdiv>pdiv containing p
+Sibling elementdiv+pdiv followed by p
*NRepeat N timesli*3Three li elements
.classAdd classdiv.containerdiv with class container
#idAdd IDdiv#headerdiv with id header
{}Text contentp{Hello}p containing the text Hello
$Auto-numberingli.item-$*3li elements numbered item-1, item-2, item-3
()Grouping(div>p)+(div>span)Two separate divs

You can combine these freely. This expression creates a div with an ID, containing a list with three numbered items and links:

texttext
div#page>ul>li.item-$*3>a{Link $}

Auto-numbering with $

The $ symbol increments with each repetition.

Use two dollar signs for two-digit padding, like 01 or 02. Use $@- to count down. This example creates three image tags with padded numbers:

htmlhtml
<img src="photo-01.jpg" alt="">
<img src="photo-02.jpg" alt="">
<img src="photo-03.jpg" alt="">

Lorem ipsum text

Emmet also expands the word lorem into placeholder text. Add a number for word count, like lorem5 for 5 words. Combine it with multiplication, like p*3>lorem5, to produce 3 paragraphs of 5 words each.

CSS abbreviations

Emmet works the same way in CSS files. Type a shorthand and expand it:

AbbreviationResult
m10margin: 10px;
p20-10padding: 20px 10px;
w100pwidth: 100%;
bgc#fffbackground-color: #fff;
fwbfont-weight: bold;
tactext-align: center;
bdrs50pborder-radius: 50%;
dfdisplay: flex;

CSS abbreviations use fuzzy search. Typing pos:a matches position: absolute, and pos:r matches position: relative. The part before the colon matches a property name, and the part after matches a value.

Expand abbreviations

There are three ways to expand an Emmet abbreviation:

Tab key

Set emmet.triggerExpansionOnTab to true in settings. Type an abbreviation and press Tab.

Enter from the suggestion list

As you type, Emmet suggestions appear in the IntelliSense list. Press Enter on one to expand it.

Emmet: Expand Abbreviation command

Run it from the Command Palette. You can bind it to any keyboard shortcut.

The suggestion list shows a live preview of the expanded abbreviation in the documentation panel. This helps you verify the output before you commit.

Wrap existing text with Emmet

Select some text, open the Command Palette, and run Emmet: Wrap with Abbreviation. Type your abbreviation and press Enter. The selected text is placed inside the expanded structure.

For example, select three lines of text and wrap with ul>li*:

htmlhtml
<ul>
    <li>First selected line</li>
    <li>Second selected line</li>
    <li>Third selected line</li>
</ul>

Enable Emmet in other file types

To use Emmet in JSX inside .js files, in Vue single-file components, or in other file types where it is not active by default, add the emmet.includeLanguages setting:

jsonjson
"emmet.includeLanguages": {
  "javascript": "javascriptreact",
  "vue-html": "html",
  "plaintext": "pug"
}

The left side is the language ID of the file you are editing. The right side is the Emmet-supported language whose syntax rules to use.

Language IDs are not always the same as file extensions. To find the correct language ID, open the file and look at the language indicator in the Status Bar. Click it to see the list of available language identifiers.

Emmet with multiple cursors

Emmet abbreviations can be expanded independently at each cursor. Place multiple cursors across different lines, type the same abbreviation at each one, and expand. Every cursor gets its own expansion. Combined with auto-numbering, this is a fast way to generate repeated but varied markup.

Customize Emmet output

Add to your settings to control how abbreviations expand:

jsonjson
"emmet.syntaxProfiles": {
  "html": {
    "attr_quotes": "single"
  }
}

This changes all HTML attribute quotes from double to single.

Useful abbreviation reference

What you wantAbbreviation
HTML5 boilerplate!
Div with class.classname
Div with ID#idname
Link taglink:css
Script tag with srcscript:src
Form with input and buttonform>input:text+button:submit
Table with header and rowstable>tr>th3^^tr3>td*3
Inline style tagstyle
Meta viewportmeta:vp

The full reference is available at the Emmet Cheat Sheet.

Rune AI

Rune AI

Key Insights

  • Emmet is built into VS Code. No extension installation needed. It works in HTML, CSS, JSX, Pug, and other markup files by default.
  • Key abbreviations: ! for HTML5 skeleton, .class for div with class, #id for div with id, > for child, + for sibling, *N for repetition, $ for numbering.
  • Press Tab (with emmet.triggerExpansionOnTab) or Enter to expand an abbreviation. The suggestion list shows a live preview as you type.
  • Use Emmet: Wrap with Abbreviation from the Command Palette to wrap existing text or code in new HTML structure.
  • Enable Emmet in other file types with emmet.includeLanguages: add mappings like "javascript": "javascriptreact" for JSX support.
RunePowered by Rune AI

Frequently Asked Questions

Does Emmet work in JSX and React files?

Yes, but you need to enable it. Open settings and add "javascript": "javascriptreact" to emmet.includeLanguages. This tells VS Code to treat JavaScript files as JSX for Emmet expansion. Emmet abbreviations will then trigger inside your JSX markup.

How do I expand Emmet abbreviations with Tab instead of Enter?

Set emmet.triggerExpansionOnTab to true in your settings. After that, type any abbreviation and press Tab to expand it. Tab still works for indentation when the text is not an Emmet abbreviation.

Why is my Emmet abbreviation not expanding?

First, check you are in a supported file type (HTML, CSS, JSX, etc.). Second, check if Emmet has been accidentally disabled. In the Extensions view, search for @builtin and make sure the Emmet extension is enabled. Third, if you have custom snippets, make sure your snippets.json syntax is correct.

How do I wrap existing text in an HTML tag with Emmet?

Select the text, open the Command Palette, and run Emmet: Wrap with Abbreviation. Type the abbreviation like div.container>p and press Enter. The selected text is wrapped inside the expanded structure.

Conclusion

Emmet turns short CSS-like expressions into full HTML and CSS. It is built into VS Code with no extension needed. Type a CSS selector-like abbreviation, press Tab or Enter, and watch it expand. Use multiplication for repeated elements, curly braces for text content, and id and class shortcuts. Enable it in JSX and Vue files with the emmet.includeLanguages setting.