Developer Guide

How to Minify or Beautify HTML, CSS and JavaScript Online (Free)

Code that is easy to read and code that is fast to download are not the same file. The ToolTiny Code Minifier & Beautifier does both jobs on one page: Minify strips a file down for production, Beautify lays it out again for people. This guide follows a real screen recording in which we formatted an 8 KB PHP page. The code itself is blurred in the screenshots because it is internal, but every number below is the one we saw on screen.

Minify or Beautify?

Minify CodeBeautify (Format)
What it doesRemoves comments, spaces and line breaks; can shorten JavaScript namesAdds line breaks and indentation
ResultSmaller file, hard to readReadable file, usually a little larger
Use it forFiles you publish on a websiteReading, reviewing or editing code, including minified code from someone else
OptionsJavaScript: rename variables, compress, license comments, ES module. HTML: inline CSS and JS, remove commentsIndent (2 spaces, 4 spaces, Tab), keep blank lines

Keep the readable version as your source and publish the minified one. With Use as input you can go from one to the other in a click.

Watch the Whole Process

The recording opens the tool from the menu, looks at the JavaScript and HTML minify options, pastes a PHP page, tries the language list and the Open file button, then formats the page with different indent settings and finishes with the result buttons.

How to Minify or Beautify Code, Step by Step

  1. Open the Code Minifier

    Open the Developer menu in the top bar and choose Code Minify / Beautify, or go straight to tooltiny.com/code-minify.html.

    Developer menu with Code Minify / Beautify highlighted
    Developer → Code Minify / Beautify
  2. Two modes: Minify and Beautify

    At the top of the tool are two buttons. Minify Code removes comments and spaces to make files smaller. Beautify (Format) adds line breaks and indentation so code is easy to read. The page remembered the mode we used last time, which is why it opened on Beautify.

    Code Minifier page with Minify Code and Beautify (Format) buttons
    Minify or Beautify
  3. Check the JavaScript options

    In Minify mode with JavaScript selected, the Options bar shows Rename variables (mangle), Compress code, Keep license comments and ES module. In the video we untick and tick them to show they can be switched off one by one. Untick Rename variables if other files call your function names directly.

    Minify mode with the JavaScript options Rename variables, Compress code, Keep license comments and ES module
    JavaScript minify options
  4. Paste your code

    Paste code into Input Code. We pasted a PHP page that mixes PHP and HTML (blurred here because it is internal code). The tool noticed and showed: “This looks like HTML, so the language was switched from JavaScript.” The input size appears under the box: 8 KB.

    Pasted PHP and HTML code, blurred, with the language switched to HTML / PHP and a notice under the boxes
    Language detected automatically
  5. Pick the language yourself if needed

    The list next to Input Code has JavaScript (.js), CSS (.css) and HTML / PHP (.html, .php). If the guess is wrong, choose the right one. For HTML the options change to Minify inline CSS and JS and Remove comments.

    Language list open with JavaScript, CSS and HTML / PHP
    JavaScript, CSS or HTML / PHP
  6. Or open a file

    Instead of pasting, click Open file under the input box, or drag a file onto it. The page accepts .js, .css, .html and .php files, and Download later keeps the same name with .min added.

    Open file button under the input box
    Open file or drag and drop
  7. Switch to Beautify

    Click Beautify (Format). Because the input box already had code, the result appeared straight away: 8.06 KB (gzip 2.13 KB) from an 8 KB input. The HTML around the PHP is indented; the code inside <?php … ?> is left exactly as written.

    Beautify mode with the formatted result, code blurred, and the size 8.06 KB
    Formatted: 8.06 KB
  8. Choose the indent

    Open Indent and pick 2 spaces, 4 spaces or Tab. The result updates at once. With our file, 4 spaces made it 8.18 KB and Tab 7.99 KB, because one tab character replaces several spaces.

    Indent list open with 2 spaces, 4 spaces and Tab; result size 8.18 KB
    4 spaces: 8.18 KB
  9. Keep or remove blank lines

    Keep blank lines keeps the empty lines you used to separate blocks. Unticked, they are removed: our result went from 7.99 KB to 7.96 KB (gzip 2.11 KB).

    Keep blank lines unticked with Tab indent, result size 7.96 KB
    Blank lines removed: 7.96 KB
  10. Run it again any time

    Press Beautify Code (or Minify Code) to process the input again, for example after editing it. Ctrl+Enter in the input box does the same.

    Beautify Code button pressed, result 7.99 KB with Tab indent
    Beautify Code / Ctrl+Enter
  11. Use, download or copy the result

    Under the result: Use as input moves it back into the input box (handy to minify a file you just formatted), Download saves it as a file and Copy puts it on the clipboard.

    Use as input, Download and Copy buttons under the result
    Use as input, Download or Copy

What the Settings Did to Our 8 KB Page

SettingResult sizegzip size
Original input8 KB2.14 KB
Beautify, 2 spaces8.06 KB2.13 KB
Beautify, 4 spaces8.18 KB2.14 KB
Beautify, Tab7.99 KB2.13 KB
Beautify, Tab, no blank lines7.96 KB2.11 KB

The raw size moved by about 2% between settings, and the gzip size, which is what a server actually sends, hardly moved at all. Pick the indent for readability; to save bytes, use Minify instead.

Good to Know

Follow ToolTiny for short tutorials

One-minute clips on converting, repairing and editing documents, images and text.

Tips

Minify or beautify your code now

HTML, CSS, JavaScript and PHP pages. Free, private, no sign-up.

Open Code Minifier

Related ToolTiny Tools

Frequently Asked Questions

What is the difference between minifying and beautifying code?
Minifying removes comments, spaces and line breaks (and, for JavaScript, can shorten variable names) so the file downloads faster. Beautifying does the opposite: it adds line breaks and indentation so people can read the code. The same tool page does both.
Can I format a PHP file?
Yes, choose HTML / PHP. The HTML around your PHP is indented, while the code inside <?php … ?> blocks is kept exactly as written. In our test the tool recognised a pasted PHP page and switched the language to HTML / PHP by itself.
Is my code uploaded anywhere?
No. The page says your source code is processed in your browser and never sent to a server. The formatting libraries are downloaded from a public CDN the first time you use a feature, but your code is not.
Which indent should I choose?
Use whatever your team or project already uses. 2 spaces is common in JavaScript and HTML, 4 spaces in PHP and many back-end languages, and Tab lets each person set their own width. Tabs also make the file a little smaller: in our test 7.99 KB with Tab against 8.18 KB with 4 spaces.
What does Keep blank lines do?
It keeps the empty lines you put between blocks of code, so the structure you chose stays visible. Untick it to remove them. In our file that saved 0.03 KB, so it is mainly about readability, not size.
What do the JavaScript minify options mean?
Rename variables (mangle) shortens local names, Compress code removes dead code and simplifies expressions, Keep license comments keeps /*! … */ notices, and ES module allows import, export and top-level await. All can be switched on or off.
What does the gzip size under each box mean?
It is how big the text would be after gzip compression, which is what most web servers actually send. It is the best guide to what visitors download.
Can I open a file instead of pasting?
Yes. Click Open file under the input box or drag a .js, .css, .html or .php file onto it. Download then saves the result with the same name.
Can I minify code I just beautified?
Yes. Click Use as input to move the result back into the input box, switch to Minify Code and press the button.
Is the tool free?
Yes. It is free, needs no account and works in any modern browser on desktop or mobile.