Skip to main content

Command Palette

Search for a command to run...

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

Updated
•4 min read•View as Markdown
Emmet for HTML: A Beginner's Guide to Writing Faster Markup

Ever felt like typing HTML tags is... well, a lot of typing? You're not alone. When I first started learning HTML, I spent so much time writing opening tags, closing tags, and making sure everything matched up. It felt slow and repetitive.

Then I discovered Emmet, and everything changed.

What is Emmet?

Think of Emmet as autocomplete on steroids. It's a shortcut language that lives inside your code editor. You type a few characters, hit a key, and boom – full HTML code appears like magic.

No installation needed. If you're using VS Code (which I recommend), Emmet is already there, waiting for you.

Why Should You Care?

Simple. Emmet saves you time and reduces mistakes. Instead of typing this:

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

You just type div.container and press Tab. Done.

Less typing means more time actually building things. And when you're learning, that's huge.

How Does It Work?

Emmet watches what you type in your HTML files. When you write an Emmet abbreviation and press Tab (or Enter), it expands into real HTML code.

That's it. No complicated setup. Just type and expand.

Basic Emmet Shortcuts

Let's start simple. Here are the shortcuts you'll use every single day.

Creating Elements

Want a paragraph? Type p and hit Tab.

p → <p></p>

Want a heading? Type h1 and hit Tab.

h1 → <h1></h1>

Any HTML tag works this way. Try button, span, section – they all work.

Adding Classes

This is where Emmet gets fun. Use a dot to add classes.

div.card → <div class="card"></div>

Multiple classes? Just keep adding dots.

button.btn.primary → <button class="btn primary"></button>

Adding IDs

Use the hashtag symbol for IDs.

div#header → <div id="header"></div>

You can mix classes and IDs together.

nav#main-nav.navbar → <nav id="main-nav" class="navbar"></nav>

Adding Attributes

Need custom attributes? Use square brackets.

img[src="photo.jpg"] → <img src="photo.jpg" alt="">
a[href="#" target="_blank"] → <a href="#" target="_blank"></a>

Creating Nested Elements

Here's where Emmet really shines. Use the greater than symbol to nest elements inside each other.

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

Want to go deeper?

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

Repeating Elements

Need multiple items? Use the multiplication symbol.

li*3 → <li></li>
       <li></li>
       <li></li>

Combine it with nesting for powerful results.

ul>li*4 → <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
          </ul>

The Full HTML Boilerplate

Starting a new HTML file? Type this and 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>

Just one character. That's all it takes to set up your entire HTML structure.

Real World Example

Let's build a simple card component. Without Emmet, you'd type a lot. With Emmet, you type this:

div.card>img[src="image.jpg"]+div.content>h2+p

Press Tab, and you get:

<div class="card">
  <img src="image.jpg" alt="" />
  <div class="content">
    <h2></h2>
    <p></p>
  </div>
</div>

One line became a complete structure. That's the power of Emmet.

Try It Yourself

Open VS Code (or your favorite editor). Create a new HTML file. Try these:

  1. Type ! and press Tab

  2. Type div.container>h1+p*2 and press Tab

  3. Type nav>ul>li*3>a and press Tab

Play around. Make mistakes. That's how you learn.

Should You Use Emmet?

Honestly? Yes. But don't stress if you forget the shortcuts at first. You can always type HTML the old way. Emmet is there when you want speed, not when you're still learning the basics.

Start with simple shortcuts. Use div.classname and element*3 until they feel natural. Then add more tricks to your toolkit.

Wrapping Up

Emmet isn't magic, but it feels like it. It takes the repetitive parts of writing HTML and makes them fast. You'll write cleaner code, make fewer typos, and spend more time on the fun parts of building websites.

Remember: Emmet is a tool, not a requirement. Use it when it helps. Skip it when it doesn't. The goal is to make your life easier, not more complicated.

Now go open your editor and try that ! shortcut. Your first full HTML page is just one Tab key away.

Happy Shortcutting 😉!