Emmet is...

A cool plug-in that can greatly speed up your HTML & CSS workflow. It's the essential toolkit for web-developers. It's previously known as Zen Coding.

Basically, most text editors out there allow you to store and re-use commonly used code chunks, called “snippets”. While snippets are a good way to boost your productivity, all implementations have common pitfalls: you have to define the snippet first and you can’t extend them in runtime.

Emmet takes the snippets idea to a whole new level: you can type CSS-like expressions that can be dynamically parsed, and produce output depending on what you type in the abbreviation. Emmet is developed and optimised for web-developers whose workflow depends on HTML/XML and CSS, but can be used with programming languages too.

In many editors (such as Eclipse, Sublime Text 2, Espresso etc.) plugins will also generate proper tabstop marks so you can quickly traverse between important places of generated code with the Tab key.

Speed HTML Workflow

Abbreviations are the heart of the Emmet toolkit: these special expressions are parsed in runtime and transformed into structured code block, HTML for example. The abbreviation’s syntax looks like CSS selectors with a few extensions specific to code generation. So every web-developer already knows how to use it.

HTML Abbreviations

Here are some examples of HTML abbreviations. For more abbreviations, scroll down to furthur reading.

Emmet

base
br
link:favicon
form
input:t
btn

Output

<base href="" />
<br />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<form action=""></form>
<input type="text" name="" id="" />
<button></button>

html:5

To get the HTML 5 boilerplate, you can simply type html:5.

Emmet

html:5

Output

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

Child: >

You can use > operator to nest elements inside each other.

Emmet

header>nav>ul>li>a

Output

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

Sibling: +

Use + operator to place elements near each other, on the same level.

Emmet

h1+div+p

Output

<h1></h1>
<div></div>
<p></p>

Climb-up: ^

With ^ operator, you can climb one level up the tree and change context where following elements should appear.
You can climb up as many levels you desire with ^ operator.

Emmet

header+section>h2+p^footer

Output

<header></header>
<section>
  <h2></h2>
  <p></p>
</section>
<footer></footer>

Multiplication: *

With * operator you can define how many times element should be outputted.

Emmet

ul>li*5

Output

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

Grouping: ( )

Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations. You can even have a group within a group.

Emmet

header+(nav>ul>li*2>a)+footer

Output

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

Attributes

In CSS, you use elem#id and elem.class notation to reach the elements with specified id or class attributes. In Emmet, you can use the very same syntax to add these attributes to specified element. You can also use [attr] notation (as in CSS) to add custom attributes to your element.

Emmet

img[title="One"]

div#header+div.page+div#footer

Output

<img src="|" alt="" title="One">

<div id="header"></div>
<div class="page"></div>
<div id="footer"></div>

Item Numbering: $

With multiplication * operator you can repeat elements, but with $ you can number them. Place $ operator inside element’s name, attribute’s name or attribute’s value to output current number of repeated element.

Emmet

ul>li.item$*3

Output

<ul>
  <li class="item1"></li>
  <li class="item2"></li>
  <li class="item3"></li>
</ul>

Text: { }

You can use curly braces to add text to element.

Emmet

a{Click Me}

a{Click $}*3

Output

<a href="|">Click Me</a>

<a href="">Click 1</a>
<a href="">Click 2</a>
<a href="">Click 3</a>

Lorem Ipsum

Lorem Ipsum is dummy text. lorem is not just a normal snippet — it’s actually a generator. Every time you expand it, it will generate a 30-words dummy text, splitted into a few sentences. You can specify how many words should be generated right in the abbreviation. For example, lorem100 will generate a 100-words dummy text.

Emmet

lorem15

Output

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia consequuntur enim minus ut libero veniam!

Speed CSS Workflow

For CSS syntax, Emmet has a lot of predefined snippets for properties. For example, you can expand m abbreviation to get margin: ; snippet. But you don’t want just margin property, you want to specify a value for this property. So you have to manually type, let’s say, 10px. Emmet can greatly optimize your workflow here: you can inject value directly into abbreviation. To get margin: 10px; you can simply expand the m10 abbreviation. Want multiple values? Use a hypen to separate them: m10-20 expands to margin: 10px 20px.

You'll find there are too many CSS snippets to remember. To make CSS writing a bit easier, Emmet implement fuzzy search logic for CSS snippets: every time you enter unknown abbreviation, Emmet will try to find a closest snippet definition. For example, instead of writing ov:h (overflow: hidden;) abbreviation, you can write ov-h, ovh or even oh.

CSS Abbreviations

Here are some examples of CSS abbreviations. For more abbreviations, scroll down to furthur reading.

Emmet

m
ml
ml50
m50-20
bgc
c#4f
fz20
w50p

Output

margin: ;
margin-left: ;
margin-left: 50px;
margin: 50px 20px;
background-color: #FFF;
color: #4f4f4f;
font-size: 20px;
width: 50%;

Vendor Prefixes: Border Radius

Emmet’s CSS resolver has a nice feature that can greatly improve your CSS3 experience. Every time you precede CSS property or its abbreviation with a hyphen, Emmet automatically creates vendor-prefixed copies of this property. Now you can type on all lines at once. Also, it actually works without preceding with a hyphen, and produces the same result. Sometime it works without including the colon.

Emmet

-bdrs:

Output

-webkit-border-radius: |;
-moz-border-radius: |;
border-radius: |;

Vendor Prefixes: Transform

Now let's try adding vendor prefixes to the transform property.

Emmet

trf

Output

-webkit-transform: |;
-moz-transform: |;
-ms-transform: |;
-o-transform: |;
transform: |;

Vendor Prefixes: Transition

Adding vendor prefixes to the transition property is a nice feature. After you hit the tab key, it will automatically highlight the word prop on all lines. Now you can change it to whatever CSS property you desire. Hit tab again and it will do the same for the time.

Emmet

trs-

Output

-webkit-transition: prop time;
-moz-transition: prop time;
-ms-transition: prop time;
-o-transition: prop time;
transition: prop time;

Vendor Prefixes: Box Shadow

Adding vendor prefixes to the box-shadow property is easy to implement, as you can see in the example below.

Emmet

bxsh2px4px5px#000

Output

-webkit-box-shadow: 2px 4px 5px #000;
-moz-box-shadow: 2px 4px 5px #000;
box-shadow: 2px 4px 5px #000;

Linear Gradients

You know how hard it can be to write a CSS gradient for all the vendor prefixes. Emmet has a CSS3 Gradient Generator that can do all the hard work for you.

Emmet

lg(red, blue)

Output

background-image: -webkit-gradient(linear, 0 0, 0 100%, from(red), to(blue));
background-image: -webkit-linear-gradient(red, blue);
background-image: -moz-linear-gradient(red, blue);
background-image: -o-linear-gradient(red, blue);
background-image: linear-gradient(red, blue);

Install on Sublime Text (3 Easy Steps)

Step 1

Run "Package Control: Install Package" command. Mac: ⌘+shift+p. Win: ctrl+shift+p. Just type the word install or package and click the first result given.

Package

Step 2

Find and install Emmet plugin. Just type the word emmet and click the first result given.

Emmet

Step 3

Restart Sublime Text (if required). You can now start improving your workflow.

Emmet
Tools for web-developers