Open In App

PugJS Basic Tags

In this article, we will learn about pug basic tags and see how they get compiled into HTML code.

Project Setup:



Step 1: Install pug by running the following command. -g is for global install and it is optional.

npm install pug-cli -g



Step 2: Open the project folder code editor. Make an index.pug file, and an index.html file in the root project directory. Inside html, make an index.html file. Our directory structure will now look like this:

Project Structure

Step 3: Now we will write pug template code in index.pug file and see it’s HTML output in index.html file. For automatic re-compiling of pug template code to HTML on file save, run below command in the terminal:

pug -w ./ -o ./html -P

“-w ./”means watch any changes in pug file in the current directory, “-o ./html -P” means save the output in html file in the current directory and pretty print it (format it correctly). You should get the following upon running the command:

Now let’s understand tags in PugJS and see the corresponding compiled HTML.


Article Tags :