Emmet in VSCode Flashcards

1
Q

How to generate a HTML boilerplate?

A

Opening up an empty HTML file in VS Code and entering ! should trigger Emmet suggestions. Press Enter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Wrap with Abbreviation
It takes an abbreviation, expands it and places currently selected content in the last element of generated snippet.

A

“Wrap with Abbreviation” (Shift+Ctrl+A)
For example:
How to add a div class: wrapper with a h1 title nested and div class content on the same level. <p> Hello World </p> will be the last element..

<div>
<p>Hello world</p>
</div>

Solution:
.wrapper>h1{Title}+.content

<div>
<div>
<h1>Title</h1>
<div>
<p>Hello world</p>
</div>
</div>
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to do wrapping of individual lines?

<div>

About
News
Products
Contacts

Lorem ipsum dolor sit amet.
</div>

A

Select the lines you want to wrap.
Shift+Ctrl+A
nav>ul.nav>li.nav-item$*>a

<div>

<nav>
<ul>
<li><a>About</a></li>
<li><a>News</a></li>
<li><a>Products</a></li>
<li><a>Contacts</a></li>
</ul>
</nav>

Lorem ipsum dolor sit amet.
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to remove list markers?

A

Simply add “trim“ (|t, pipe-t) filter to abbreviation to automatically remove list markers from wrapped content:

Add it at the back |t
ul.nav>li.nav-item$1>a|t

Select the lines you want to wrap.

<div>

1. About
2. News
3. Products
4. Contacts

Lorem ipsum dolor sit amet.
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to control output position?
Can use the text content inside attributes like title, alt etc

A

You can control the output position with $# placeholder.

ul>li[title=$#]*>{$#}+img[alt=$#]

Attribute in square brackets

<div>

About
News
Products
Contacts

Lorem ipsum dolor sit amet.
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ELEMENTS:
How to generate HTML tags ?

A

You can use elements’ names like div or p to generate HTML tags.
You can write any word and transform it into a tag: div → <div></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Child: >

A

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

div>ul>li
…will produce

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Sibling: +

A

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

div+p+bq
…will output

<div></div>

<p></p>

<blockquote></blockquote>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Climb-up: ^

A

With ^ operator, you can climb one level up the tree and change context where following elements should appear:
Note: can use multiple ^^^, each one will move one level up

div+div>p>span+em^bq
…outputs to

<div></div>

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Multiplication: *

A

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

ul>li*5
…outputs to

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Grouping: ()

A

Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations:

div>(header>ul>li*2>a)+footer>p
…expands to

<div>
<header>
<ul>
<li><a></a></li>
<li><a></a></li>
</ul>
</header>
<footer>
<p></p>
</footer>
</div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ID and Class

A

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:

div#header+div.page+div#footer.class1.class2.class3
…will output

<div></div>

<div></div>

<div></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Custom attributes

A

You can use [attr] notation (as in CSS) to add custom attributes to your element:

td[title=”Hello world!” colspan=3]
…outputs

<td></td>

You can place as many attributes as you like inside square brackets.
You don’t have to specify attribute values: td[colspan title] will produce <td colspan="" title=""> with tabstops inside each empty attribute (if your editor supports them).
You can use single or double quotes for quoting attribute values.
You don’t need to quote values if they don’t contain spaces: td[title=hello colspan=3] will work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Item numbering:

A

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:

ul>li.item$*5
…outputs to

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

You can use multiple $ in a row to pad number with zeroes:

ul>li.item$$$*5
…outputs to

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Changing numbering base and direction

A

With @ modifier, you can change numbering direction (ascending or descending) and base (e.g. start value).

For example, to change direction, add @- after $:

ul>li.item$@-*5
…outputs to

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

To change counter base value, add @N modifier to $:

ul>li.item$@3*5
…transforms to

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

You can use these modifiers together:

ul>li.item$@-3*5
…is transformed to

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Text: {}

A

You can use curly braces to add text to element:

a{Click me}
…will produce

<a>Click me</a>
Note that {text} is used and parsed as a separate element (like, div, p etc.) but has a special meaning when written right after element. For example, a{click} and a>{click} will produce the same output, but a{click}+b{here} and a>{click}+b{here} won’t:

<!-- a{click}+b{here} -->

<a>click</a><b>here</b>

<!-- a>{click}+b{here} -->

<a>click<b>here</b></a>

17
Q

How to remove tag?

A

Ctrl+K
Removes tag
Place it inside the opening tag

<body>
<div>
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet.</p>
<p>Officiis animi consequuntur iure.</p>
<p>Ea asperiores aperiam non necessitatibus?</p>
<p>Expedita iusto cupiditate eum esse.</p>
</div>
</body>