Emmet is a powerful plugin for web developers that can be used in many text editors, and allows us to type abbreviations and display code in html, jsx, css, sass and others, in an easier and faster way. Emmet is installed by default on many editors like VS Code, WebStorm and IntelliJ.
How does emmet work?
Type your emmet abbreviations and then press the tab key to see the magic happen in front of your eyes. These are a few examples of how to use it:
- Tags with IDs: ‘#’ is used to assign an ID
- Tags with classes: ‘.’ is used to assign single or multiple classes
- Nested tags: ‘>’ is used to nest different elements
- Siblings tags: ‘+’ is used to create siblings elements
- Grouping tags: ‘()’ is used to group elements
- Repeat elements or groups: ‘*’ is used to generate elements or groups
- Content in elements: ‘{}’ are used to set content inside an element
- Numbering: ‘$’ is used to put numbers in an item
- Attributes:’[]’ are used to add an attribute in an element
- Implicit tags: Emmet creates the tags that you want based on the context
Using Emmet within styles
You can also use Emmet inside of your styles in CSS, SCSS, SASS and other styles files. Using this approach saves you a lot of time, since you don’t have to type long properties and values.
Abbreviation | Output |
---|---|
m10 | margin: 10px |
m10-5-10-5 | margin: 10px 5px 10px 5px |
m10p5em10rem5 | margin: 10% 5em 10rem 5px |
p10 | padding: 10px |
p10-5-10-5 | padding: 10px 5px 10px 5px |
Cool things to know about Emmet
When you are typing your Emmet abbreviations you can press [Ctrl + Space] in your text editor to see what elements are being generated, as they will be displayed in a popup. You can also create lorem ipsum paragraphs by just typing “lorem” and pressing the Tab key. Check out the Emmet Cheat Sheet for more tips and tricks!