HTML to Pug Converter
Turn HTML into clean Pug templates in a second. Closing tags disappear, nesting becomes indentation, classes and ids use the short .class and #id style, and short text stays on the same line as its tag.
How to Convert HTML to Pug
Quick answer: paste your HTML or open a file; the Pug appears below. Copy it or download the .pug file.
-
1
Add your HTML
Paste it or open a file.
-
2
Choose options
Adjust the output on the right.
-
3
Check the Pug
It updates as you type.
-
4
Copy or download
Save it as .pug.
What You Get
What Is HTML?
HTML is the language every web page is written in. Elements are marked with opening and closing tags, such as paragraphs, headings, links, images, lists and tables, and browsers turn them into the pages you see. Every website builder, content system and email editor accepts HTML.
What Is Pug?
Pug is a template language that writes HTML with indentation instead of closing tags. A line such as a.button(href="/shop") Buy now becomes a full link element, nesting is shown by indenting, and loops, conditions and variables can generate repeated parts of a page. Many websites and web apps use Pug templates because they are short and easy to read.
Why Convert HTML to Pug?
Moving an existing page into a Pug project by hand is slow and easy to get wrong. Converting gives you a correct starting template instantly, which you can then split into layouts and mixins. It is also a quick way to learn Pug by comparing HTML you know with its Pug version.
How the Conversion Works
Your HTML is read by the browser's own HTML reader, so even untidy markup with missing closing tags is understood the same way a browser would. Each element becomes a line with its tag name, ids and classes as shortcuts, and other attributes in brackets. Text goes after the tag or on its own line with a pipe, comments become Pug comments, and script, style and pre contents are kept exactly as blocks.
Example
The sample page becomes a short template: header.top contains h2#title and a p with the strong text inline, ul.products holds the list items, and the link becomes a.button(href='/shop') Shop now. The doctype line is kept at the top.
Tips
Div elements with an id or class are written as just #id or .class, which is standard Pug. Turn off the shortcuts option if you prefer every attribute in brackets. Check inline formatting such as links inside sentences, which Pug writes as separate lines.
Who Uses It?
Developers adopting Pug, students, and teams converting existing pages into templates. Because the text never leaves the device, it is also safe for drafts and internal documents.
Step by Step
Paste your HTML into the input box, drop a file onto it, or press Open File. The Pug appears in the output box straight away and updates as you type, so you can fix mistakes and watch the result change. Adjust the options on the right if needed. When it looks right, press Copy to put the result on your clipboard, or Download to save it as a .pug file. Press Sample at any time to see an example.
Using Your Pug
Save the template with the .pug extension in your project's views or templates folder. From here you can split repeated parts such as headers and footers into separate files with include, replace repeated items with each loops, and turn hard-coded text into variables passed in by your application. Compile it once to check the result matches the original page before replacing it. Keep indentation consistent, using the same number of spaces throughout the file.
Private, Free and Instant
The converter is free, with no sign-up and no limit beyond the 5 MB text size. Everything runs in your browser, so drafts, internal documents and unpublished content are never uploaded or stored. It works on Windows, Mac, Linux and Chromebooks, and on phones and tablets.
HTML to Pug: Writing Templates Without Angle Brackets
Pug, once called Jade, is a template language for Node.js. It uses indentation instead of closing tags and has variables, loops and includes.
What conversion looks like
<div class="card"><h2>Title</h2></div> becomes div.card with an indented h2 Title line. Ids use a hash, as in div#main, and attributes go in brackets.
Tip
Check the indentation, because Pug uses it to define structure. To turn Pug back, see Pug to HTML.
Frequently Asked Questions
Questions about HTML to Pug