HTML Entities, Formatting and Minifying Explained
Web & SEO · Published October 17, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael
Web pages are built from three kinds of text: HTML for structure, CSS for style and JavaScript for behavior. Each has its own housekeeping, from escaping special characters to making the files smaller. This guide covers the three jobs: escaping, formatting and minifying.
Escaping characters in HTML
Some characters have a special meaning in HTML, so to show them as plain text you write them as entities. The less-than sign becomes <, the greater-than sign >, the ampersand & and the quotation mark ". If text from a user is placed in a page without escaping, someone can slip in a script and attack other visitors, which is called cross-site scripting. Escaping on output is the basic defense. The HTML Entity Encoder converts text both ways.
| Character | Entity | Why |
|---|---|---|
& | & | Starts every entity |
< | < | Starts a tag |
> | > | Ends a tag |
" | " | Ends a double-quoted attribute |
' | ' | Ends a single-quoted attribute |
| Non-breaking space | | A space that never wraps onto a new line |
If a page is saved as UTF-8 and says so, you can type accented letters, symbols and emoji directly and skip entities for them. Use entities for the reserved characters above.
Formatting versus minifying
- Formatting adds line breaks and indentation so people can read the code. It makes files a little bigger.
- Minifying removes everything a browser doesn't need, such as comments, spaces and line breaks. It makes files smaller and harder to read.
Use the HTML Formatter when you inherit a page that's one long line, and keep the readable version as your source. Minify only the copy that you publish.
What minifying saves
The CSS Minifier and the JavaScript Minifier strip comments and whitespace. On a small script, the saving can be around a third, and across real stylesheets it's often 10 to 40 percent before compression. Servers also compress files with gzip or Brotli, which already shrinks repeated spaces well, so the extra gain from minifying is smaller than it looks, but it still helps.
| File type | Typical saving from minifying | Notes |
|---|---|---|
| CSS | 20 to 40 percent | Comments and whitespace go. Values stay as written |
| JavaScript, comments and spaces only | 20 to 40 percent | Variable names stay. A bundler with renaming saves more |
| HTML | A few percent | Pages are mostly content, which can't be shortened |
A sensible workflow
- Write and edit readable files, formatted consistently.
- Before publishing, minify copies of the CSS and JavaScript and save them under separate names, such as style.min.css.
- Point the page at the minified copies.
- Turn on server compression, which saves far more than minifying alone.
- Load the page and check the main features.
Safety notes
- The JavaScript minifier here removes comments and spaces but doesn't rename your variables, so it can't change what your code does. Build tools that rename variables save more, but need testing.
- Keep your original files. Minified code is very hard to edit.
- Test the page after minifying, especially scripts that rely on line breaks to end statements.
- In HTML, leave the contents of
preandtextareaalone, since spaces matter there.
Finding mistakes by formatting
Formatting is also a debugging aid. Run a broken page through the formatter and a missing closing tag shows up as everything after it drifting to the right. A list item that's indented more than its neighbors points straight at the problem.
Where each job fits in a project
| Job | When | Tool |
|---|---|---|
| Escape user text | Whenever text from a person is shown on a page | Your template engine, checked with the HTML Entity Encoder |
| Format | When you open code someone else wrote | HTML Formatter |
| Minify | Just before publishing | CSS Minifier, JS Minifier |
Related reading: the same readability habits apply to queries, covered in how to format SQL so anyone can read it.