DEV Community

Cover image for HTML Shortcuts in VS Code
Peta Stewart
Peta Stewart

Posted on • Edited on

HTML Shortcuts in VS Code

Speed Coding

Becoming an efficient developer sometimes requires us to spend a little time to learn a few shortcuts. And here Emmet is helping us. Emmet is a plug-in which ships with VS Code and provides shorthand notations for HTML when writing code in .html files.

Shortcut Features Include:

Note: To accept the emmet shortcut, press "Tab" or "Enter. And to skip all the suggestions, press "Esc" or adding a space will remove the list.

HTML Page Template

To add the new page boilerplate code, insert:

!
Enter fullscreen mode Exit fullscreen mode

And then enter to get:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Elements

Type any element tag name

h1
Enter fullscreen mode Exit fullscreen mode

To get the closing and opening tags

<h1></h1>
Enter fullscreen mode Exit fullscreen mode

Sibling Elements

Use +

header+footer
Enter fullscreen mode Exit fullscreen mode

To add element on the same level

<header></header>
<footer></footer>
Enter fullscreen mode Exit fullscreen mode

Child Elements

Use >

    header>nav
Enter fullscreen mode Exit fullscreen mode

To add a nested element

    <header>
        <nav></nav>
    </header>
Enter fullscreen mode Exit fullscreen mode

Grouping

Use ()

    header+(main>section)+footer
Enter fullscreen mode Exit fullscreen mode

To group elements

    <header></header>
    <main>
        <section></section>
    </main>
    <footer></footer>
Enter fullscreen mode Exit fullscreen mode

Climb Up

Use ^ to escape a level of nesting

    header+main>section^footer
Enter fullscreen mode Exit fullscreen mode

To escape a level of nesting

    <header></header>
    <main>
        <section></section>
    </main>
    <footer></footer>
Enter fullscreen mode Exit fullscreen mode

Multiple Elements

Use *

    ul>li*4
Enter fullscreen mode Exit fullscreen mode

To multiply the number of elements

    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
Enter fullscreen mode Exit fullscreen mode

Class & ID's

Use .

    nav.my-nav
Enter fullscreen mode Exit fullscreen mode

To add a class

<nav class="my-nav"></nav>
Enter fullscreen mode Exit fullscreen mode

And #

nav#my-id
Enter fullscreen mode Exit fullscreen mode

To add an ID

<nav id="my-id"></nav>
Enter fullscreen mode Exit fullscreen mode

Adding Text

Use {}

button{Click Me}
Enter fullscreen mode Exit fullscreen mode

To add text between the tags

<button>Click Me</button>
Enter fullscreen mode Exit fullscreen mode

Custom Attributes

Use []

button[data-id=btn-id]
Enter fullscreen mode Exit fullscreen mode

To add a custom attribute inside the tag

<button data-id="btn-id"></button>
Enter fullscreen mode Exit fullscreen mode

Numbering

Use $

ul>li*3#my-item${I'm number $}
Enter fullscreen mode Exit fullscreen mode

To add numbering for the element

<ul>
    <li id="my-item1">I'm number 1</li>
    <li id="my-item2">I'm number 2</li>
    <li id="my-item3">I'm number 3</li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Tag Attributes

Use :

script:src
Enter fullscreen mode Exit fullscreen mode

To add attributes

<script src=""></script>
Enter fullscreen mode Exit fullscreen mode

Place Holder Text

Use :

lorem6*3
Enter fullscreen mode Exit fullscreen mode

To add chunks of dummy text

Lorem ipsum dolor sit amet consectetur.
Expedita quasi aspernatur velit commodi repellendus?
Voluptas voluptatibus numquam et nam ratione.
Enter fullscreen mode Exit fullscreen mode

See the video for more explanation and check out the "Emmet Cheat Sheet" for more examples.

And make sure you start using shortcuts to accelerate your coding!

Top comments (1)

Collapse
 
67et98i9i59 profile image
ThatOneCatWithAHat

Thank you very much for helping me! i was in need of this for sooooooooooooooooooooooooooooooooooooooooooooooo Long :D Thanks again dev.to