Skip to main content

Command Palette

Search for a command to run...

Emmet: Write HTML at the Speed of Thought

Published
6 min read

The Problem: HTML Typing Fatigue

Picture this: You're building a navigation menu. Without shortcuts, you type:

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

That's 87 keystrokes (including tabs and newlines). Your fingers hurt, your flow is broken, and you've spent 30 seconds on something that should take 3 seconds.

There has to be a better way.


What is Emmet?

Emmet is a shortcut language (plugin/tool) built into most code editors (VS Code, Sublime, WebStorm). It lets you write abbreviations that instantly expand into full HTML.

Think of it like text expansion or HTML autocorrect on steroids.

The magic: You type CSS-selector-like syntax, hit Tab (or Enter), and Emmet writes the HTML for you.


Why Beginners Love Emmet

  1. Speed: Write 5 characters, get 50 characters of HTML

  2. Fewer Typos: No more forgetting closing tags or mismatched brackets

  3. Focus: Keep your mind on structure, not syntax

  4. Muscle Memory: Uses CSS selector syntax you already know

  5. Built-in: Works in VS Code out of the box—no installation needed

Important: Emmet is optional. It's a power tool, not a requirement. But once you use it, you'll never go back.


The Basic Workflow


Lesson 1: Creating Elements

The simplest form: type the tag name, hit Tab.

EmmetExpands To
div<div></div>
p<p></p>
h1<h1></h1>
img<img src="" alt="">
input<input type="text">

Try it: Open any HTML file and type h2, then press Tab. Boom—heading ready.


Lesson 2: Classes and IDs (The Daily Drivers)

This is where Emmet shines. Use CSS selector syntax:

EmmetExpands To
div.header<div class="header"></div>
#main<div id="main"></div>
button.btn.primary<button class="btn primary"></button>
p.lead#intro<p class="lead" id="intro"></p>

Pro Tip: If you omit the tag name for classes/IDs, Emmet assumes div:

  • .container<div class="container"></div>

  • #wrapper<div id="wrapper"></div>


Lesson 3: Adding Attributes

Use square brackets [] for any attribute:

EmmetExpands To
a[href="#"]<a href="#"></a>
img[src="photo.jpg" alt="Beach"]<img src="photo.jpg" alt="Beach">
input[type="email" required]<input type="email" required>
td[colspan="2"]<td colspan="2"></td>

Lesson 4: Nesting (The > Symbol)

Use > to create parent > child relationships:

Emmet:

Expands To:

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

Going Deeper:

Becomes a header with nav containing a 5-item list (we'll cover the * next).


Lesson 5: Multiplication (*) - The Time Saver

Need 5 list items? Don't copy-paste. Multiply!

Emmet:

Expands To:

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

Real-World Combo:

Creates 5 navigation links at once:

<ul class="nav">
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>
    <li><a href="#"></a></li>
</ul>

Lesson 6: Siblings (+) and Climbing (^)

Sometimes you need elements at the same level:

EmmetMeaningResult
header+main+footerSiblingsThree separate sections
div>h1^pClimb upp is sibling of div, not child of h1

Example:

Creates:

<article>
    <h1></h1>
    <div class="content"></div>
    <p></p>
</article>

Lesson 7: The HTML Boilerplate (!)

This is the #1 most useful Emmet command for beginners.

Type ! 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>

Instant starting point for every project.


Putting It All Together: Real Examples

Example 1: Blog Post Card

Result:

<article class="card">
    <h2 class="title"></h2>
    <img src="pic.jpg" alt="">
    <p class="excerpt"></p>
    <a href="#">Read More</a>
</article>

Note: Curly braces {} add text content.

Example 2: Contact Form

Result:

<form action="" class="contact">
    <div>
        <label for=""></label>
        <input type="text">
    </div>
    <div>
        <label for=""></label>
        <input type="text">
    </div>
    <div>
        <label for=""></label>
        <input type="text">
    </div>
</form>

The Emmet Mindset: Build Top-Down

Think of your HTML structure like CSS selectors:

  1. Big container first (.container)

  2. Add children (>header)

  3. Add siblings (+main+footer)

  4. Multiply repeated patterns (*4)

  5. Add attributes ([src=""])


Quick Reference Cheat Sheet

PatternResultUse Case
tag<tag></tag>Basic element
.class<div class="class">Class shorthand
#id<div id="id">ID shorthand
>Child nestingStructure
+SiblingSame-level elements
*MultiplicationLists, grids
[]AttributesLinks, images
{}Text contentLabels, buttons
!Full HTML docStarting new file

Common Beginner Mistakes

  1. Forgetting to press Tab: Emmet only works with the expansion key (usually Tab)

  2. Spaces: Emmet abbreviations cannot contain spaces (until you get to advanced syntax)

  3. Invalid Nesting: div>p>a> (trailing >) will break—make sure every > has a child

  4. Wrong File Type: Emmet works best in .html files or HTML sections of frameworks


Practice Challenge

Try expanding this single line:

What does the $ do? It numbers your items: Link 1, Link 2, Link 3, Link 4!


Conclusion: Your New Superpower

Emmet isn't cheating—it's working smart. As a beginner, you should still understand the HTML you're generating, but Emmet removes the friction of typing angle brackets.

Start small:

  • Today: Use ! for boilerplate

  • Tomorrow: Use div.class shortcuts

  • Next week: Build full components with > and *

Remember: Every second you save typing <div></div> is a second you can spend learning CSS Grid or JavaScript.