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

Search for a command to run...

No comments yet. Be the first to comment.
When writing JavaScript code, you often need to perform calculations, compare values, or combine conditions. To do these tasks, JavaScript uses something called operators. If you’ve ever done basic ma

When learning JavaScript, you’ll eventually encounter a keyword that can feel confusing at first: this. The value of this changes depending on how a function is called. JavaScript also provides specia

Functions are one of the most important concepts in JavaScript. They help you organize your code and avoid repeating the same logic again and again. In JavaScript, there are multiple ways to create fu

When writing JavaScript programs, you often need to store multiple values together. For example, imagine you want to store a list of fruits: Apple Mango Banana Orange You could store them like t

As JavaScript applications grow, managing code and data can become complicated. To make programs easier to organize and reuse, developers often use a programming style called Object-Oriented Programmi

ygshjm
24 posts
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?
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.
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.
Instead of typing:
<div></div>
You just type:
div
And press Tab. Emmet does the rest!
Emmet is incredibly useful, especially when you're learning HTML, because:
You write less code, so you can focus on learning and building instead of typing.
Emmet automatically creates correct HTML syntax, so you make fewer errors.
Seeing how abbreviations expand into HTML helps you understand HTML structure better.
Once you learn Emmet, you can write HTML much faster than typing everything manually.
No more typing the same opening and closing tags over and over.
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!
Emmet is built into most modern code editors. Here's how it works:
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!
┌─────────────────────────────────────┐
│ You type: div │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Press Tab key │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Emmet expands: │
│ <div></div> │
└──────────────┬──────────────────────┘
│
▼
HTML is ready!
Emmet works in:
VS Code (Visual Studio Code) - Most popular, recommended for beginners
Sublime Text
Atom
WebStorm
And many other editors
In most editors, Emmet is already enabled by default! You don't need to install anything. Just:
Open a new HTML file
Type an Emmet abbreviation
Press Tab
That's it!
Create a new file and save it as index.html
Type: div
Press Tab
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)
Emmet uses simple abbreviations that look like CSS selectors. If you know CSS, Emmet will feel familiar!
Element name = HTML tag
Just type the HTML element name, and Emmet creates that tag.
| You Type | Emmet Expands To |
div | <div></div> |
p | <p></p> |
h1 | <h1></h1> |
span | <span></span> |
a | <a href=""></a> |
img | <img src="" alt=""> |
Open your code editor
Create a new HTML file
Type p and press Tab
Watch it expand to <p></p>
It's that simple!
You type: p
│
│ (Press Tab)
▼
Result: <p></p>
Creating HTML elements with Emmet is straightforward. Just type the element name!
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>
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>
┌─────────────────────────────────────┐
│ You type: p{Hello} │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Press Tab │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Result: <p>Hello</p> │
└─────────────────────────────────────┘
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>
Emmet makes it easy to add classes, IDs, and other attributes to elements.
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>
Add multiple classes with multiple dots:
You type: div.box.container
Press Tab
You get: <div class="box container"></div>
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>
You can use both class and ID together:
You type: div.container#main
Press Tab
You get: <div class="container" id="main"></div>
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">
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>
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
One of Emmet's most powerful features is creating nested (parent-child) elements easily.
Use > to create parent-child relationships:
You type: div>p
Press Tab
You get:
<div>
<p></p>
</div>
You type: div>p
│
│ (Press Tab)
▼
Result: <div>
<p></p>
</div>
You can nest multiple levels:
You type: div>ul>li
Press Tab
You get:
<div>
<ul>
<li></li>
</ul>
</div>
You type: div>section>article>p
Press Tab
You get:
<div>
<section>
<article>
<p></p>
</article>
</section>
</div>
div>ul>li
│ │ │
│ │ └─ Child (li inside ul)
│ └──── Parent (ul inside div)
└──────── Grandparent (div)
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!
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>
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!)
div>ul>li
│
├─ div (parent)
│
└─ ul (child of div)
│
└─ li (child of ul)
Emmet lets you repeat elements using multiplication. This is super useful for lists!
Use * followed by a number to repeat an element:
You type: li*3
Press Tab
You get:
<li></li>
<li></li>
<li></li>
You type: li*3
│
│ (Press Tab)
▼
Result: <li></li>
<li></li>
<li></li>
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>
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>
li*3
│ │
│ └─ Number of times to repeat
└──── Element to repeat
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>
┌─────────────────────────────────────┐
│ You type: ul>li*3 │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Emmet understands: │
│ - Create ul │
│ - Inside ul, create 3 li elements │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Result: │
│ <ul> │
│ <li></li> │
│ <li></li> │
│ <li></li> │
│ </ul> │
└─────────────────────────────────────┘
One of the most useful Emmet features is generating a complete HTML document structure instantly.
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.
┌─────────────────────────────────────┐
│ You type: ! │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Press Tab │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Complete HTML5 boilerplate! │
│ (DOCTYPE, html, head, body, etc.) │
└─────────────────────────────────────┘
<!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
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!
Here's how Emmet works in your daily coding 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
┌─────────────────────────────────────┐
│ 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> │
└─────────────────────────────────────┘
Let's build a simple page structure:
Start with boilerplate:
! and press TabAdd a header:
Click inside <body>
Type header>h1{My Website} and press Tab
Add navigation:
nav>ul>li*3{Link $} and press TabAdd main content:
main>article*2>h2{Article $}+p{Content} and press TabAdd footer:
footer>p{Copyright} and press TabIn just a few seconds, you have a complete page structure!
Here are the most useful Emmet patterns you'll use every day:
! → 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
form>input*2+button → Form with 2 inputs and button
input[type="text"] → Text input
input[type="email"] → Email input
button{Submit} → Submit button
div.card*3 → 3 card divs
ul>li*5 → List with 5 items
div>article*4 → 4 articles in a div
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
| Emmet | Result |
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> |
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
Try these in your code editor:
Basic elements:
Type div and press Tab
Type p{Hello} and press Tab
Type h1{Title} and press Tab
Classes and IDs:
Type div.container and press Tab
Type div#main and press Tab
Type div.box#content and press Tab
Nesting:
Type div>p and press Tab
Type ul>li*3 and press Tab
Type div>h1+p and press Tab
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
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!