How to Make a Leet Speak Converter With HTML and JavaScript

Updated · 5 min read · By

A leet speak converter swaps letters for look-alike numbers as you type, so "hacker" becomes "h4ck3r". It is a short, satisfying project that teaches how to read what a user types and change it one character at a time.

The word hacker converted to h4ck3r using a lookup table of letter swaps in JavaScript
Full version: our Hacker Text Generator adds glitch, monospace and wide text. For the background, see what is leet speak?

The complete code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Leet Speak Converter</title>
  <style>
    body { background: #000; color: #00ff66; font-family: "Courier New", monospace; max-width: 700px; margin: 40px auto; padding: 0 16px; }
    textarea { width: 100%; height: 110px; box-sizing: border-box; background: #000; color: #00ff66; border: 1px solid #00ff66; font: 18px "Courier New", monospace; padding: 10px; }
    #result { min-height: 60px; margin-top: 20px; font-size: 26px; word-break: break-word; }
  </style>
</head>
<body>
  <h1>Leet Speak Converter</h1>
  <textarea id="input" placeholder="Type here..."></textarea>
  <div id="result"></div>

  <script>
    const leet = { a: "4", e: "3", i: "1", o: "0", s: "5", t: "7" };

    const input = document.getElementById("input");
    const result = document.getElementById("result");

    function toLeet(text) {
      let output = "";
      for (const letter of text) {
        const swap = leet[letter.toLowerCase()];
        output += swap ? swap : letter;
      }
      return output;
    }

    input.addEventListener("input", function () {
      result.textContent = toLeet(input.value);
    });
  </script>
</body>
</html>

How to use this code

  1. Get the file. Press Download above the code to save it as leet-converter.html. Or press Copy code, paste it into a plain text editor (Notepad on Windows, TextEdit in plain-text mode on a Mac, or a code editor such as VS Code) and save it as leet-converter.html. The name must end in .html, not .txt.
  2. Open it. Double-click the file. It opens in your web browser and starts working straight away.
  3. Change it. Open the same file in the text editor, edit something, save, and refresh the browser page to see the result.

Nothing needs to be installed, and the file works without an internet connection.

How the code works

Easy changes to try

Add more swaps

Extend the table with any pairs you like:

const leet = { a: "4", b: "8", e: "3", g: "9", i: "1", l: "1", o: "0", s: "5", t: "7", z: "2" };

Hard leet with symbols

Replacements can be longer than one character. Because the backslash has a special meaning in JavaScript, write it twice:

const leet = { a: "4", e: "3", k: "|<", m: "/\\/\\", n: "|\\|", v: "\\/", w: "\\/\\/" };

Convert back to normal text

Make a second table with the pairs reversed, such as { "4": "a", "3": "e" }, and use it in a copy of toLeet. It will not be perfect, because 1 could have been an I or an L.

Add a copy button

Add <button onclick="navigator.clipboard.writeText(result.textContent)">Copy</button> under the result.

One warning: leet swaps do not make a password strong. Password-guessing tools try these substitutions automatically.

FAQ

What is leet speak?

A way of writing where letters are replaced by look-alike numbers and symbols, such as 4 for A and 3 for E.

Why do capitals turn into numbers too?

The code lowers each letter before looking it up, so A and a both become 4.

Can I add my own letters?

Yes. Add more pairs to the leet table, separated by commas.

More tools

See all tools

Keep reading