Skip to main content

Command Palette

Search for a command to run...

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

Updated
2 min read
Emmet for HTML: A Beginner’s Guide to Writing Faster Markup

If you’ve ever spent five minutes typing out <p></p> and <div></div> over and over again, you know that writing HTML can feel a bit slow. It’s like building a house by hand-carving every single brick.

This is where Emmet comes in. Emmet is a powerful "shorthand" language built into most modern code editors (like VS Code). It allows you to type short abbreviations that instantly expand into full blocks of HTML.

What is Emmet?

In simple terms, think of Emmet as Auto-correct for HTML on steroids. Instead of typing out all the brackets and closing tags, you type a simple word, hit the Tab key, and Emmet does the heavy lifting for you. It’s not a new language; it’s just a faster way to write the HTML you already know.

1. Generating the Boilerplate

Every HTML file needs a basic structure (the doctype, head, body, etc.).

  • The Manual Way: Type about 10–15 lines of code.

  • The Emmet Way: Type ! and press Tab.

The Result:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

</body>
</html>

2. Creating Elements with Classes and IDs

Emmet uses syntax similar to CSS selectors, making it very intuitive to learn.

  • For an ID: Use the # symbol.

    • div#header<div id="header"></div>
  • For a Class: Use the . symbol.

    • p.intro<p class="intro"></p>

3. Nesting: Creating Elements Inside Elements

You can build entire structures in one line using the > (child) symbol.

  • Abbreviation: div>ul>li

  • Expanded HTML:

<div>
    <ul>
        <li></li>
    </ul>
</div>

4. Multiplication: Creating Many Elements at Once

Need a list with five items? Don't copy-paste. Use the * symbol.

  • Abbreviation: ul>li*5

  • Expanded HTML:

<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

5. Adding Text and Attributes

You can even pre-fill your tags with text or specific attributes.

  • Text Content: Use curly braces { }.

    • button{Click Me}<button>Click Me</button>
  • Attributes: Use square brackets [ ].

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

Putting it All Together: A Pro Example

Imagine you need a navigation bar with three links inside a nav container.

The Emmet Shortcut: nav>ul>li*3>a

The Result:

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

Summary: Why Use Emmet?

  • Speed: You can write a whole page structure in seconds.

  • Accuracy: Emmet never forgets to close a tag or mistypes a bracket.

  • Focus: You spend less time fighting with your keyboard and more time thinking about your design.

Emmet is purely optional, but once you start using it, you’ll never want to go back to the "slow way."