Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut key to auto complete HTML structure

I am looking for the shortcut keys that I should use to autocomplete the structure of the HTML.

So for instance, when I type html and press a few keys the following structure should appear:

<!DOCTYPE html>
<html>
  <head>
    <title> </title>
  </head>
  <body>

  </body>
</html>

Note: I am using a MAC

like image 858
Illep Avatar asked Aug 31 '25 18:08

Illep


2 Answers

"!" After typing, press the "TAB" key on the keyboard.

like image 129
Darshana Ekanayake Avatar answered Sep 02 '25 08:09

Darshana Ekanayake


Perhaps you should look into templates for your IDE, for example in Sublime Text you have snippets which I would recommend looking into.

However, there is another workflow that you are able to use using a toolkit such as Emmet. The feature that you specifically want in Emmet is called "Expand Abbreviation". Essentially, you type out "CSS like" strings, put your caret at the end of the string and hit tab and Emmet will parse it into HTML. For example, the following string:

!doctype>html>(head>title)+(body)

will compile to the above (with a trailing closing tag of </!doctype> which is a bit awkward. However Emmet is quite clever and we can go one step further.. so expanding:

html:5

Will actually give you

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

</body>
</html>

Which is pretty much what you were looking for! And if you want to take it another step further, Emmet also supports expanding ! which is an alias for html:5. Only one character.

Check out Emmet's cheat sheet for more little bits.

like image 28
bitten Avatar answered Sep 02 '25 09:09

bitten