We all can agree that writing HTML is a slow and Repetitive task. Most of the time either we write the same tag again and tag or copy paste the whole HTMl structure and change the contents of the tags.
For example just to create a table we have to write <tr>, <td> & <th> repeatedly. It not only consumes time but also tiring.
For Example:
<div class="container">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</div>
For the above code you have to:
- Write all the Opening Tags.
- Write all the Closing Tags.
- Write all the attributes manually.
This gets tedious quickly, especially when building larger pages.
To solve this Emmet comes to the picture. Emmet is a shortcut system for writing HTML efficiently. It expands short abbreviations into full-fledged HTML structures, reducing the time required to write repetitive code.
Think of Emmet like auto-complete for HTML. It writes entire chunks of HTML for you.
For the above example I have provided. The shortcut of that code can be.
.container>h1{This is a heading}+p{This is a paragraph.}
How to use Emmet in VS Code.
In vs code editor it works out of the box. You don't need to install any extension separatly.
Basic workflow of using emmet abbreviation.
- Type an Emmet abbreviation
- Press Tab (or Enter)
- Editor expands it into HTML
Symbol Table for Emmet Syntax & Abbreviations
| Symbol | Meaning |
|---|---|
| > | Child element |
| + | Sibling element |
| . | Class |
| # | Id |
| * | Repeat element |
| () | Grouping |
| {} | Passing content |
| [] | Attrubutes |
Creating HTML element using emmet
Just type tag name and hit enter(or tab)
h1
Passing content inside HTML elemet
Use {} to pass the content inside the element.
h1{This is Heading}
Creating nested element
Use > to create a nested element. The tag that is written before the < is parent tag and the tag written after is the child tag.
div>h1{This is Heading}
Creating Sibling element
Use + to create a sibling element inside a parent tag.
div>h1{This is heading}+p{This is Paragraph}
Adding class to a HTML element
Use . between the tag and the element to create a class.
div.container
To give class to a <div> tag you can use:
.className
Adding Id to a HTML element
Use # between the tag and the element to create a Id.
div#container
Adding Attributes to HTML elements
input[type:text][placeholder="Enter you name]
Add same element multiple time
Use * to create the same element number of times.
p*3
Boilerplate of HTML
Use ! and hit enter. This will create a complete boilerplate.
!
Example of a complex HTML structure
Conclusion
Emmet is a very useful tool for web developers that helps you write HTML faster. With a few simple shortcuts, you can avoid writing the same tags again and again and save a lot of time.
Whether you are creating a small landing page or a big web application, Emmet makes your work easier. You can quickly create elements, add classes and IDs, nest tags, and even generate a full HTML boilerplate. Since Emmet is already available in VS Code, you can start using it right away without installing anything.
Begin with small shortcuts in your daily coding. Slowly, you will get comfortable with more complex ones. Once Emmet becomes a habit, writing HTML will feel much faster and smoother.
Hope you liked this blog. If there’s any mistake or something I can improve, do tell me. You can find me on LinkedIn and X, I post more stuff there.












Top comments (0)