As in, does Visual Studio Code, the free code editor from Microsoft, work with Emmet, the free and open source code expansion tool? The answer is of course! In fact, you don’t have to do anything at all to get it going. Emmet is built-in to VS Code.
Let’s take a look at what Emmet can do and some VS Code specific stuff to make the most of it.
In this article, I’ll use ⌘ to denote the command key on Apple and the control key on Windows. I’ll also use ⇧ for the shift key.
What Is Emmet?
Emmet is a code expansion tool that is designed to dramatically speed up the creation of HTML and CSS.
It works like this. Say you wanted to create a div. Normally, you would type out each character:
< … d … i … v … >
Your text editor might even help autocomplete that tag name for you. Then to close it, you might only have to type a new angle bracket (<) and it will offer to complete the closing tag.
This is not a bad way to compose HTML, but when you’re working in HTML, you’re probably writing many more tags than that, which means that you’re opening and closing a lot of angle brackets. Those angle brackets can really slow you down and make the creation of HTML tedious.
This is where Emmet comes in.
Emmet allows you to simply type div
and hit the tab key. It is automatically expanded out into a full HTML div tag.

This works for any HTML tag. You can add an id with a #
, a class with a .
, and attributes with [foo]
. It’s happy to do multiple of each!

In fact, if you are working with a div, you don’t even need to specify the div tag. You can just start with the id or class and you will get a div by default. Emmet is even smart enough to change that to a <span>
if you are within another inline-by-default element.

Quite complex markup can be composed this way. You can use >
to specify going down a level and +
to specify items at the same level. Take for example a Bootstrap Navbar. The markup a navbar might look like this:
<nav class="navbar">
<a class="navbar-brand" href="#">Navbar</a>
<div class="navbar-nav">
<a class="nav-item nav-link" href="#">Home</a>
<a class="nav-item nav-link" href="#">Features</a>
<a class="nav-item nav-link" href="#">Pricing</a>
</div>
</nav>
We can generate this whole block with Emmet like this:

There’s a lot going on there in terms of Emmet syntax. The best way to learn it is to grab the Emmet Syntax Cheat Sheet.
You can also incorporate Lorem Ipsum into the generated markup as needed.
You probably noticed that I was able to auto-generate 3 anchor tags and that when I expanded all of it out into HTML, I got tab stops on all my anchor tags and href
attributes. This allows you to quickly create a block of HTML and then go and add specifics to each item.
There is another ( dare I say cooler) way to do this though 😎. It’s called “Wrap Individual Lines”.
Wrap Individual Lines With Abbreviation
If we back up to the example above, what we really want is a navbar with Home, Features, and Pricing links. We can add that text after we generate the markup with Emmet, or we can do it before using the “Wrap Individual Lines With Abbreviation” command.
Invoke the command pallet (⌘ + ⇧ + P) and select “Wrap Individual Lines”. We enter the exact same Emmet syntax that we had before, but this time we stop at the *
as this is where Emmet will insert our lines.

There is also a “Wrap With Abbreviation” that will wrap a single line without having to select anything. This is particularly useful when wrapping links. Simple paste a URL in, invoke the command, hit “a” and then hit enter.
🔥 Hot Tip
Map a keyboard shortcut to the “Wrap With Abbreviation” command. This makes it super quick to create things like anchors.

Emmet In Other File Types
By default, Emmet works on HTML and CSS — and that includes preprocessors/template languages. Out of the box, you get support in html, haml, jade, slim, jsx, xml, xsl, css, scss, sass, less and stylus. The docs also mention that you get it in any file type that inherits from the above file types — such as php.
CSS
Emmet also works in CSS. It works with a search technique called Fuzzy search which matches what you are trying to express with few characters. For example df
expands into display: flex;
and w100p
expands in width: 100%;
.
These work in different CSS files types, like Sass, where it knows not to insert semicolons in the `.sass` syntax.
File type inheritence
Unfortunately, there is no way to know which files inherit from an existing language type. For instance, Emmet does not work in Markdown files because Markdown does not inherit from any of the known types. Even though HTML is perfectly valid in Markdown files.
To fix this, we can add a language mapping so Emmet knows to behave properly in Markdown files. Add the following line to the User Settings file.
To jump to User Settings quickly, press ⌘, (command comma).
"emmet.includeLanguages": {
"markdown": "html"
}
Now we’ve mapped Markdown to HTML so Emmet knows how to treat the file. Well, almost. If we open up a Markdown file, you’ll notice that Emmet is working, but not like we would expect. If I type div
and press tab, nothing happens. If I type div
and then an *
, Emmet tries to kick in via the suggestions menu.

That’s not good because Markdown uses asterisks for headers. Emmet is going to intercept those every time. The reason this is happening is that VS Code is trying to prevent the tab key from clobbering some other function that the tab key might serve in a document of this type.
To get around this, we can add the following line to our User Settings:
"emmet.triggerExpansionOnTab": true
Now the div expansion will work on tab, but the asterisks still fire the Emmet suggestion window. My suggestion is to turn that window off completely with the following line in User Settings:
"emmet.showExpandedAbbreviation": "never"

This also works for languages like React and Vue. While Emmet works by default in JSX files, we can make it work in JSX in regular JavaScript too. Add this mapping to your User Settings:
"emmet.includeLanguages": {
"javascript": "javascriptreact"
}
Creating Your Own Snippets
You can also create your own Emmet snippets.
For example, you could expand Emmet’s SVG capability by creating a custom snippet like rect
that maps to rect[x][y][width][height]
and thus expand into:
<rect x="" y="" width="" height=""></rect>
More information about that can be found in the official VS Code documentation. This is how CodePen custom snippets work under the hood as well!
More Emmet Resources
If you’d like to learn more about Emmet, here are some other resources for getting started:
Is there really people discovering zen coding in 2017 ?
apparently yes. This is news to me. Thanks for the post, Burke.
Believe it or not, beginners exist!
Yes! While I discovered it sometime back, it came to my attention that there are a lot of developers who are either just getting started, or they just haven’t come across it yet. We’re all learning!
Wow, this is a really helpful article. Thanks for sharing.
Glad you liked it and thank you for taking the time to comment!
I like emmet but still prefer the original name for it. I’ve been using it for a while but I didn’t know about the wrap lines feature!
I’m with you. I thought Zen was a better name. But you know what they say about naming things…
I think it might have been a legal issue.
To AlienSKP: https://xkcd.com/1053/
I really like VSCode but I cannot start using it because of the css.fuzzySearch lack support by emmet. I really need the ‘pos-a’ trigger for ‘position: absolute;’ result and other like this example.
Here you can read that is not included the css.fuzzySearch customization yet.
It is the last thing that keeps me working with SublimeText. Also, the app opening speed (I use OS X 10.12.6). Sublime opens within 2 seconds and VSC needs at least 5 seconds…
Looks like fuzzy search, in general, is an issue that is being worked on. I think it affects Emmet, intellisense as well. It looks like they’ve made some changes in October so perhaps we’ll see it in a release quite soon.
Thank you for the info! I wish for a future update to solve it :)
Actually css.fuzzySearch is supported out of the box. That is why
dn
expands todisplay: none
. In your case,posa
orpos:a
will expand toposition: absolute
In css abbreviations, when you use
:
, the left part is used to match with the css property name and the right part is used to match with css property value.Wow! Thank you, Ramya! I didn’t think to use a colon. It does indeed look like fuzzy search is working like a champ.
Thank you Ramya, I will try use
:
(semicolon) instead of-
(dash). Because when codingd-n
by pressing TAB it returns:double-button
rule.I almost switched back to sublime text because because
php
didn’t expand to<?php ?>
but then realized this is not Emmet, it’s sublime. So I’ve added the custom rule. Thanks :)Nice! Glad you’re still with us…
You got me wrong. I was not making fun of noobs at all. I’m just surprised if it is still unknown to so much people.. Sorry for behaving like an ol’ f#ck!
It’s been here for like nearly 10 years, so “What is Emmet” sounds to me like “What is jQuery”, knowamean ?
Anyway. Let’s go to the grocery store!
No worries at all! I appreciate you taking time to comment and also for coming back and clarifying. That’s classy and I dig it.
Cool, thank you so much for this great article. That would save lots of time but I wonder if Emmet could do a live Wrap preview in VSCode as in Sublime Text?
Hey Josh! This is a great question. I assume you’re referring to something like this? Right now I think this is handled in the command palette via the “Wrap With Abbreviation”, but there is no preview. There is currently an open issue to implement this, so we may see it sooner than later!
Hey Burke! That’s it, wrap abbreviation in real-time which is currently in Sublime Text only. That would be awesome to implement this in VSCode!