Pikkola Markup, tool No. 76

Readable, then small.

A page that a person can read and a page that a phone can download are the same page with different white space. This one reads HTML and CSS twice: once to lay them out, once to take out every byte a browser does not need. The checks underneath are the mistakes a browser hides until a screen reader or a validator finds them.

2
languages
12
checks
0
uploads

The studio

One document, two shapes

Format when a person has to read it, minify when a phone has to download it. The issues are read from the same tokens, so a line number in a finding is the line in front of you.

What you are pasting
Start from a sample
The document

It reads what you paste and nothing else. A whole page, a fragment, a stylesheet or one rule: the reader takes whatever it is given and leaves what it cannot parse as it found it.

Options
What changed
Bytes in
0
Bytes out
0
Saved
0
gzip in
-
gzip out
-
Tags
0

Bytes are UTF-8, which is what the file costs. The gzip figure appears when the browser can compress in the tab, and it is closer to what a server sends.

formatted

          

The same text, read once

A formatter and a minifier that disagree about a document are two bugs. This page reads the tokens once and both writers use the same list, so a tag the formatter saw is a tag the minifier saw.

01

Read, not guess

The reader walks the text and produces tags, attributes, text and comments, respecting quotes and the raw content of pre, textarea, script and style. A tag it does not recognise is a tag, not an error: it is treated as a block, and the text around it keeps its shape.

02

Write it for a person

A block element starts a line and its children sit one level in; an inline element stays in the sentence it belongs to. Attributes go on their own lines when the tag would run past the wrap column. The CSS is written one selector and one declaration per line, with at-rules and nested blocks indented.

03

Take out what a browser skips

Comments, white space between tags, white space inside a declaration, the last semicolon of a rule. Quoting stays, raw content stays, JavaScript stays. The byte count before and after is the honest number, and the gzip count is the one a phone pays.

What changes, and what is left alone

A minifier is a program that removes things. The list of things it will not remove is the list that makes it safe.

Part of the document Formatter Minifier
<pre>, <textarea>Copied byte for byteUntouched, because every space is content
<script>Copied, only the block's own indent changesUntouched: JavaScript needs a parser, not a regex
<style>, style=""Formatted as CSSMinified as CSS, unless you turn that off
CommentsKept, unless you untick the boxRemoved, except a conditional comment and one starting with an exclamation mark
Attribute quotingKept as writtenKept, because removing it needs a rule for every character
White space between tagsOne newline and an indentRemoved
Line breaks in textCollapsed to one spaceCollapsed to one space
CSS colours and unitsLeft as writtenLeft as written: #ffffff is not shortened to #fff for you

Two things it deliberately does not do: it does not validate the document against the specification, and it does not rewrite, rename or reorder anything you wrote.

Field guide

Minifying a page without breaking it

Most minifier bugs are not subtle. A space removed where a space was content, a comment that was not a comment, a closing tag that moved. This is the order worth checking them in, and the places where a page is more fragile than it looks.

White space is content in four places

A browser collapses every run of white space in ordinary text, which is why a minifier may do the same. The exception is the elements whose rendering rule is white-space: pre: pre, textarea and, by default, script and style. Inside those, one space is one space, and a newline is a newline. Everything else about minifiers follows from that rule, including why this one copies those four blocks rather than re-indenting them.

The other fragile space is between inline elements

<span>one</span> <span>two</span> shows a gap; remove the space and it reads onetwo. The same is true for links, emphasis and anything else with display: inline. A minifier that removes every white-space run between tags is a minifier that has broken a sentence somewhere. This one keeps one space whenever text is on either side of the run, and drops it only between two tags.

MarkupWhat a browser showsSafe to remove the space?
a</span> <span>ba bNo
<div> <div>nothingYes
<pre> a </pre>a, with a leading spaceNo
<li> a </li>aYes, at the edges

Comments that are not comments

A conditional comment, <!--[if lt IE 9]>, is read as markup by old Internet Explorer and as a comment by everything else. Removing it can change what an old browser renders, which is a support decision rather than a size one. A comment that starts with an exclamation mark, <!--! license -->, is a licence notice by convention, and a tool that strips licences quietly is a tool that gets someone into trouble. Both are kept.

What a formatter changes, and what it must not

Indentation and line breaks are white space, so a formatter can invent them freely, with the same four exceptions. What it must not do is reorder attributes, rewrite a tag name to lower case, or close a tag the author left open. The first two change how a document reads in review; the third changes the document. The formatter here writes tags as they were written, and the checks report an unclosed tag instead of quietly fixing it.

Reading the numbers

The byte count is the honest one: UTF-8 bytes, the same number the server sends before compression. A well-structured HTML page often loses fifteen to thirty percent to minification, and a page of mostly text loses less, because the text is the content. The gzip figure matters more than the raw one for anything over a few kilobytes: compression already removes the repeated white space and tag names, so minifying a gzipped page saves less than the raw percentage suggests. Both are shown for the input and for the output, so the second comparison is the one to make.

What this page will not catch

A validator knows the content model of every element: which children a ul may have, which attributes belong on an img, whether a meta belongs in the body. This page checks a handful of those rules, the ones that break a page or an accessibility audit most often, and says so. For a full pass, the W3C validator is still the tool, and a browser's accessibility tree is still the test that matters.

For the CSS side in more depth, Pikkola CSS generates shadows and glass panels with the same rules. For a document whose size is the problem, Pikkola SVG does the same job for a vector file.

Questions

Is my HTML or CSS uploaded?

No. The reader and the writer are functions in a JavaScript file on this domain, and the page's Content-Security-Policy allows no connection except the cookieless page-view counter. The text stays in the tab and keeps working with the network off after the first load.

Does the formatter change what the page looks like?

It should not. It adds and removes white space between elements, which a browser ignores, and it copies the contents of pre, textarea, script and style byte for byte, because there a space is content. A tag it does not recognise is treated as a block, which changes the layout of the text file, not of the page.

Why does the minifier keep some comments?

Two kinds. A conditional comment is read as markup by old Internet Explorer, so removing it can change what an old browser renders. A comment starting with an exclamation mark is the convention for a licence, and stripping a licence is not this page's decision to make.

Does it minify JavaScript?

No, and it says so. Minifying JavaScript safely needs a parser rather than a regular expression, and the shortcuts are how broken scripts ship. The contents of a script tag are copied as written. CSS is minified, because its grammar is small enough to handle exactly.

What does the byte count include?

UTF-8 bytes, which is what the file costs, and the difference between the input and the output. When the browser offers CompressionStream, the page also shows the gzip size of both, which is closer to what a server sends.

Can I trust the checks?

Use them as a careful reader's list, not as a validator. They catch unclosed tags, mismatched end tags, duplicate attributes and ids, images without alt text, a block inside a paragraph and a few more. A full validation needs the specification's own rules, and a browser is more forgiving than the standard.