Skip to main content

Command Palette

Search for a command to run...

Emmet for HTML

A Beginner’s Guide to Writing Faster Markup

Updated
8 min readView as Markdown
Emmet for HTML

The Problem: Why Raw HTML Typing Feels Slow

Imagine you're starting a new web project. You open your code editor and immediately need to write this:

<div class="container">
  <div class="header">
    <h1></h1>
  </div>
  <div class="main">
    <ul>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </div>
</div>

Typing all those opening and closing tags, indenting properly, and remembering what closes where—it's tedious and easy to mess up. You keep hitting the same keys over and over again. The more HTML you write, the more repetitive it becomes. What if you could do this in a few keystrokes instead?

That's where Emmet steps in.


What Is Emmet?

Emmet is a shortcut language built into most modern code editors. Think of it as a super-efficient abbreviation system that expands tiny snippets of code into full HTML tags.

You type a short abbreviation → you press Tab or Enter → Emmet expands it into complete HTML.

For example:

  • You type: div

  • You press Tab

  • You get: <div></div>

Emmet is not a replacement for HTML. It's a helper tool that speeds up the process of writing HTML. The HTML it generates is completely normal, standard HTML that your browser reads exactly the same way as if you typed it by hand.


Why Emmet Matters for Beginners

Learning to use Emmet early gives you three real advantages:

1. Your fingers get tired less. Instead of typing dozens of characters for each tag, you type a few. Over the course of a project, this saves you minutes (or hours) of typing.

2. Fewer typos. When Emmet generates tags, they're always correctly paired—no forgotten closing tags, no mismatched brackets. You stay focused on logic instead of syntax details.

3. Better focus on structure. When you're not worried about typing speed or syntax errors, you can think more about what your HTML should look like. You can design your page structure faster and more confidently.

Think of it like learning shortcuts in a video game. At first, you might do everything manually. But once you learn the shortcuts, you play faster and with less frustration.


How Emmet Works Inside Your Code Editor

Emmet comes built-in with most modern code editors. If you're using VS Code (which is free and very popular), Emmet is already installed and ready to use. The same goes for Sublime Text, Atom, and many others.

Here's how it works:

  1. You type an abbreviation in an HTML file. For example: div.container

  2. You press Tab (or Enter) to expand it.

  3. Emmet instantly converts your abbreviation into complete HTML: <div class="container"></div>

In VS Code, the default trigger key is Tab. If Tab doesn't work, it might not be enabled yet—but don't worry, it usually is by default.


Basic Emmet Syntax

Emmet uses a syntax similar to CSS selectors. If you've ever written CSS, you already recognize most of it. Let's introduce the building blocks one at a time.

Creating HTML Elements

The simplest abbreviation is just the element name.

AbbreviationExpands To
p<p></p>
h1<h1></h1>
div<div></div>
section<section></section>

That's it. Type the tag name and press Tab. Emmet turns it into a complete HTML tag.

Try it yourself: Open VS Code, create a new file (save it as .html), type p, and press Tab. You should see <p></p> appear instantly.


Creating HTML Elements with Content

You can add text inside a tag using curly braces {}.

AbbreviationExpands To
h1{Hello World}<h1>Hello World</h1>
p{This is a paragraph}<p>This is a paragraph</p>
a{Click me}<a href="">Click me</a>
button{Submit}<button>Submit</button>

The text goes directly inside the opening and closing tags. This is super useful for buttons, links, and headings where you want immediate content.


Adding Classes and IDs (The CSS Connection)

This is where Emmet gets really intuitive because it borrows directly from CSS.

In CSS, you write .classname for classes and #idname for IDs. Emmet uses the exact same syntax to add these attributes to your HTML elements.

Adding a Single Class

AbbreviationExpands To
div.container<div class="container"></div>
button.btn<button class="btn"></button>
p.intro<p class="intro"></p>

Adding an ID

AbbreviationExpands To
div#header<div id="header"></div>
section#main<section id="main"></section>
input#email<input id="email">

Adding Multiple Classes

You can chain multiple class names together:

AbbreviationExpands To
div.container.dark.bold<div class="container dark bold"></div>
button.btn.btn-primary<button class="btn btn-primary"></button>

Combining Classes and IDs

AbbreviationExpands To
div#navbar.sticky.dark<div id="navbar" class="sticky dark"></div>
section#hero.bg-light<section id="hero" class="bg-light"></section>

Nested Elements (Boxes Inside Boxes)

In real HTML, elements are often nested inside each other, like boxes within boxes. Emmet uses the > symbol (the child operator) to show this nesting.

Think of > as "goes inside."

Simple Nesting

AbbreviationExpands To
div>p<div><p></p></div>
ul>li<ul><li></li></ul>
section>h2<section><h2></h2></section>

Deeper Nesting (Multiple Levels)

You can chain > operators to nest deeper:

AbbreviationExpands To
div>ul>li<div><ul><li></li></ul></div>
section>article>p<section><article><p></p></article></section>

Here's a more realistic example:

Abbreviation:

nav>ul>li>a{Home}

Expands to:

<nav>
  <ul>
    <li>
      <a href="">Home</a>
    </li>
  </ul>
</nav>

The editor automatically indents everything for you, making it readable immediately.


Repeating Elements Using Multiplication

When you need the same element multiple times, use the * symbol (the multiplication operator) followed by a number.

Think of * as "repeat this."

Basic Repetition

AbbreviationExpands To
li*3Three <li></li> items in a row
div*5Five empty <div></div> containers
p*2Two <p></p> paragraphs

Here's what li*3 actually produces:

<li></li>
<li></li>
<li></li>

Repetition Inside a Parent

This is where multiplication gets really powerful. Combine > (nesting) with * (repetition):

Abbreviation:

ul>li*5

Expands to:

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

Emmet automatically puts all five items inside the <ul> tag. You get a complete list structure in one abbreviation.

Adding Classes to Repeated Elements

Combine everything you've learned so far:

Abbreviation:

ul>li.item*4

Expands to:

<ul>
  <li class="item"></li>
  <li class="item"></li>
  <li class="item"></li>
  <li class="item"></li>
</ul>

Each li gets the class automatically applied.


Siblings (Elements Next to Each Other)

Sometimes you want elements at the same level, not nested inside each other. Use the + symbol (the sibling operator) to place elements side by side.

Think of + as "and then."

Simple Siblings

AbbreviationExpands To
div+p<div></div><p></p>
header+main+footerThree separate elements at the same level

Here's a more realistic example:

Abbreviation:

header+main+footer

Expands to:

<header></header>
<main></main>
<footer></footer>

Combining Nesting and Siblings

You can mix > and + to build real page structures:

Abbreviation:

header>nav>ul>li*3+footer

This means: a header with a nested navigation structure containing a list, plus a footer at the bottom.

Expands to:

<header>
  <nav>
    <ul>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </nav>
</header>
<footer></footer>

HTML Boilerplate

Here's the one Emmet abbreviation that every beginner should know: the exclamation mark !

When you're starting a new HTML file, type just ! and press Tab.

Expands to:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

</body>
</html>

You get a complete, modern HTML5 boilerplate in a single keystroke. This is something you'll use every single day. Instead of copying and pasting (or remembering the structure), you just type ! and you're ready to start building.

After Emmet expands it, you can customize the <title> tag and add your content to the <body>. Everything else is already correct.


Putting It All Together: Real Examples

Now that you've learned each piece, let's build some real page structures.

Example 1: A Simple Navigation Bar

What you type:

nav.navbar>ul.nav-list>li.nav-item*4>a.nav-link{Home}

What you get:

<nav class="navbar">
  <ul class="nav-list">
    <li class="nav-item">
      <a class="nav-link" href="">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="">Home</a>
    </li>
  </ul>
</nav>

You'd then go back and edit the link text to be different (Home, About, Services, Contact), but the structure is done instantly.

Example 2: A Basic Card Component

What you type:

div.card>div.card-header>h3{Title}+div.card-body>p{Description}

What you get:

<div class="card">
  <div class="card-header">
    <h3>Title</h3>
  </div>
  <div class="card-body">
    <p>Description</p>
  </div>
</div>

Example 3: A Form with Multiple Fields

What you type:

form>div.form-group*3>label{Label}+input[type=text]

What you get:

<form>
  <div class="form-group">
    <label>Label</label>
    <input type="text">
  </div>
  <div class="form-group">
    <label>Label</label>
    <input type="text">
  </div>
  <div class="form-group">
    <label>Label</label>
    <input type="text">
  </div>
</form>

A Few More Useful Tricks

As you get comfortable with the basics, here are a few more patterns you'll naturally encounter:

Adding Custom Attributes

Use square brackets [attr=value] to add any attribute:

AbbreviationExpands To
input[type=email]<input type="email">
img[src=photo.jpg][alt=My Photo]<img src="photo.jpg" alt="My Photo">

Numbering Repeated Items

Use $ to auto-number repeated elements:

Abbreviation:

li.item$*5

Expands to:

<li class="item1"></li>
<li class="item2"></li>
<li class="item3"></li>
<li class="item4"></li>
<li class="item5"></li>

Each item gets a unique number automatically.


You Can Always Type It By Hand

Here's the most important thing to remember: Emmet is optional. You don't have to use it. If you ever feel confused or prefer typing something out, that's completely fine. Emmet is a productivity tool, not a requirement.

Some beginners find Emmet instantly helpful. Others prefer to master HTML basics first, then add Emmet to their workflow later. Both approaches are valid. The goal is becoming comfortable and confident writing HTML.


Key Takeaway

Emmet is a helper that turns tedious HTML typing into quick, efficient abbreviations. It respects your code (the HTML is always valid), it reduces errors, and it lets you focus on what matters: building great web pages. Start with the basics—element names, classes, nesting, and repetition—and you'll already be writing HTML twice as fast. Everything else is bonus.