Cover Image for Emmet Part 2 - Advanced
Jesse Hall
Jesse Hall

2 min read

Emmet Part 2 - Advanced

If you haven't read Emmet Basics Part 1, check that out first.

In this post, we cover the following topics:
📌 Boilerplates
📌 Climb Up
📌 Grouping
📌 Attributes
📌 Item Numbering
📌 Implicit Tags
📌 CSS Sneak Peek

Part 3 coming soon!

Boilerplate

You can create a basic HTML boilerplate easily!

!

results.html
Copy

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

Climb Up

With Emmet we can easily traverse multiple levels. Here we can climb up a level using ^

div+div>p>span+em^bq

results.html
Copy

<div></div>
<div>
<p><span></span><em></em></p>
<blockquote></blockquote>
</div>

Grouping

We can achieve something similar by using grouping. To group, surround parts of the code with parenthesis.

div>(hdr>ul>li\*2>a)+ftr>p

results.html
Copy

<div>
<header>
<ul>
<li><a href=""></a></li>
<li><a href=""></a></li>
</ul>
</header>
<footer>
<p></p>
</footer>
</div>

Attributes

We can also easily add attributes to any tag using square brackets.

p[title="Hello World"]

results.html
Copy

<p title="Hello World"></p>

Item Numbering

When multiplying items, an index is tracked. We can use the index by inserting the $ sign.

h$[title=item$]{Header $}*3

results.html
Copy

<h1 title="item1">Header 1</h1>
<h2 title="item2">Header 2</h2>
<h3 title="item3">Header 3</h3>

Implicit Tags

tags do not always need to be used. In some cases they are implied. Here we create a table with a row and a column without specifying the tr or td.

table>.row>.col

results.html
Copy

<table>
<tr class="row">
<td class="col"></td>
</tr>
</table>

CSS Sneak Peek

Emmet can be used for CSS too! Part 3 will be all about fast CSS workflows.

pos
pos:s
pos:a
pos:r
pos:f

results.css
Copy

position:relative;
position:static;
position:absolute;
position:relative;
position:fixed;

Part 3 coming very soon!


Check out the full video on my YouTube channel.

Help me out by liking this video and subscribing if you haven't already.

Thanks for reading!