Skip to main content

Command Palette

Search for a command to run...

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

Published
2 min read

So basically, In this bog, we are understand what is emmet and how to use emmet in HTML and CSS to write a three time faster code.

What is Emmet?

  1. Emmet is basically a bunch of shortcuts and snippets.

  2. So when you type a small piece of code it creates a bunch of code by just using a small part of information.

  3. You write a short code, emmet expands it into full HTML and CSS for you.

example

You type:

p

Then press Tab
Emmet turns it into:

<p></p>

Why emmet exist:

  • Saves time

  • Fewer mistakes

  • Less typing

Why emmet is useful for beginners:

When someone is new to HTML and they write HTML , they feel very irritating because they need to open a tag and close the tag ,every time they write HTML.

So emmet helps with reducing type,avoiding syntax errors, clear clusture HTML structure and main it makes writing HTML is less irritating.

E.g.

With Emmet:

p + Tab

You get:

<p></p>

Basic emmet syntax and its abbreviations:-

Symbol Meaning

  1. div Create an element

  2. > Child (nested inside)

  3. . Class

  4. # ID

  5. * Repeat

  6. {} Text content

  7. ! HTML boilerplate

These emmet we are going to use in daily basis.

Creating HTML elements using emmet:

  1. Create elements inside elements (child)

Use >

div>p

⬇️

<div>
  <p></p>
</div>
  1. Create multiple elements at once

Use *

li*3

⬇️

<li></li>
<li></li>
<li></li>
  1. Create elements next to each other

Use +

h2+p

⬇️

<h2></h2>
<p></p>
  1. Create elements with class

Use .

div.container

⬇️

<div class="container"></div>
  1. Create elements with ID

Use #

section#about

⬇️

<section id="about"></section>

Generating full HTML boilerplate with Emmet

Type this in an empty HTML file:

!

Then press Tab (or Enter)

Emmet generates this automatically:

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

Why this is called “boilerplate”

It includes everything a basic webpage needs:

  • <!DOCTYPE html> → tells browser it’s HTML5

  • <meta charset> → supports all characters

  • <meta viewport> → makes site responsive

  • <title> → page title

  • <body> → content area