Emmet for HTML
Source: Dev.to
Writing HTML can feel slow and repetitive. Typing “, `
, opening and closing tags over and over… What if you could typediv` and instantly get “? 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:
pPress Tab →
That’s it. Emmet turns short codes into full HTML.
Why Use Emmet?
Without Emmet
-
-
-
You type all of this manually – lots of typing, lots of time.
With Emmet
div.container>ul>li*3Press Tab and you get the same HTML instantly!
Benefits
- Write HTML 10× 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
- Type an Emmet abbreviation.
- Press Tab or Enter.
- It expands into HTML.
That’s all you need 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 → TabResult
Example 2
p → TabResult
Example 3
h1 → TabResult
##
2. Adding Classes
Use a dot (.) to add a class.
Example
div.container → TabResult
Multiple classes
div.card.shadow → TabResult
3. Adding IDs
Use a hash (#) to add an ID.
Example
div#header → TabResult
Class and ID together
div#header.navbar → TabResult
4. Adding Attributes
Use square brackets [] to add custom attributes.
Example
a[href="https://google.com"] → TabResult
[](https://google.com)Multiple attributes
img[src="photo.jpg" alt="Photo"] → TabResult
[Image: Photo]5. Adding Text Content
Use curly braces {} to add text inside elements.
Example
p{Hello World} → TabResult
Hello World
With class
h1.title{Welcome} → TabResult
## Welcome
Creating Nested Elements
Use > to create child elements (nesting).
Example 1
div>p → TabResult
Example 2
ul>li → TabResult
-
Deeper nesting
div>ul>li → TabResult
-
With classes
div.container>h1.title → TabResult
##
Repeating Elements with Multiplication
Use * to create multiple copies.
Example 1
li*3 → TabResult
-
-
-
Example 2
div.box*4 → TabResult
With nesting
ul>li*5 → TabResult
-
-
-
-
-
Emmet Cheat Sheet & Examples
A quick reference for using Emmet to write HTML faster.
Combining Everything
Now let’s combine what we learned.
Example 1 – Navigation menu
Abbreviation
nav>ul>li*4>a → TabResult
- []()
- []()
- []()
- []()
Example 2 – Card layout
Abbreviation
div.container>div.card*3>h2+p → TabResult
##
##
##
Note:
+creates sibling elements (elements at the same level).
Creating Siblings with +
Use + to place elements next to each other (siblings).
Simple sibling pair
Abbreviation
h1+p → TabResult
##
Multiple siblings
Abbreviation
h1+p+p → TabResult
##
Complex example
Abbreviation
header>h1+nav>ul>li*3 → TabResult
##
-
-
-
HTML Boilerplate with Emmet
The most useful shortcut for creating a full HTML document.
Shortcut
! → TabResult
Document
Alternative:
html:5 → Tabproduces the same output.
Practical Examples
Example 1 – Blog post structure
Abbreviation
article>h1.title+p.meta+div.content>p*3 → TabResult
##
Example 2 – Simple form
Abbreviation
form>input[type="text"]+input[type="email"]+button{Submit} → TabResult
Submit
Example 3 – Table
Abbreviation
table>tr*3>td*4 → TabResult
Emmet Cheat Sheet
| Category | Shortcut | Output |
|---|---|---|
| Basic | tagname | “ |
| Div | div | “ |
| Classes | .classname | “ |
| IDs | #idname | “ |
| Class + ID | div.class#id | “ |
| Attributes | a[href] | []() |
img[src alt] | ![]() | |
| Text | p{Hello} | ` |
| Hello | ||
| ` | ||
| Nesting | div>p | ` |
| | **Siblings** |div+p|
| | **Multiplication** |li*3|-
| | **Boilerplate** |!orhtml:5` | Full HTML template (see above) |
Tips for Beginners
- Start simple – practice with
div,p,h1. - Use it daily – the more you type, the faster you become.
- Don’t memorize everything – learn the shortcuts you need most.
- Try each example – open VS Code and type the abbreviations yourself.
- Remember: Emmet is optional; you can always write HTML manually.
Common Mistakes
Forgetting to press Tab – type the abbreviation, then press Tab to expand.
Typos in the abbreviation
dvi.container → Won’t work div.container → Works!Not checking the result – always review the generated markup and adjust if necessary.
Summary
- Emmet = shortcuts for writing HTML quickly.
- How it works:
- Type an abbreviation.
- Press Tab.
- Emmet expands it to full HTML.
Key symbols
.– class#– ID>– child (nesting)+– sibling*– repetition[]– attributes{}– text content!– HTML boilerplate
Most useful shortcuts
!→ full HTML templatediv.container>ul>li*5→ quick list structuresform>input[type]*3→ simple forms
Start using Emmet today, and you’ll wonder how you ever coded without it!