Skip to main content

Command Palette

Search for a command to run...

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

Updated
12 min read
Emmet for HTML: A Beginner's Guide to Writing Faster Markup

Imagine you want to create a simple webpage with a header, some content, and a footer. Without Emmet, you'd have to type every single character:

<div>
  <h1>Welcome</h1>
  <p>This is a paragraph.</p>
  <ul>
    <li>Item one</li>
    <li>Item two</li>
    <li>Item three</li>
  </ul>
</div>

That's a lot of typing! You have to:

  • Type every opening tag

  • Type every closing tag

  • Make sure brackets match

  • Indent everything properly

  • Remember all the syntax

It's slow, repetitive, and easy to make mistakes. What if there was a faster way?

What Emmet Is (In Very Simple Terms)

Emmet is like a shortcut language for writing HTML (and CSS). Instead of typing out all the HTML code manually, you write a short abbreviation, and Emmet automatically expands it into full HTML code.

Think of it like text shortcuts on your phone:

  • You type "omw" and it becomes "On my way!"

  • You type "brb" and it becomes "Be right back!"

Emmet works the same way, but for HTML code.

Simple Example:

You type: div

Emmet expands to: <div></div>

That's it! You write a short abbreviation, press a key (usually Tab), and Emmet turns it into complete HTML.

The Magic:

Instead of typing:

<div></div>

You just type:

div

And press Tab. Emmet does the rest!

Why Emmet Is Useful for HTML Beginners

Emmet is incredibly useful, especially when you're learning HTML, because:

1. Saves Time

You write less code, so you can focus on learning and building instead of typing.

2. Reduces Mistakes

Emmet automatically creates correct HTML syntax, so you make fewer errors.

3. Helps You Learn

Seeing how abbreviations expand into HTML helps you understand HTML structure better.

4. Makes You Faster

Once you learn Emmet, you can write HTML much faster than typing everything manually.

5. Less Repetitive

No more typing the same opening and closing tags over and over.

Real Example:

Without Emmet:

  • Type: <div><p>Hello</p></div> (25 characters)

  • Time: ~5-10 seconds

  • Risk of typos: High

With Emmet:

  • Type: div>p (5 characters)

  • Press Tab

  • Time: ~1 second

  • Risk of typos: Low

That's 5 times faster!

How Emmet Works Inside Code Editors

Emmet is built into most modern code editors. Here's how it works:

The Workflow:

1. You type an Emmet abbreviation
         │
         ▼
2. Press Tab (or Enter, depending on editor)
         │
         ▼
3. Emmet expands the abbreviation
         │
         ▼
4. You get complete HTML code!

Visual Flow:

┌─────────────────────────────────────┐
│  You type: div                      │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Press Tab key                      │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Emmet expands:                     │
│  <div></div>                        │
└──────────────┬──────────────────────┘
               │
               ▼
         HTML is ready!

Where to Use Emmet:

Emmet works in:

  • VS Code (Visual Studio Code) - Most popular, recommended for beginners

  • Sublime Text

  • Atom

  • WebStorm

  • And many other editors

How to Activate:

In most editors, Emmet is already enabled by default! You don't need to install anything. Just:

  1. Open a new HTML file

  2. Type an Emmet abbreviation

  3. Press Tab

That's it!

VS Code Example:

  1. Create a new file and save it as index.html

  2. Type: div

  3. Press Tab

  4. You'll see: <div></div>

If it doesn't work, make sure:

  • The file is saved with .html extension

  • You're in a code editor (not a plain text editor)

  • Emmet is enabled (it usually is by default)

Basic Emmet Syntax and Abbreviations

Emmet uses simple abbreviations that look like CSS selectors. If you know CSS, Emmet will feel familiar!

The Basic Rule:

Element name = HTML tag

Just type the HTML element name, and Emmet creates that tag.

Basic Examples:

You TypeEmmet Expands To
div<div></div>
p<p></p>
h1<h1></h1>
span<span></span>
a<a href=""></a>
img<img src="" alt="">

Try It Yourself:

  1. Open your code editor

  2. Create a new HTML file

  3. Type p and press Tab

  4. Watch it expand to <p></p>

It's that simple!

Visual Example:

You type:  p
           │
           │ (Press Tab)
           ▼
Result:    <p></p>

Creating HTML Elements Using Emmet

Creating HTML elements with Emmet is straightforward. Just type the element name!

Single Elements:

You type: div
Press Tab
You get: <div></div>

You type: p
Press Tab
You get: <p></p>

You type: h1
Press Tab
You get: <h1></h1>

Elements with Content:

To add text content, use curly braces {}:

You type: p{Hello World}
Press Tab
You get: <p>Hello World</p>

You type: h1{Welcome}
Press Tab
You get: <h1>Welcome</h1>

Visual Flow:

┌─────────────────────────────────────┐
│  You type: p{Hello}                 │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Press Tab                          │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Result: <p>Hello</p>               │
└─────────────────────────────────────┘

Common Elements:

Try these in your editor:

  • div<div></div>

  • p{Text}<p>Text</p>

  • h1{Title}<h1>Title</h1>

  • a{Link}<a href="">Link</a>

  • img<img src="" alt="">

  • button{Click}<button>Click</button>

Adding Classes, IDs, and Attributes

Emmet makes it easy to add classes, IDs, and other attributes to elements.

Adding Classes:

Use a dot (.) to add a class:

You type: div.container
Press Tab
You get: <div class="container"></div>

You type: p.highlight
Press Tab
You get: <p class="highlight"></p>

Multiple Classes:

Add multiple classes with multiple dots:

You type: div.box.container
Press Tab
You get: <div class="box container"></div>

Adding IDs:

Use a hash (#) to add an ID:

You type: div#header
Press Tab
You get: <div id="header"></div>

You type: p#intro
Press Tab
You get: <p id="intro"></p>

Combining Class and ID:

You can use both class and ID together:

You type: div.container#main
Press Tab
You get: <div class="container" id="main"></div>

Adding Attributes:

Use square brackets [] to add any attribute:

You type: a[href="https://example.com"]
Press
Tab
You get: <a href="https://example.com"></a>

You type: img[src="photo.jpg"][alt="Photo"]
Press Tab
You get: <img src="photo.jpg" alt="Photo">

Visual Examples:

You type:  div.container
           │
           │ (Press Tab)
           ▼
Result:    <div class="container"></div>

─────────────────────────────────────

You type:  div#header
           │
           │ (Press Tab)
           ▼
Result:    <div id="header"></div>

─────────────────────────────────────

You type:  a[href="#"]
           │
           │ (Press Tab)
           ▼
Result:    <a href="#"></a>

Common Patterns:

  • div.container → Container div with class

  • div#main → Div with ID

  • div.container#main → Div with both class and ID

  • a[href="#"][target="_blank"] → Link with multiple attributes

  • img[src="pic.jpg"][alt="Image"] → Image with attributes

Creating Nested Elements

One of Emmet's most powerful features is creating nested (parent-child) elements easily.

The Greater Than Sign (>)

Use > to create parent-child relationships:

You type: div>p
Press Tab
You get:

<div>
  <p></p>
</div>

Visual Flow:

You type:  div>p
           │
           │ (Press Tab)
           ▼
Result:    <div>
             <p></p>
           </div>

Multiple Levels of Nesting:

You can nest multiple levels:

You type: div>ul>li
Press Tab
You get:

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

Deeper Nesting:

You type: div>section>article>p
Press Tab
You get:

<div>
  <section>
    <article>
      <p></p>
    </article>
  </section>
</div>

Nested Structure Diagram:

div>ul>li
│   │  │
│   │  └─ Child (li inside ul)
│   └──── Parent (ul inside div)
└──────── Grandparent (div)

Adding Content to Nested Elements:

You type: div>h1{Title}>p{Text}
Press Tab
You get:

<div>
  <h1>Title</h1>
  <p>Text</p>
</div>

Wait, that's not quite right. Let me show the correct way:

You type: div>h1{Title}+p{Text}
Press Tab
You get:

<div>
  <h1>Title</h1>
  <p>Text</p>
</div>

The + sign creates siblings (elements at the same level). We'll cover that next!

Siblings with Plus Sign (+)

Use + to create sibling elements (elements at the same level):

You type: div>h1+p
Press Tab
You get:

<div>
  <h1></h1>
  <p></p>
</div>

You type: div>h1{Title}+p{Text}
Press Tab
You get:

<div>
  <h1>Title</h1>
  <p>Text</p>
</div>

Complex Nested Example:

You type: div.container>header>h1{Logo}+nav>ul>li*3
Press Tab
You get:

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

(We'll learn about *3 for repeating elements next!)

Visual Nested Structure:

div>ul>li
│
├─ div (parent)
   │
   └─ ul (child of div)
      │
      └─ li (child of ul)

Repeating Elements Using Multiplication

Emmet lets you repeat elements using multiplication. This is super useful for lists!

The Asterisk (*)

Use * followed by a number to repeat an element:

You type: li*3
Press Tab
You get:

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

Visual Example:

You type:  li*3
           │
           │ (Press Tab)
           ▼
Result:    <li></li>
           <li></li>
           <li></li>

Common Use Cases:

List items: You type: ul>li*5
Press Tab
You get:

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

Multiple paragraphs: You type: div>p*3
Press Tab
You get:

<div>
  <p></p>
  <p></p>
  <p></p>
</div>

Adding Content to Repeated Elements:

Use $ to add numbers to repeated elements:

You type: li*3{$}
Press Tab
You get:

<li>1</li>
<li>2</li>
<li>3</li>

You type: li*3{Item $}
Press Tab
You get:

<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>

Visual Multiplication:

li*3
│  │
│  └─ Number of times to repeat
└──── Element to repeat

Complex Example with Multiplication:

You type: div>article*3>h2{Title $}+p{Content $}
Press Tab
You get:

<div>
  <article>
    <h2>Title 1</h2>
    <p>Content 1</p>
  </article>
  <article>
    <h2>Title 2</h2>
    <p>Content 2</p>
  </article>
  <article>
    <h2>Title 3</h2>
    <p>Content 3</p>
  </article>
</div>

Multiplication Flow:

┌─────────────────────────────────────┐
│  You type: ul>li*3                  │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Emmet understands:                  │
│  - Create ul                         │
│  - Inside ul, create 3 li elements  │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Result:                             │
│  <ul>                                │
│    <li></li>                         │
│    <li></li>                         │
│    <li></li>                         │
│  </ul>                               │
└─────────────────────────────────────┘

Generating Full HTML Boilerplate with Emmet

One of the most useful Emmet features is generating a complete HTML document structure instantly.

The HTML Boilerplate:

You type: !
Press Tab
You get:

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

That's it! One character (!) gives you a complete HTML5 document structure.

Visual Flow:

┌─────────────────────────────────────┐
│  You type: !                        │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Press Tab                          │
└──────────────┬──────────────────────┘
               │
               ▼
┌─────────────────────────────────────┐
│  Complete HTML5 boilerplate!        │
│  (DOCTYPE, html, head, body, etc.)  │
└─────────────────────────────────────┘

What You Get:

  • <!DOCTYPE html> - Document type declaration

  • <html> - Root element

  • <head> - Head section with meta tags

  • <body> - Body section where your content goes

  • All the essential tags ready to use

Customizing the Boilerplate:

You can also customize it:

You type: html:5
Press Tab
You get: Same HTML5 boilerplate

You type: html:xt
Press Tab
You get: XHTML transitional boilerplate

But for most beginners, just ! is perfect!

Emmet Workflow Inside a Code Editor

Here's how Emmet works in your daily coding workflow:

Step-by-Step Workflow:

1. Open your code editor (VS Code recommended)
         │
         ▼
2. Create a new HTML file
         │
         ▼
3. Type Emmet abbreviation
         │
         ▼
4. Press Tab to expand
         │
         ▼
5. Edit the expanded HTML as needed
         │
         ▼
6. Repeat for more elements

Visual Workflow:

┌─────────────────────────────────────┐
│  Editor: index.html                │
│                                     │
│  [Empty file]                       │
└──────────────┬──────────────────────┘
               │
               ▼ Type: !
┌─────────────────────────────────────┐
│  Editor: index.html                 │
│                                     │
│  !                                  │
└──────────────┬──────────────────────┘
               │
               ▼ Press Tab
┌─────────────────────────────────────┐
│  Editor: index.html                 │
│                                     │
│  <!DOCTYPE html>                    │
│  <html lang="en">                  │
│  <head>...</head>                   │
│  <body></body>                      │
│  </html>                            │
└──────────────┬──────────────────────┘
               │
               ▼ Type: div.container>h1+p
┌─────────────────────────────────────┐
│  Editor: index.html                 │
│                                     │
│  <body>                             │
│    div.container>h1+p               │
│  </body>                            │
└──────────────┬──────────────────────┘
               │
               ▼ Press Tab
┌─────────────────────────────────────┐
│  Editor: index.html                 │
│                                     │
│  <body>                             │
│    <div class="container">         │
│      <h1></h1>                      │
│      <p></p>                        │
│    </div>                           │
│  </body>                            │
└─────────────────────────────────────┘

Real-World Example:

Let's build a simple page structure:

  1. Start with boilerplate:

    • Type ! and press Tab
  2. Add a header:

    • Click inside <body>

    • Type header>h1{My Website} and press Tab

  3. Add navigation:

    • Type nav>ul>li*3{Link $} and press Tab
  4. Add main content:

    • Type main>article*2>h2{Article $}+p{Content} and press Tab
  5. Add footer:

    • Type footer>p{Copyright} and press Tab

In just a few seconds, you have a complete page structure!

Common Emmet Patterns for Daily Use

Here are the most useful Emmet patterns you'll use every day:

Page Structure:

!                    → Full HTML5 boilerplate
header>h1            → Header with h1
nav>ul>li*5          → Navigation with 5 list items
main>section*3        → Main with 3 sections
footer>p             → Footer with paragraph

Forms:

form>input*2+button   → Form with 2 inputs and button
input[type="text"]    → Text input
input[type="email"]   → Email input
button{Submit}        → Submit button

Cards/Lists:

div.card*33 card divs
ul>li*5               → List with 5 items
div>article*44 articles in a div

Common Combinations:

div.container>h1+p    → Container with heading and paragraph
section>h2+div>p*3    → Section with heading and 3 paragraphs
div#main>div*3        → Main div with 3 child divs

Quick Reference Table

EmmetResult
div<div></div>
p{Text}<p>Text</p>
div.container<div class="container"></div>
div#header<div id="header"></div>
div>p<div><p></p></div>
div>p+h1<div><p></p><h1></h1></div>
li*3<li></li><li></li><li></li>
li*3{$}<li>1</li><li>2</li><li>3</li>
!Full HTML5 boilerplate
a[href="#"]<a href="#"></a>

Key Takeaways

  • Emmet is a shortcut language - Write less, get more HTML

  • Saves time and reduces errors - Especially useful for beginners

  • Works in most code editors - VS Code recommended

  • Basic syntax is simple - Element names, dots for classes, hashes for IDs

  • Nesting uses > - Create parent-child relationships easily

  • Siblings use + - Create elements at the same level

  • Multiplication uses * - Repeat elements quickly

  • ! creates full HTML5 boilerplate - One character for complete structure

  • Practice makes perfect - Try each example in your editor

  • Emmet is optional but powerful - You can still write HTML manually, but Emmet makes it faster

Practice Exercises

Try these in your code editor:

  1. Basic elements:

    • Type div and press Tab

    • Type p{Hello} and press Tab

    • Type h1{Title} and press Tab

  2. Classes and IDs:

    • Type div.container and press Tab

    • Type div#main and press Tab

    • Type div.box#content and press Tab

  3. Nesting:

    • Type div>p and press Tab

    • Type ul>li*3 and press Tab

    • Type div>h1+p and press Tab

  4. Full page:

    • Type ! and press Tab

    • Add header>h1{Logo} inside body

    • Add nav>ul>li*5{Link} inside body

    • Add footer>p{Copyright} inside body

Don't Worry About Remembering Everything

There are many Emmet shortcuts, but you don't need to learn them all at once. Start with the basics:

  • Element names (div, p, h1)

  • Classes (.container)

  • IDs (#header)

  • Nesting (>)

  • Multiplication (*3)

As you use Emmet more, you'll naturally learn more shortcuts. The important thing is understanding the concept—that Emmet helps you write HTML faster by using abbreviations.

Remember: Emmet is a tool to make your life easier. You can always write HTML manually if you prefer, but once you get comfortable with Emmet, you'll wonder how you ever coded without it!

Start simple, practice regularly, and you'll be writing HTML at lightning speed in no time!