HTML to Jade (Pug) Converter
CV-60Paste HTML and get the same markup in Jade, the template language that is now called Pug. Nesting becomes indentation and ids and classes become shortcuts.
Runs in your browser. Nothing is uploaded.
HTML
Pug (Jade)
How to use it
- Paste your HTML into the input box, or open an .html file and drop it on the box.
- Pick 2 spaces, 4 spaces or a tab for the indent.
- Choose whether to keep HTML comments as // lines.
- Copy the result or download it as a .pug file.
How the conversion is written
A div with an id and classes becomes #app.card.wide. Other elements keep their name, with the rest of the attributes in brackets, such as a(href="/docs" target="_blank"). Attributes with no value, like checked, are written without one. Text follows the tag on the same line. Script, style, pre and textarea bodies become a dot block: the tag name, a dot, then the text indented below. Comments become // lines.
Mixed text, entities and interpolation
When an element holds both text and tags, the tool keeps the whole inner HTML on one line as text, because that is valid Pug and keeps the order of the words and tags. Line breaks inside text are collapsed to a space. The characters < > and & in text are written as entities so they are not read as markup. If your text contains #{, !{ or #[, a backslash is added in front, because Pug treats those as interpolation. Look at those lines yourself.
What is not produced
The output is plain markup. No mixins, includes, variables, loops or conditionals are created, since HTML has nothing to map them from. Whitespace-only text between tags is dropped. Indentation inside pre blocks may change, because a dot block removes the common indent of its lines. The HTML is read with a small tolerant tokenizer, not a full HTML5 parser.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
No HTML found to convert. | The input is empty or holds only whitespace or comments that were dropped. | Paste some HTML, or turn on Keep HTML comments if the input is only a comment. |
Questions people ask
Is Jade the same as Pug?
Pug is the new name of Jade. The project was renamed, and the tool writes Pug syntax, so the files use the .pug extension. The basic tag, id, class and attribute forms the tool writes are the ones people mean by Jade.
How do I convert HTML to Jade?
Paste the HTML and the Jade appears as you type. Choose the indent size and whether to keep comments, then copy the result or download it. There is nothing to install and nothing leaves your browser.
How are classes and ids written in the output?
They use the shortcut form: #id and .class directly after the tag name, with the tag name left out for a div. An id or class with unusual characters stays in the attribute list in brackets.
Does it handle inline tags like b and a inside a paragraph?
Yes. A paragraph that mixes text and tags is written on one line with the inner HTML left as is, for example p Read the <b>docs</b>. That is valid Pug and keeps the word order.
Can I go back from Jade to HTML?
Yes, with the Jade to HTML converter on this site. It compiles the common subset of Pug and reports any unsupported line, such as a variable or a loop, with its line number.
About this tool
Output is Pug, the name Jade was given when it was renamed, so the file extension is .pug. An element is written as tag#id.class(other="attributes"); the tag name is left out for a div that has an id or class. An id or class with characters other than letters, digits, _ and - stays in the attribute list instead. An attribute with no value is written without one. Text follows the tag on the same line. An element that mixes text and tags is written as one line with the inner HTML left in the text, and line breaks in text are collapsed to one space. Text is written with < > and & as entities so Pug does not read it as markup. Script, style, pre and textarea bodies are written as a dot block, and the common indent of their lines is removed, so indentation inside pre may change. Comments become // lines, or are dropped when the option is off. Text containing #{, !{ or #[ gets a backslash in front, because Pug reads those as interpolation; look at such lines yourself. Whitespace-only text between tags is dropped. No mixins, includes or code are produced.