DEV Community

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

Posted on • Edited on

60

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!

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

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

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay