HTML Beautifier Tool

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>HTML Beautifier</title>

    <link rel="stylesheet" href="styles.css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.min.js"></script>

</head>

<body>

    <div class="container">

        <h1>HTML Beautifier</h1>

        <textarea id="inputHtml" placeholder="Paste your HTML code here..."></textarea>

        <div class="buttons">

            <button onclick="beautifyHtml()">Beautify</button>

            <button onclick="copyToClipboard()">Copy</button>

        </div>

        <textarea id="outputHtml" placeholder="Beautified HTML will appear here..." readonly></textarea>

    </div>

    <script src="script.js"></script>

</body>

</html>

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

body {
    background: linear-gradient(to right, #6a11cb, #2575fc);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
    padding: 10px;
}

.container {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
    max-width: 600px;
    width: 100%;
}

h1 {
    margin-bottom: 15px;
    color: #333;
}

textarea {
    width: 100%;
    height: 150px;
    padding: 10px;
    border: 2px solid #6a11cb;
    border-radius: 5px;
    margin-bottom: 10px;
    resize: none;
    font-size: 14px;
}

.buttons {
    display: flex;
    justify-content: space-between;
}

button {
    background: #6a11cb;
    color: #fff;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
    width: 48%;
}

button:hover {
    background: #4e0fa3;
}
function beautifyHtml() {
    let inputHtml = document.getElementById("inputHtml").value;
    if (inputHtml.trim() === "") {
        alert("Please enter HTML code!");
        return;
    }
    
    let beautifiedHtml = html_beautify(inputHtml, {
        indent_size: 4,
        wrap_line_length: 80,
        preserve_newlines: true
    });

    document.getElementById("outputHtml").value = beautifiedHtml;
}

function copyToClipboard() {
    let outputHtml = document.getElementById("outputHtml");
    if (outputHtml.value.trim() === "") {
        alert("No beautified HTML to copy!");
        return;
    }

    outputHtml.select();
    document.execCommand("copy");
    alert("Beautified HTML copied!");
}

Contact Form