Skip to main content

Command Palette

Search for a command to run...

Emmet for HTML: A beginner’s guide to writing faster markup

Updated
4 min read
Emmet for HTML: A beginner’s guide to writing faster markup

If you’ve ever spent an afternoon building a website, you know the feeling: your fingers are tired from typing < and > a thousand times. Writing HTML manually can feel like building a skyscraper one literal brick at a time. It’s slow, it’s repetitive, and it’s very easy to forget to close a tag, which breaks your entire layout.

Enter Emmet.

Emmet is the ultimate "cheat code" for web developers. It is a plugin (built into most modern editors like VS Code) that allows you to type short, CSS-like snippets and expand them into full blocks of HTML with a single tap of the Tab key. It turns minutes of typing into seconds of shorthand.


What is Emmet, Really?

In simple terms, Emmet is a shorthand language. Instead of writing the full "formal" version of HTML, you write a tiny abbreviation. When you hit Tab, Emmet looks at your shortcut, recognizes the pattern, and "expands" it into the correct HTML code.

Think of it like texting "omw" instead of "I am on my way." Your phone (the editor) knows exactly what you mean and fills in the rest.


The Basics: Creating Elements

The simplest Emmet shortcut is just the name of the tag. If you want a paragraph tag, you don't need to type <p></p>.

The Shortcut: p

The Result (after hitting Tab): <p></p>

This works for almost every HTML tag: h1, div, section, footer, nav. You just type the word and Tab it into existence.


Adding Classes and IDs

If you’ve started learning CSS, you know that we use Classes (with a .) and IDs (with a #) to identify our elements. Emmet uses that exact same syntax.

Adding a Class

If you want a div with a class of "container":

  • Abbreviation: div.container

  • Result: <div class="container"></div>

Adding an ID

If you want a header with an ID of "main-title":

  • Abbreviation: h1#main-title

  • Result: <h1 id="main-title"></h1>

You can even combine them! Typing div.box#hero will give you a div with both the class "box" and the ID "hero."


Nested Elements: Building Structures

This is where Emmet starts to feel like magic. You can describe the "family tree" of your HTML in a single line using the > symbol (which means "inside").

Imagine you want a navigation bar (nav) that contains an unordered list (ul), which contains a list item (li).

  • Abbreviation: nav>ul>li

  • Result:

<nav>
<ul>
<li></li>
</ul>
</nav>

Multiplication: Creating Lists Fast

One of the most annoying parts of HTML is writing repetitive lists. If you need five list items, you usually have to copy and paste. With Emmet, you just use the * (multiplication) symbol.

  • Abbreviation: ul>li*5

  • Result: Emmet will generate a ul with five li tags inside it instantly.


Attributes and Text

Need a link that points to Google? Or a paragraph that already has text inside it?

  • Attributes: Use square brackets [].

    • a[href="https://google.com"] expands to <a href="https://google.com"></a>.
  • Text Content: Use curly braces {}.

    • p{Hello World} expands to <p>Hello World</p>.

The Ultimate Shortcut: The Boilerplate

Every HTML file starts with the same "head" and "body" tags. Typing this out every time is a chore. In most editors, Emmet provides a global shortcut to generate the entire starting structure of a webpage.

The Shortcut: !
The Result: A full, valid HTML5 skeleton including the <!DOCTYPE>, <html>, <head>, and <body> tags.


Why Every Beginner Should Use It

You might think, "Shouldn't I learn to type it the long way first?"

While it's important to understand the structure, using Emmet actually helps you learn. Because Emmet uses CSS-style syntax (dots for classes, hashes for IDs), it reinforces the relationship between your HTML structure and your CSS styling. Plus, it prevents "syntax errors"—Emmet never forgets to close a tag or add a closing bracket.

How to Practice

  1. Open VS Code.

  2. Create a file named index.html.

  3. Type ! and hit Tab.

  4. Inside the <body>, try typing div.wrapper>h2{Welcome}+p*3 and hit Tab.