HTML to Pug Converter

HTML Input
Conversion Options
Pug Output
HTML to Pug Conversion Rules
<div class="container">div.container or .container
<div id="main">div#main or #main
<p>Text</p>p Text
<img src="img.jpg" alt="Image">img(src="img.jpg" alt="Image")
<!-- Comment -->//- Comment
• Nested elements use indentation instead of closing tags

HTML to Pug Converter

Convert HTML markup to Pug template syntax. Pug (formerly Jade) is a clean, whitespace-sensitive template engine for Node.js that produces HTML.

Key Features

  • Clean Syntax: No closing tags, indentation-based structure
  • Shorthand Notation: CSS-like selectors for classes and IDs
  • Attribute Handling: Proper conversion of HTML attributes
  • Comment Preservation: Converts HTML comments to Pug comments
  • Text Content: Handles inline and block text properly
  • Nested Structure: Maintains proper indentation hierarchy

HTML vs Pug Comparison

HTML Input
<div class="container"><header id="main-header"><h1 class="title">Welcome</h1><nav class="navigation"><ul><li><a href="/">Home</a></li><li><a href="/about">About</a></li></ul></nav></header><main><p>Content here</p></main></div>
Pug Output
.containerheader#main-headerh1.titleWelcomenav.navigationullia(href="/")Homelia(href="/about")AboutmainpContent here

Pug Syntax Benefits

  • Cleaner Code: No closing tags, less verbose
  • CSS Selectors: Use .class and #id shortcuts
  • Indentation-Based: Structure defined by whitespace
  • Template Features: Variables, includes, mixins
  • Faster Writing: Less typing than HTML

Use Cases

  • Converting existing HTML templates to Pug
  • Migrating from HTML to Node.js template engines
  • Learning Pug syntax and structure
  • Cleaning up verbose HTML markup
  • Creating maintainable templates

Related Tools

Enhance your template workflow with our other tools: Pug to HTML, HTML to JSX, HTML Beautifier, and HTML Formatter.