Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for My 5 favorite HTML/CSS shortcuts in VSCode
Seth A Burleson
Seth A Burleson

Posted on • Edited on

     

My 5 favorite HTML/CSS shortcuts in VSCode

Tired of typing in<div> only to be forced to scroll back and type in the class elements? Exhausted by nesting div into div to make your beautiful grid layout in what was supposed to be a flash, but turned into leaning on your left arrow key until your hand went numb? If you said yes to any of that, you need to meet my buddy Emmet. Emmet helps devs by allowing you to type in snippets within VSCode, and have beautiful HTML come out the other end.

5. Quick siblings

Good ol' addition symbols (+) will get you sibling elements. Lets say you have a div with an image, h3, and paragraph. With your cursor in the body of the div, just typeimg+h3+p and emmet will give you the beautiful html :

      <div>          <img src="" alt="">          <h3></h3>          <p></p>      </div>
Enter fullscreen modeExit fullscreen mode

And your cursor will be ready to insert the src for your image.

4. Nested elements

What if you need nested elements? Just change out the + for a >!body>main>div>h1 will give you

      <body>          <main>              <div>                  <h1></h1>              </div>          </main>      </body>
Enter fullscreen modeExit fullscreen mode

3. Multiple elements

Making a table can be time consuming, unless you're using emmet to its full potential. Using the same technique, parentheses will let you multiply the number of nested children.div>(p*5) turns into:

      <div>          <p></p>          <p></p>          <p></p>          <p></p>          <p></p>      </div>
Enter fullscreen modeExit fullscreen mode

2. fast ids

If you want to put some divs in with ids already attached, you can use css-style syntax.#article becomes<div></div>. But you can combine other techniques with this, for instancediv>#hello>p becomes

       <div>          <div>              <p></p>          </div>      </div>
Enter fullscreen modeExit fullscreen mode

1. Divs, but with class!

If you paid attention during the last tip you'll probably already understand how to use classes. Just add a dot..bold becomes<div></div>. You can also chain them together to add more (.bold.bigtitle.nav-bar-header) or combine any previous methods to get these going. Trydiv>#art1.article>#art2.article>#art3.article and you'll see how many things we've just covered can be combined.

Let me know what your favorite shortcuts are!

Top comments(4)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
tarek_mo profile image
tarek mo
  • Location
    Meknes, Morocco
  • Joined

Also m0 for margin : 0
p0 for padding : 0

Small details add up!

CollapseExpand
 
juz14girl profile image
juz14girl
  • Location
    Sweden
  • Joined

This is really cool. I'm new. Thanks for the help.

CollapseExpand
 
alexmeddeiros profile image
Alex Medeiros 💾
Looking for opportunity.
  • Joined

Uau.... Thanks. 👏👏👏

CollapseExpand
 
fullsailer profile image
John Flynn
  • Joined

Emmet is my favorite right now.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

A fullstack C# developer chronicling my journey of learning code.
  • Location
    Greensboro NC
  • Joined

More fromSeth A Burleson

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp