Skip to main content

Command Palette

Search for a command to run...

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

Updated
β€’7 min read

Speed up your HTML coding with this powerful shortcut language

The Problem: Writing HTML is Slow

Imagine this: You're building a simple navigation bar. You need:

- A <nav> element

- An unordered list <ul>

- Five list items <li>

- Each with an anchor tag <a>

- Each anchor needs a class and an href attribute

Without Emmet, you'd type something like this:

<nav>
  <ul>
    <li><a href="#" class="nav-link">Home</a></li>
    <li><a href="#" class="nav-link">About</a></li>
    <li><a href="#" class="nav-link">Services</a></li>
    <li><a href="#" class="nav-link">Portfolio</a></li>
    <li><a href="#" class="nav-link">Contact</a></li>
  </ul>
</nav>

That's 9 lines and a lot of typing, opening/closing tags, and potential typos.

With Emmet, you'd type this:

nav>ul>li*5>a.nav-link[href="#"]{Link}

Then press Tab (or Enter, depending on your editor), and boom! The entire structure appears instantly.

What is Emmet? (In Simple Terms)

Emmet is like a shortcut language for HTML and CSS.

Think of it like text shortcuts on your phone:

- You type "omw," and it expands to "On my way!"

- You type "brb," and it expands to "Be right back!"

Emmet works the same way, but for code:

- You type div and press Tab β†’ <div></div>

- You type div.container and press Tab β†’ <div class="container"></div>

- You type ul>li*3 and press Tab β†’ A list with 3 items!

It's not a separate toolβ€”it's built into most modern code editors like VS Code, Sublime Text, and Atom. You're probably already using it without knowing!

Why Emmet is Useful for HTML Beginners

1. Speed ⚑

Write HTML 10x faster. What takes 5 minutes manually takes 30 seconds with Emmet.

2. Fewer Mistakes βœ…

No more forgetting closing tags or typos. Emmet generates perfect, valid HTML.

3. Learn HTML Structure πŸ“š

Emmet abbreviations mirror HTML structure, so you learn how elements relate to each other.

4. Focus on Logic, Not Syntax 🧠

Spend time thinking about your page structure, not typing repetitive tags.

5. Professional Workflow πŸ’Ό

Most professional developers use Emmet. Learning it early puts you ahead.

How Emmet Works Inside Code Editors

Here's the magic flow:

You type: div.container

         ↓

    Editor detects Emmet abbreviation

         ↓

    You press Tab or Enter

         ↓

    Emmet expands abbreviation

         ↓

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

Try it yourself:

1. Open VS Code (or your favorite editor)

2. Create a new HTML file

3. Type div and press Tab

4. Watch the magic happen! ✨

Basic Emmet Syntax

Emmet uses simple symbols to represent HTML relationships:

| Symbol | Meaning | Example |

|--------|---------|---------|

| > | Child (nested inside) | div>p β†’ <div><p></p></div> |

| + | Sibling (next to) | div+p β†’ <div></div><p></p> |

| * | Multiplication (repeat) | li*3 β†’ 3 <li> elements |

| ^ | Climb up (parent) | div>p^span β†’ <div><p></p></div><span></span> |

| () | Grouping | (div>p)*2 β†’ 2 divs, each with a p |

Creating HTML Elements

Single Elements

div

Press Tab β†’ <div></div>

p

Press Tab β†’ <p></p>

button

Press Tab β†’ <button></button>

Try these: h1, section, article, header, footer, nav

Adding Classes and IDs

Classes (using .)

div.container

Press Tab β†’ <div class="container"></div>

p.intro

Press Tab β†’ <p class="intro"></p>

button.btn.btn-primary

Press Tab β†’ <button class="btn btn-primary"></button>

IDs (using #)

div#header

Press Tab β†’ <div id="header"></div>

section#hero

Press Tab β†’ <section id="hero"></section>

Combine Classes and IDs

div#main.container.wrapper

Press Tab β†’ <div id="main" class="container wrapper"></div>

Note: ID comes first, then classes.

Adding Attributes

Use square brackets [] for any HTML attribute:

Basic Attributes

a[href="#"]

Press Tab β†’ <a href="#"></a>

img[src="photo.jpg"][alt="Photo"]

Press Tab β†’ <img src="photo.jpg" alt="Photo" />

input[type="text"][placeholder="Enter name"]

Press Tab β†’ <input type="text" placeholder="Enter name" />

Combining with Classes/IDs

a.button[href="/about"][target="_blank"]

Press Tab β†’ <a href="/about" target="_blank" class="button"></a>

Creating Nested Elements

Use > to create parent-child relationships:

Simple Nesting

div>p

Press Tab β†’
<div>

  <p></p>

</div>

Multiple Levels

div>ul>li Press Tab β†’

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

Complex Nesting

nav>ul>li>a Press Tab β†’

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

Multiple Children

div>p+span+button Press Tab β†’

<div>
 <p></p>
 <span></span>
 <button></button>
</div>

Complex Nesting

nav>ul>li>a Press Tab β†’ 

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

Multiple Children

div>p+span+button Press Tab β†’ 

<div>
  <p></p>
  <span></span>
  <button></button>
</div>

Repeating Elements with Multiplication

Use * followed by a number to repeat elements:

Simple Repetition

li*5 Press Tab β†’ 

<li></li>

<li></li>

<li></li>

<li></li>

<li></li>

Repeated Nested Structures

ul>li*3. Press Tab β†’ 

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

Complex Repetition

div.card*4>h2+p+button Press Tab β†’ 

<div class="card">
  <h2></h2>
  <p></p>
  <button></button>
</div>

<div class="card">
  <h2></h2>
  <p></p>
  <button></button>
</div>

<div class="card">
  <h2></h2>
  <p></p>
  <button></button>
</div>

<div class="card">
  <h2></h2>
  <p></p>
  <button></button>
</div>

Adding Text Content

Use curly braces {} to add text inside elements:

Simple Text

p{Hello World}

Press Tab β†’ <p>Hello World</p>

Text in Nested Elements

div>h1{Welcome}+p{This is a paragraph} Press Tab β†’ 

<div>
  <h1>Welcome</h1>
  <p>This is a paragraph</p>
</div>

Text with Repetition

ul>li*3{Item $} Press Tab β†’ 

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

Pro Tip: The $ symbol creates numbered text automatically!

Generating Full HTML Boilerplate

Emmet can generate a complete HTML5 document structure:

The Magic Abbreviation

Type this in an empty file:

!

Or

html:5 Press Tab 

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

Customized Boilerplate

You can also customize it:

html:5>head>meta[charset=UTF-8]+title{My Page}+body>h1{Hello}

This creates a full HTML document with custom content!

Real-World Examples

Let's build common HTML structures with Emmet:

Example 1: Navigation Bar

Emmet:

nav.navbar>ul.nav-list>li.nav-item*5>a.nav-link[href="#"]{Link $}

Result:

<nav class="navbar">
  <ul class="nav-list">
    <li class="nav-item"><a href="#" class="nav-link">Link 1</a></li>
    <li class="nav-item"><a href="#" class="nav-link">Link 2</a></li>
    <li class="nav-item"><a href="#" class="nav-link">Link 3</a></li>
    <li class="nav-item"><a href="#" class="nav-link">Link 4</a></li>
    <li class="nav-item"><a href="#" class="nav-link">Link 5</a></li>
  </ul>
</nav>

Example 2: Card Component

Emmet:

div.card>img[src="image.jpg"][alt="Card image"]+div.card-body>h3.card-title{Title}+p.card-text{Description}+button.btn{Read More}

Result:

<div class="card">
  <img src="image.jpg" alt="Card image" />
  <div class="card-body">
    <h3 class="card-title">Title</h3>
    <p class="card-text">Description</p>
    <button class="btn">Read More</button>
  </div>
</div>

Example 3: Form Structure

Emmet:

form>div.form-group*3>label[for="input$"]{Label $}+input[type="text"][id="input$"][name="input$"]+button[type="submit"]{Submit}

Result:

<form>
  <div class="form-group">
    <label for="input1">Label 1</label>
    <input type="text" id="input1" name="input1" />
  </div>
  <div class="form-group">
    <label for="input2">Label 2</label>
    <input type="text" id="input2" name="input2" />
  </div>
  <div class="form-group">
    <label for="input3">Label 3</label>
    <input type="text" id="input3" name="input3" />
  </div>
  <button type="submit">Submit</button>
</form>

Visual Guide: How Emmet Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ You Type: div.container>p*3 β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

↓

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Emmet Parser β”‚

β”‚ - div with class container β”‚

β”‚ - contains 3 p elements β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

↓

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ Press Tab/Enter β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

↓

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ <div class="container"> β”‚

β”‚ <p></p> β”‚

β”‚ <p></p> β”‚

β”‚ <p></p> β”‚

β”‚ </div> β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Common Patterns You'll Use Daily

Here are the Emmet patterns you'll use most often:

1. Container with Content

div.wrapper>h1{Title}+p{Text}

2. List Items

ul>li*5{Item $}

3. Form Inputs

input[type="text"][placeholder="Enter text"]

4. Buttons

button.btn.btn-primary{Click Me}
a[href="/page"]{Link Text}

6. Images

img[src="image.jpg"][alt="Description"]

7. Sections

section#about>div.container>h2{About}+p{Lorem}

Practice Exercises

Try creating these structures with Emmet:

1. Header with logo and navigation

  • Hint: header>div.logo+nav>ul>li*4>a

2. Article with title, author, date, and content

3. Footer with 3 columns

  • Hint: footer>div.column*3>h3+p*2

4. Table with 3 rows and 4 columns

  • Hint: table>tr*3>td*4

5. Complete page structure

  • Hint: Start with ! then add header, main, footer

Happy Coding! πŸš€

Have questions about Emmet? Drop them in the comments below!