# SuperHTML HTML Validator, Formatter, LSP, and Templating Language Library ## SuperHTML CLI Tool The SuperHTML CLI Tool offers **validation** and **autoformatting** features for HTML files. The tool can be used either directly (for example by running it on save), or through a LSP client implementation. ``` $ superhtml Usage: superhtml COMMAND [OPTIONS] Commands: check Check documents for errors. fmt Format documents. lsp Start the Language Server. help Show this menu and exit. version Print the version and exit. General Options: --help, -h Print command specific usage. --syntax-only Disable HTML element and attribute validation. ``` > [!WARNING] SuperHTML only supports HTML5 (the WHATWG living spec) > regardless of what you put in your doctype (a warning will be generated > for unsupported doctypes). > [!WARNING] Templated HTML (Jinja2, Angular, Mustache, ...) is not yet > supported when all validation rules are enabled, use `--syntax-only` (or > the relative Extension Setting in VSCode) to limit validation to syntax > errors to use SuperHTML with templated HTML documents. > > Compatibility with popular templating languages is being explored. ### Diagnostics SuperHTML validates not only syntax but also element nesting and attribute values. No other language server implements the full HTML spec in its validation code.  ### Autoformatting The autoformatter has two main ways of interacting with it in order to request for horizontal / vertical alignment. 1. Adding / removing whitespace between the **start tag** of an element and its content. 2. Adding / removing whitespace between the **last attribute** of a start tag and the closing `>`. > [!TIP] Consider using `superhtml fmt --check` in your CI to enforce every > change to be performed on normalized HTML files. This is a technique > commonly used in Zig (and Go) for source code that can also help > streamline frontend development. #### Example of rule #1 Before: ```html
Foo
Foo
Foo
Foo
` are siblings, while in reality browsers are required **by the spec** to ignore the self-closing slash in `
`, making `` a child, not a sibling of it. Add to that the fact that tooling like the default HTML formatter in VSCode will provide misleading autoformatting (try it yourself, disable SuperHTML in VSCode and autoformat the snippet above), to this day people are way more confused about HTML than they need to be. Related: [#100](https://github.com/kristoff-it/superhtml/pull/100). ### Why doesn't SuperHTML report duplicate values in `[class]` as an error? The HTML spec defines the global `class` attribute as a space-separated list of tokens, as opposed to a space-separated list of _unique_ tokens, like some other attributes are (e.g. `accesskey`). ### Why is `