Skip to main content

Command Palette

Search for a command to run...

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

Published
3 min read
A

learning to survive

1. What is Emmet

Emmet is a shortcut language (or toolkit) that lets you type short abbreviations and instantly expand them into full HTML code. It's like autocorrect on steroids for web developers. You write something short, press Tab (or Enter in some editors), and Emmet generates the proper HTML structure for you.

It's not magic it's smart text expansion built into most modern code editors.

2. Why Emmet is useful for HTML beginners

  • Saves tons of time by reducing typing (you can write complex structures in seconds).

  • Helps avoid typos (fewer characters = fewer mistakes).

  • Lets you focus on learning HTML structure and logic instead of fighting syntax.

  • Builds muscle memory for common patterns quickly.

  • It's optional but powerful—once you start using it, going back feels painfully slow.

Many beginners double or triple their coding speed after learning just the basics.

3. How Emmet works inside code editors

Emmet is built-in to Visual Studio Code (VS Code, highly recommended for beginners) and many other editors like Sublime Text, Atom, etc. No extra installation needed in VS Code.

  • Open an .html file.

  • Type an Emmet abbreviation.

  • Press Tab (default trigger) → it expands into HTML.

  • You can customize the trigger key if needed, but Tab works great out of the box.

Try it yourself: Create a new file index.html in VS Code and follow along!

4. Basic Emmet syntax and abbreviations

Emmet uses a CSS-like syntax:

  • Element names: just write them (div, p, ul, etc.)

  • Unknown words become custom tags (e.g., foo → <foo></foo>)

  • Operators connect them (more below)

Common basics:

  • div → <div></div>

  • p → <p></p>

  • h1 → <h1></h1>

5. Creating HTML elements using Emmet

Start simple. Type these one at a time and press Tab:

  • h1 → <h1></h1>

  • section → <section></section>

  • img → <img src="" alt=""> (self-closing, with common attributes)

Side-by-side:

Emmet: p Expanded: <p></p>

Emmet: a Expanded: <a href=""></a>

Try it now: Type article and Tab.

6. Adding classes, IDs, and attributes

Use CSS selector style:

  • .class → add class (implicit div if no tag)

  • #id → add id

  • [attr="value"] → custom attributes

Examples:

  • .container → <div class="container"></div>

  • header.main-header → <header class="main-header"></header>

  • #logo → <div id="logo"></div>

  • input[type="text"] → <input type="text">

  • img[src="logo.png" alt="Logo"] → <img src="logo.png" alt="Logo">

Side-by-side:

Emmet: ul.menu Expanded: <ul class="menu"></ul>

Emmet: button.btn.btn-primary[disabled] Expanded: <button class="btn btn-primary" disabled></button>

7. Creating nested elements

Use > for child:

  • ul>li → <ul><li></li></ul>

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

Side-by-side:

Emmet: div>header>h1 Expanded:

HTML

<div>
  <header>
    <h1></h1>
  </header>
</div>

Emmet: form>input[type="email"]+input[type="password"]+button Expanded:

HTML

<form>
  <input type="email">
  <input type="password">
  <button></button>
</form>

(+ means sibling)

8. Repeating elements using multiplication

Use * to repeat:

  • li*3 → three <li></li>

  • ul>li.item*5 → <ul> with 5 <li class="item"></li>

Numbering with $:

  • li.item$*3 → <li class="item1"></li>, <li class="item2">, <li class="item3">

  • a{Link $}*4 → four <a>Link 1</a>, etc.

Side-by-side:

Emmet: ul>li*3>a{Item $} Expanded:

HTML

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

9. Generating full HTML boilerplate with Emmet

The most satisfying one for new files:

  • Type ! and press Tab Expanded: Full HTML5 boilerplate!

HTML

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