DEV Community

Cover image for Emmet for HTML
Mohd Asif Ansari
Mohd Asif Ansari

Posted on

Emmet for HTML

Writing HTML can feel slow and repetitive. Typing <div></div>, <p></p>, opening and closing tags over and over...

What if you could type div and instantly get <div></div>? That's what Emmet does.

What is Emmet?

Emmet is a shortcut tool built into most code editors. It lets you write HTML super fast using abbreviations.

Simple example:

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

That's it. Emmet turns short codes into full HTML.

Why Use Emmet?

Without Emmet:

<div class="container">
  <ul>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</div>
Enter fullscreen mode Exit fullscreen mode

You type all of this manually. Lots of typing, lots of time.

With Emmet:

div.container>ul>li*3
Enter fullscreen mode Exit fullscreen mode

Press Tab, and you get the same HTML instantly!

Benefits:

  • Write HTML 10x faster
  • Fewer typos (no missing closing tags)
  • Less repetitive work
  • Focus on structure, not syntax

How Emmet Works

Emmet is built into most modern code editors:

  • VS Code (built-in)
  • Sublime Text (built-in)
  • Atom (built-in)
  • WebStorm (built-in)

How to use it:

  1. Type an Emmet abbreviation
  2. Press Tab or Enter
  3. It expands into HTML

That's all you need to know to get started!

Basic Emmet Syntax

Let's learn the fundamentals one by one.

1. Creating Simple Elements

Type the tag name and press Tab.

Example 1:

div → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div></div>
Enter fullscreen mode Exit fullscreen mode

Example 2:

p → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<p></p>
Enter fullscreen mode Exit fullscreen mode

Example 3:

h1 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<h1></h1>
Enter fullscreen mode Exit fullscreen mode

Easy! Just type the tag name.

2. Adding Classes

Use a dot (.) to add a class.

Example:

div.container → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div class="container"></div>
Enter fullscreen mode Exit fullscreen mode

Multiple classes:

div.card.shadow → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div class="card shadow"></div>
Enter fullscreen mode Exit fullscreen mode

3. Adding IDs

Use a hash (#) to add an ID.

Example:

div#header → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div id="header"></div>
Enter fullscreen mode Exit fullscreen mode

Class and ID together:

div#header.navbar → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div id="header" class="navbar"></div>
Enter fullscreen mode Exit fullscreen mode

4. Adding Attributes

Use square brackets [] to add custom attributes.

Example:

a[href="https://google.com"] → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<a href="https://google.com"></a>
Enter fullscreen mode Exit fullscreen mode

Multiple attributes:

img[src="photo.jpg" alt="Photo"] → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<img src="photo.jpg" alt="Photo">
Enter fullscreen mode Exit fullscreen mode

5. Adding Text Content

Use curly braces {} to add text inside elements.

Example:

p{Hello World} → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<p>Hello World</p>
Enter fullscreen mode Exit fullscreen mode

With class:

h1.title{Welcome} → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<h1 class="title">Welcome</h1>
Enter fullscreen mode Exit fullscreen mode

Creating Nested Elements

Use > to create child elements (nesting).

Example 1:

div>p → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div>
  <p></p>
</div>
Enter fullscreen mode Exit fullscreen mode

Example 2:

ul>li → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<ul>
  <li></li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Deeper nesting:

div>ul>li → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div>
  <ul>
    <li></li>
  </ul>
</div>
Enter fullscreen mode Exit fullscreen mode

With classes:

div.container>h1.title → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div class="container">
  <h1 class="title"></h1>
</div>
Enter fullscreen mode Exit fullscreen mode

Repeating Elements with Multiplication

Use * to create multiple copies.

Example 1:

li*3 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<li></li>
<li></li>
<li></li>
Enter fullscreen mode Exit fullscreen mode

Example 2:

div.box*4 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
Enter fullscreen mode Exit fullscreen mode

With nesting:

ul>li*5 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<ul>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
  <li></li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Combining Everything

Now let's combine what we learned.

Example 1: Navigation menu

nav>ul>li*4>a → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<nav>
  <ul>
    <li><a href=""></a></li>
    <li><a href=""></a></li>
    <li><a href=""></a></li>
    <li><a href=""></a></li>
  </ul>
</nav>
Enter fullscreen mode Exit fullscreen mode

Example 2: Card layout

div.container>div.card*3>h2+p → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<div class="container">
  <div class="card">
    <h2></h2>
    <p></p>
  </div>
  <div class="card">
    <h2></h2>
    <p></p>
  </div>
  <div class="card">
    <h2></h2>
    <p></p>
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Note: + creates sibling elements (elements at the same level).

Creating Siblings with +

Use + to create elements next to each other (siblings).

Example:

h1+p → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<h1></h1>
<p></p>
Enter fullscreen mode Exit fullscreen mode

Multiple siblings:

h1+p+p → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<h1></h1>
<p></p>
<p></p>
Enter fullscreen mode Exit fullscreen mode

Complex example:

header>h1+nav>ul>li*3 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<header>
  <h1></h1>
  <nav>
    <ul>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </nav>
</header>
Enter fullscreen mode Exit fullscreen mode

HTML Boilerplate with Emmet

The most useful Emmet shortcut: creating the full HTML structure.

Just type:

! → Tab
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Instant complete HTML page structure!

Alternative (same result):

html:5 → Tab
Enter fullscreen mode Exit fullscreen mode

Practical Examples

Example 1: Blog Post Structure

article>h1.title+p.meta+div.content>p*3 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<article>
  <h1 class="title"></h1>
  <p class="meta"></p>
  <div class="content">
    <p></p>
    <p></p>
    <p></p>
  </div>
</article>
Enter fullscreen mode Exit fullscreen mode

Example 2: Form

form>input[type="text"]+input[type="email"]+button{Submit} → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<form>
  <input type="text">
  <input type="email">
  <button>Submit</button>
</form>
Enter fullscreen mode Exit fullscreen mode

Example 3: Table

table>tr*3>td*4 → Tab
Enter fullscreen mode Exit fullscreen mode

Result:

<table>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>
Enter fullscreen mode Exit fullscreen mode

Emmet Cheat Sheet

Basic:

  • tagname<tagname></tagname>
  • div<div></div>

Classes and IDs:

  • .classname<div class="classname"></div>
  • #idname<div id="idname"></div>
  • div.class#id<div class="class" id="id"></div>

Attributes:

  • a[href]<a href=""></a>
  • img[src alt]<img src="" alt="">

Text:

  • p{text}<p>text</p>

Nesting:

  • div>p → Parent > Child
  • div+p → Siblings

Multiplication:

  • li*3 → Creates 3 <li> elements

Boilerplate:

  • ! or html:5 → Full HTML template

Tips for Beginners

1. Start simple
Just practice basic tags first: div, p, h1

2. Use it daily
The more you use Emmet, the faster you get

3. Don't memorize everything
Learn what you use most often

4. Try each example
Open VS Code and actually type these shortcuts

5. Emmet is optional
You can still write HTML normally. Emmet just makes it faster

Common Mistakes

Forgetting to press Tab

  • Type the abbreviation
  • Then press Tab to expand it

Typos in abbreviation

dvi.container → Won't work
div.container → Works!
Enter fullscreen mode Exit fullscreen mode

Not checking the result
Always check what Emmet generated and adjust if needed

Summary

Emmet = Shortcuts for writing HTML fast

How it works:

  1. Type abbreviation
  2. Press Tab
  3. Get full HTML

Key symbols:

  • . for classes
  • # for IDs
  • > for children (nesting)
  • + for siblings
  • * for repetition
  • [] for attributes
  • {} for text
  • ! for HTML boilerplate

Most useful shortcuts:

  • ! → Full HTML template
  • div.container>ul>li*5 → Quick structures
  • form>input[type]*3 → Forms

Start using Emmet today, and you'll wonder how you ever coded without it!

Top comments (0)