Skip to main content

Command Palette

Search for a command to run...

Emmet for HTML: A Beginner’s Guide to Writing Faster Markup

Published
4 min read

Let’s be honest: writing plain HTML can feel incredibly tedious.

Every time you want to create a simple paragraph, your fingers have to perform a gymnastics routine: Shift + <, type p, Shift + >, type your text, Shift + <, /, p, Shift + >.

Doing that hundreds of times a day is exhausting. It slows down your thought process and turns building a webpage into a typing test.

Enter Emmet.


What is Emmet?

Emmet is a plugin built directly into most modern code editors (like VS Code). Think of it as a shortcut language or text-expansion tool for HTML and CSS.

Instead of typing out every single bracket and closing tag, you type a tiny abbreviation, press the Tab key (or Enter), and Emmet instantly expands it into perfect, flawlessly formatted HTML.

  • Is it mandatory? No. You can write websites without it.

  • Should you use it? Absolutely. It will save you hundreds of hours over your development career.

Let’s look at how it works inside your editor, starting with the most famous trick of all.

The Magic Trick: The HTML Boilerplate

Before you write a single line of code, every HTML file needs a skeleton (the <!DOCTYPE html>, <html>, <head>, and <body> tags). Writing this from memory is a pain.

With Emmet, you only need one character:

You Type: ! (Then press Tab)

Emmet Expands To:

HTML

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

Boom. In one keystroke, your page is ready to go.

The Basic Syntax: One Concept at a Time

Emmet abbreviations look a lot like CSS selectors. Let's break down the daily-use patterns you need to know. I highly encourage you to open VS Code right now and try typing these out!

1. Creating Basic Elements

To create any HTML tag, just type the name of the tag and hit Tab. No brackets required.

  • Type: h1

  • Expands to: <h1></h1>

  • Type: button

  • Expands to: <button></button>

2. Adding Classes and IDs

If you are using a utility-first framework like Tailwind CSS, adding multiple classes manually is frustrating. Emmet uses the dot (.) for classes and the hashtag (#) for IDs.

  • Type: div.bg-blue-500.p-4.text-white

  • Expands to: ```html

<div class="bg-blue-500 p-4 text-white"></div>


  * **Type:** `nav#main-menu`
  * **Expands to:** \`\`\`html

&lt;nav id=&quot;main-menu&quot;&gt;&lt;/nav&gt;

3. Adding Custom Attributes ([])

Need to add a source to an image or a placeholder to an input? Use square brackets.

  • Type: img[src="logo.png" alt="Company Logo"]

  • Expands to: ```html

<img src="logo.png" alt="Company Logo">


-----

## 🪆 Next-Level Emmet: Building Structures

Creating single tags is great, but Emmet's true power shines when you build nested structures.

### Nesting Elements (`>`)

The greater-than sign tells Emmet to put the next element *inside* the previous one.

  * **Type:** `header>nav>ul`
  * **Expands to:**

<!-- end list -->

```html
<header>
    <nav>
        <ul></ul>
    </nav>
</header>

Multiplication (*)

Need to make a list of your top 3 favorite cricket players or news articles? Don't copy and paste. Multiply!

  • Type: ul>li*3

  • Expands to:

HTML

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

Adding Text ({})

You can even inject the text directly into the HTML using curly braces.

  • Type: button.btn-primary{Click Me!}

  • Expands to:

HTML

<button class="btn-primary">Click Me!</button>

The Ultimate Combo

Once you understand these basic puzzle pieces, you can combine them to generate entire sections of a website in seconds.

Let's say we want a div containing a heading and a list of three items.

The Workflow Flow:

Plaintext

Type this abbreviation:
div.card>h2{Daily News}+ul>li.news-item*3

Press Tab!

The Final HTML:

HTML

<div class="card">
    <h2>Daily News</h2>
    <ul>
        <li class="news-item"></li>
        <li class="news-item"></li>
        <li class="news-item"></li>
    </ul>
</div>

Summary

When you first start using Emmet, it might actually feel a little slower as you stop to think about the syntax. Do not give up. Treat Emmet like learning to touch-type. It takes a few days of practice to build the muscle memory, but once it clicks, you will never want to write HTML without it again.