---
title: Minification
project: Total.js V5
version: 0.0.20
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/reference/minification/
updated: 2026-11-18T16:57:24.576Z
---

# Minification

> U.minify_css(), U.minify_js() and U.minify_html().

## API

### U.minify_css(css)

Type: `method`

Minifies CSS and compiles nested rules and `$variables`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `css` | `String` | yes |  | CSS source. |

Returns: `String` Minified CSS.

Removes comments and whitespace, shortens `margin` and `padding` (`0 0 0 0` to `0`, `10px 20px 10px 20px` to `10px 20px`) and colours such as `#FFFFFF`. A rule that contains only other rules is expanded (`.a { .b { } }` to `.a .b{}`). Variables are declared as `$name: value;` and used as `$name`. On an error the function logs `CSS compiler error` and returns an empty string.

Example: Nested rules
```js
U.minify_css('.menu {\n\t.item { color: red; }\n\t.active { font-weight: bold; }\n}');
// '.menu .item{color:red}.menu .active{font-weight:bold}'
```

Example: Variables
```js
U.minify_css('$brand: #0066FF;\n.button { background: $brand; }');
// '.button{background:#0066FF}'
```

### U.minify_js(js)

Type: `method`

Minifies JavaScript.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `js` | `String` | yes |  | JavaScript source. |

Returns: `String` Minified code.

Removes comments, line breaks and unneeded whitespace. Strings are kept as they are. It does not rename variables.

Example: Minify
```js
U.minify_js('if (a) {\n\tconsole.log(a); // log\n}'); // 'if(a){console.log(a);}'
```

### U.minify_html(html)

Type: `method`

Minifies HTML.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `html` | `String` | yes |  | HTML source. |

Returns: `String` Minified HTML.

Removes comments (not conditional comments such as `<!--[if IE]>`) and collapses runs of spaces between words to one space. Line breaks and indentation between tags are kept. The content of `<script>`, `<textarea>`, `<pre>`, `<code>` and `<readme>` is not changed. Inline `<script>` and `<style>` are minified with the JS and CSS minificators when `$minifyjs` and `$minifycss` are on.

Example: Minify
```js
var html = U.minify_html(source);
```
