TodayTools

HTML, CSS and JavaScript minifier

Paste code and get a smaller file. Ctrl+C copies the result.

PrivateNo uploadsRuns in your browser

Donate
Language
Mode

Minify removes spaces, line breaks and comments the browser does not need.

A man planning on a whiteboard

For a faster site

Lighter pages, faster loads.

Speed fix. Raj trims his site's code before launch.

BeforePages that load slowly

With sdevSmaller files in one click

  • Two colleagues looking at a tablet

    Quick to open

    Visitors see the page in a blink.

  • Young Man

    More orders

    A faster shop brings more orders.

How to minify HTML, CSS and JavaScript

  1. Paste or open

    Paste HTML, CSS or JavaScript, open a file or drop it on the Input pane. The language is picked for you; change it with the tabs if needed.

  2. Choose options

    Minify makes it small; Beautify makes it readable. For JavaScript you can shorten names and remove console logging. HTML can also minify its inline styles and scripts.

  3. Copy or download

    See the size before and after, also after gzip. Press Copy, Ctrl+C with nothing selected, or Download to save a .min file.

Good to know

  • JavaScript is minified by terser: it removes spaces and comments, shortens names that only your code uses, and simplifies code such as if statements, without changing what it does.
  • CSS is read piece by piece: text in quotes, url() addresses and custom properties (--name) stay exactly as written, and calc() keeps its spaces and units. Colours like #ffffff become #fff and 0px becomes 0.
  • HTML keeps the spacing between words and inside <pre> and <textarea>. Inline <style> and <script> blocks are minified with the same tools; a block with a mistake is left as it was and you are told which line.
  • Files over 2 MB stay out of the editor and are read by the worker, so large bundles minify without freezing the page.
  • Errors show the line and column. Go to error selects the spot in the input.

Where people use it

  • Make a page load faster

    Smaller files load quicker, mostly on slow phone networks.

  • Ship a widget or snippet

    Minify a script before you share it so it is small and tidy.

  • Read squeezed code

    Switch to Beautify to spread minified code back over many lines.

  • Check for errors first

    Find unclosed tags or missing braces before you minify.

    JavaScript validator
  • Edit and preview

    Change the HTML and see the page live.

    HTML editor, formatter and live preview

Why this one

It shows the real saving for each file, including after gzip, so you know if it was worth it.

  • Handles HTML, CSS and JavaScript.
  • Shows how much smaller the file gets, before and after gzip.
  • Works on large files.
  • Your code never leaves your device.

What you can change

  • Minify or beautify
  • Shorten names
  • Remove console.log
  • Keep licence comments
  • Minify inline CSS and JS in HTML

People find this page by searching

  • minify html
  • minify css
  • minify javascript
  • js minifier online
  • css minifier
  • html compressor
  • beautify javascript
  • reduce javascript file size
Cite this tool
  • APA
    sdev.in. (n.d.). HTML, CSS and JavaScript minifier [Web tool]. https://www.sdev.in/tools/code-minifier
  • MLA
    "HTML, CSS and JavaScript minifier." sdev.in, https://www.sdev.in/tools/code-minifier.
  • Chicago
    sdev.in. "HTML, CSS and JavaScript minifier." https://www.sdev.in/tools/code-minifier.
  • BibTeX
    @misc{sdev-code-minifier,
      title = {HTML, CSS and JavaScript minifier},
      author = {{sdev.in}},
      howpublished = {\url{https://www.sdev.in/tools/code-minifier}},
      note = {Web tool}
    }

Questions people ask

Is the minified code safe to use in place of the original?

Yes, it does the same thing. JavaScript is minified by a well-tested minifier that understands the code, not by search and replace. CSS is read token by token, so text in quotes, url() addresses and calc() sums are kept exactly. Test the page once after minifying, as you would after any build step.

What do the gzip numbers mean?

Most web servers compress files with gzip before sending them. The gzip size is close to what visitors really download, so it is the fairest way to compare before and after.

What does Shorten names do?

It renames variables and function arguments that are only used inside your code to one or two letters. Names other scripts can see, such as global functions, are left alone.

Why are some comments kept?

Comments that start with /*! or mention @license usually carry a licence that must stay with the code. Untick Keep licence comments to remove them too.

Can I turn minified code back into readable code?

Yes. Choose Beautify to format it with line breaks and indent. Shortened names cannot be brought back, but the structure becomes easy to read.

Is my code uploaded?

No. Everything runs in a background worker in your browser. Nothing is sent to a server.

Donate