HTML to Pug Converter

Quickly convert HTML code to Pug code. Supports local browser conversion with code editor and auto-complete features.

9 times used | 5.0 rating

HTML Input

Pug Output

Usage Instructions

1

Enter HTML Code

Paste or enter your HTML code in the left input box.

2

Perform Conversion

Click the "Convert to Pug" button to convert HTML to Pug format.

3

View Results

View the converted Pug code in the right output box.

4

Use Results

Copy or download the converted Pug code for use in your projects.

Basic Knowledge of Pug Template Engine

What is Pug?

Pug (formerly Jade) is a high-performance template engine that compiles to HTML and is widely used in Node.js environments. Pug provides a concise, elegant syntax that allows developers to write structured HTML pages with less code, while supporting advanced features such as variables, mixins, and conditional statements.

Main Advantages of Pug

Concise syntax, reducing redundant code

Indentation-based syntax, improving code readability

Supports template inheritance and inclusion

Powerful logical expression support

Automatic escaping, enhancing security

Seamless integration with JavaScript ecosystem

HTML vs. Pug Syntax Comparison

HTML Syntax:
<div class="container">
  <h1>Welcome Page</h1>
  <p class="description">
    This is a sample paragraph
  </p>
  <ul>
    <li>List item 1</li>
    <li>List item 2</li>
  </ul>
</div>
Pug Syntax:
.container
  h1 Welcome Page
  p.description
    | This is a sample paragraph
  ul
    li List item 1
    li List item 2

Common Pug Syntax Examples

Elements and Text
h1 Heading text
Classes and IDs
div.container#main
Inline Attributes
a(href='link', title='Title')
Nested Content
div
  p Nested text
Comments
//- Comment that won't be output
// HTML comment that will be output
Variables
- var name = 'User'
p= name

Conversion Notes

  • Complex HTML structures may require manual adjustments to conform to Pug best practices
  • Pug relies on strict indentation, ensure converted code has correct indentation
  • Script and style blocks in HTML may need special handling after conversion
  • For large projects, using professional Pug converters or framework plugins is recommended