HTML to Pug (Jade) Converter
Transform verbose HTML into clean, whitespace-sensitive Pug syntax. Optimize your frontend workflow by automatically handling indentation, classes, and IDs.
HTML Source
Pug Result
About
Pug (formerly Jade) is a high-performance template engine heavily used in the Node.js ecosystem. Its primary advantage is a terse, readable syntax that eliminates the need for closing tags and angle brackets. However, manually converting existing HTML templates to Pug is error-prone due to Pug's strict reliance on whitespace indentation. A single misaligned space can break the entire template.
This tool parses your HTML and reconstructs it using Pug's shorthand syntax. It intelligently converts <div class="box"> into .box, handles ID attributes like #main, and pipes multiline text correctly. It is an essential utility for developers modernizing legacy codebases or switching templating engines.
Formulas
Pug relies on depth-based indentation. The converter calculates depth d for each node in the DOM tree.
When constructing the tag string, the converter checks for the existence of `id` and `class` attributes to utilize Pug's dot notation, prioritizing brevity:
Reference Data
| Feature | HTML Input | Pug Output |
|---|---|---|
| Classes | <div class="nav item"> | .nav.item |
| IDs | <div id="header"> | #header |
| Attributes | <input type="text"> | input(type="text") |
| Content | <p>Hello</p> | p Hello |
| Nesting | <ul><li>A</li></ul> | ul li A |
| Self-closing | <img src="..."> | img(src="...") |