Format Code Now
/
ConvertHTML to Pug Next: HTML to XML ›

HTML to Pug Converter

CV-101

Paste HTML and get the same markup as a Pug template, with #id and .class shorthand, attributes in parentheses and indentation for nesting.

Runs in your browser. Nothing is uploaded.

HTML

Pug

How to use it

  1. Paste your HTML.
  2. Pick the indent size: 2 spaces, 4 spaces or a tab.
  3. Choose whether to keep comments.
  4. Press HTML to Pug, then copy or download the .pug file.

What the Pug looks like

Tags lose their angle brackets and closing tags, and nesting becomes indentation. An id and classes become shorthand, so <div id="top" class="a b"> turns into #top.a.b, and a div with neither keeps the word div. Other attributes go in parentheses, with a bare name for an attribute that has no value. A tag with one line of text keeps it on the same line, and mixed content uses | lines. Script, style, pre and textarea text becomes a tag. block.

Things to check

Pug writes plain text as it is, so character references such as &amp; are copied unchanged. Attribute values are decoded, because Pug escapes them again when it renders. Runs of whitespace collapse to one space outside text blocks, and whitespace between block-level tags is dropped. A literal #{ or #[ in your text is escaped with a backslash. The output was not compiled with Pug here, so run it through Pug in your project to confirm.

Error messages and what to do

MessageWhat it meansFix
No HTML found to convertThe input has no elements or text.Paste some markup.

Questions people ask

How do I convert HTML to Pug?

Paste the HTML, press HTML to Pug and copy the result. Each tag becomes a Pug line, nesting becomes indentation, and ids and classes use the # and . shorthand. Save the output as a .pug file.

Is Pug the same as Jade?

Pug is the later name of Jade. This tool writes Pug syntax, so check any Jade-only features in your own version. For plain markup the two read alike.

Does it convert inline scripts and styles?

Yes. Script, style, pre and textarea with only text become a block that ends with a dot, such as script., and the lines are indented under it exactly as written.

What happens to HTML comments?

They become // lines, which Pug renders back as HTML comments when it compiles the template. Untick Keep comments to drop them from the Pug output.

Does it handle broken HTML?

Mostly. The reader closes unclosed tags such as li and p the way browsers do and ignores stray end tags. It does not validate the markup, so check the nesting of badly broken input before you rely on it.

Can I convert Pug back to HTML?

Yes, with the Pug to HTML tool on this site, which handles static Pug. Templates that use variables, loops or includes need the real Pug compiler.

About this tool

Produces static Pug: tag names, #id and .class shorthand (a div with an id or class drops the word div), attributes in parentheses, text inline or on | lines, and indentation for nesting. A class or id that is not a plain name stays as an attribute. Script, style, pre and textarea with only text become tag. blocks. Text is copied as written, so character references such as &amp; stay as they are (Pug does not escape plain text); attribute values are decoded because Pug escapes them again on output. Whitespace runs collapse to one space except in those text blocks, and whitespace between block-level tags is dropped. Comments become // lines unless you turn them off. A literal #{ or #[ in text is escaped with a backslash. The result was not compiled with Pug here; check it in your own project.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.