CODING ACADEMY

View Original

Save Time When Coding HTML By Using Emmet

Hand coding lots of HTML can be time consuming. By utilising the power of Emmet in your coding environment you might actually start to enjoy coding HTML again.

WHAT IS EMMET?

Most text editors have the ability to use code snippets and can store these and use the equivalent of macros to retrieve blocks of code.

Emmet takes this idea to a whole new level, allowing you to quickly generate code with a few simple keystrokes.

I use CodeAnywhere.com as my online IDE and it has the benefit of having Emmet pre-installed. You will need to find out if your own IDE or coding platform of choice supports Emmet.

Let's get right into it and start with probably the simplest of all commands.

In my IDE I can simply type in an exclamation mark and then hit the tab key:

See this content in the original post

and the result is:

See this content in the original post

Let's say I wanted to produce an unordered list with a list item:

See this content in the original post

will produce:

See this content in the original post

What if I wanted 5 list items:

See this content in the original post

which produces:

See this content in the original post

We can take this a step further. If I wanted to add a class to each list item:

See this content in the original post

which gives:

See this content in the original post

We can give each list item an id and have this auto-increment:

See this content in the original post

which generates:

See this content in the original post

We can work with tables. For example, let's say I wanted to create a table with 3 rows and 5 columns, then I can use:

See this content in the original post

which is a lot faster than typing out the following:

See this content in the original post

We can combine classes and ids as follows:

See this content in the original post

which gives:

See this content in the original post

We can build up page elements quickly and efficiently and even use groupings with parenthesis:

See this content in the original post

which gives:

See this content in the original post

Generating a simple navbar is just a case of:

See this content in the original post

With the following result:

See this content in the original post

CSS

Emmet can also be used for CSS.

Dealing with simple things like width, height, padding etc

See this content in the original post

gives:

See this content in the original post

Through to more complex rules for linear gradient and vendor prefixes:

See this content in the original post

which gives:

See this content in the original post

There are many options to explore and not all can be covered in this brief tutorial.

I strongly suggest you start with some basic commands and start to use Emmet within your toolbox to save you time.