sprezzature-ux-laws
🇫🇷 LISEZMOI.md · 🇬🇧 README.md
A static Laws-of-UX auditor for HTML.
The Laws of UX (user experience: how an interface feels to use, such as how long it takes to find the right button) are named heuristics from psychology and human-computer-interaction
research, curated by Jon YABLONSKI at lawsofux.com. Hick's Law,
for instance, says that the more choices a screen offers at once, the longer a person
takes to pick one, so a navigation menu with forty links is measurably harder to use
than one with seven. This tool cannot see a rendered page or watch a real person use it.
It reads the raw HTML text and flags the mistakes that are decidable from that text
alone, such as counting the links in a <nav>. That trade keeps it fast and
deterministic enough to run in a pre-commit hook or a continuous integration (CI) step,
at the cost of catching only the fraction of each law's violations that a text scan can
see. The full, sourced definition of each law lives in
references/laws-of-ux.md.
How it works
Laws covered
Eight laws, in the order the checks run. The slug is the name every surface uses.
| Slug | Law | Severity | What fires it | Fixer |
|---|---|---|---|---|
hick |
Hick's Law | error | A <nav> showing more than 7 top-level <a> or <button> choices on one screen (see below) |
no |
choice-overload |
Choice overload | warning | A <section> or <div> whose classes contain pricing or plans and grid or flex, with more than 4 direct <article> or <div> columns |
no |
miller |
Miller's Law | warning | A visible run of 8 or more letters and digits, with at least one digit (codes, IDs, card numbers) | yes |
jakob |
Jakob's Law | error | A <div> or <span> with onclick, role="button" or cursor-pointer, and no real <button>, <a>, <input>, <select> or <summary> child |
yes |
fitts |
Fitts's Law | warning | An interactive element with no h-, min-h- or size- class of at least 11 (44 px), or full, screen, auto |
yes |
aesthetic-usability |
Aesthetic-usability effect | warning | An interactive element with no focus-visible:ring-* or focus:ring-* class |
yes |
selective-attention |
Selective attention | warning | A <span> coloured text-red-*, text-green-*, text-amber-*, text-yellow-* or text-orange-*, with no status word ("error", "ok", "pending"…) and no <svg> or <img> child |
no |
tesler |
Tesler's Law | warning | An HH:MM time with no timezone token (UTC, GMT, Z, +02:00, Europe/Paris…) within 40 characters |
no |
Interactive elements are <button>, <a>, <input>, <select>, <textarea> and
<summary>. What each check leaves alone:
- Miller reads visible text only: it skips the lines of a
<script>or<style>block, the tags themselves with their attributes (and, on a tag split across lines, the values ofclass,id,hrefandsrc), purely alphabetic words, and names shaped as three or more letters followed by digits only (GMTED2010,LANDSAT8,ISO14001): those are names of standards or datasets, and the fixer would otherwise split them with non-breaking spaces. - Jakob also leaves a styled
<span>or<div>inside a<label>that holds an<input>,<select>or<textarea>: the form control carries the semantics. - Fitts skips
<input type="hidden">, and treats an<a>as a text link rather than a button unless it carriesinline-flex,flex,block,btn,button, or abg-orborder-class. - Tesler skips a time that sits in a duration context: the words
duration,elapsed,remaining,currentTime,runtime,length, adata-ra-attribute, anra-timeclass, a range input,<progress>,<audio>or<video>. A playback position has no timezone.
Fitts and aesthetic-usability read Tailwind's scale, so they first ask whether the
document uses Tailwind CSS (Cascading Style Sheets, the rules that give a web page its colours, fonts and layout) at all: Tailwind-only utilities of at least two different
kinds (spacing, colour, a responsive or state prefix, gap, sizing, rounding), such as
px-4 and bg-blue-600. px-4 and py-2 are one kind. When it does not, each of the two checks returns one
info finding for the whole document instead of one warning per element, and --fix
writes no Tailwind classes into it.
How it counts: choices, not elements
Hick's Law measures the choices a person faces at one moment, so counting the links in a file gets it wrong twice.
A responsive header holds two menus. A row marked hidden sm:inline and a
hamburger marked sm:hidden never appear together: the phone reader sees one
set, the desktop reader sees the other. Adding them up charges the reader for
choices no screen ever shows. The auditor resolves each control's visibility
from its Tailwind display classes, walking ancestors (a container that hides
its subtree wins over a child that would show), and reports the worse of the
phone count and the desktop count, naming which one it is.
A group is one choice. A <details>, a <dialog>, a <menu>, or an element
whose role is radiogroup, tablist, menubar, listbox or combobox
collapses several controls into a single decision. Each one counts once, whatever
it contains. Two <nav> elements on one page are counted apart.
Where the two states are ambiguous the count goes up rather than down: a
control that appears at md and disappears again at lg is treated as
desktop-only. Over-reporting sends somebody to look; under-reporting ships.
Install
pip install sprezzature-ux-laws
One install gives all five surfaces: the library, the command line, the HTTP (HyperText Transfer Protocol, the protocol a browser uses to ask a server for a page, and a program to ask for data)
API (application programming interface, addresses another program calls to use this tool with no person clicking), the MCP
(Model Context Protocol, the protocol through which AI agents call tools in English) server, and the agent skill. It
installs four commands: sprezzature-ux-laws and sprezzature-ux-laws-audit (the auditor),
sprezzature-ux-laws-mcp (the server) and sprezzature-ux-laws-skill (the skill). The
Dockerfile and docker-compose.yml that serve the API in a container live in the
repository, not in the package. The base dependencies are click (the command line), FastAPI, uvicorn,
fastapi-mcp and mcp. There are no feature extras. The only extra, [dev], is the test
toolchain (pytest, ruff, mypy, httpx2).
The auditor itself uses the Python standard library only (html.parser), with no
browser and no network, which keeps it cheap enough for a pre-commit hook.
Command line
# Audit a file or a whole directory tree
sprezzature-ux-laws public/index.html
sprezzature-ux-laws site/ --json
# Restrict to some laws, or skip some
sprezzature-ux-laws page.html --only fitts,jakob
sprezzature-ux-laws page.html --ignore tesler
# Repair the mechanical ones in place, or preview the repair
sprezzature-ux-laws page.html --fix
sprezzature-ux-laws page.html --fix --dry-run
Two installed commands take the same targets and flags and call the same handler:
sprezzature-ux-laws (click) and sprezzature-ux-laws-audit (the per-tool script).
From a clone, without installing the package, python scripts/audit_laws_of_ux.py page.html runs that handler too, provided click can be imported.
| Flag | Effect |
|---|---|
--json |
Print a JSON (JavaScript Object Notation, a text format in which programs store data as named fields, such as "title": "Home") array, one object per finding (law, severity, path, line, message, snippet), instead of the text report. |
--strict |
Any finding fails the run, whatever its severity. |
--only LAWS |
Comma-separated slugs to run. Default: all eight. |
--ignore LAWS |
Comma-separated slugs to skip. |
--fix |
Apply the mechanical fixes in place. |
--dry-run |
Report what --fix would apply, without writing. Implies --fix. |
-V, --version |
Print the version. |
A target is an .html or .htm file, or a directory searched recursively for both
suffixes, in any case. Any other existing file is skipped with a warning. A path that does not
exist is refused by both commands (exit 2).
Exit codes:
0: noerrorfinding (with--strict, no finding at all), or no HTML file found. A--dry-runalways exits0.1: at least oneerrorfinding (with--strict, at least one finding).2: an unknown slug in--onlyor--ignore, a path that does not exist, or another usage error.
Findings are printed in the order the checks run, not in line order.
What --fix changes
Four laws have a fixer. The other four (hick, choice-overload,
selective-attention, tesler) need a design decision, not a text edit.
| Law | Edit |
|---|---|
fitts |
Adds min-h-11 to the element's class attribute. |
aesthetic-usability |
Adds focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-blue. |
miller |
Splits the visible run into groups of four from the right, joined by non-breaking spaces. The same run in a tag (an href, a data- value) is left as it is. |
jakob |
Rewrites the clickable <div> or <span> to <button>, and removes role="button", when it opens and closes on one line and holds no real control. A wrapper around it is left alone. |
The fixer re-audits and repeats, up to five passes, because rewriting a <div> into a
<button> creates new Fitts and focus-ring findings. A second run on a repaired file
applies zero edits. A fixer only extends a class attribute that already exists: an
element without one, or whose class is not on the line its tag opens, is counted as
unfixable and stays among the remaining findings.
--fix writes the page only when a fixer changed something, and keeps its line endings
(a file ending its lines in carriage return + line feed, CRLF, as Windows Notepad writes them, stays CRLF). It rewrites the page, so diff the result before committing it.
From Python
from pathlib import Path
import sprezzature_ux_laws as ux
for finding in ux.audit_html("<nav>" + '<a href="/">x</a>' * 12 + "</nav>"):
print(finding.law, finding.severity, finding.message)
ux.audit_file(Path("public/index.html"), laws={"fitts", "jakob"})
applied, unfixable, remaining = ux.fix_file(Path("page.html"), laws=set(ux.LAWS), dry_run=True)
The package exports audit_html, audit_file, fix_file, Finding, Walker,
Element, LAW_REGISTRY, LAWS, FITTS_FIX_TOKEN and skill_path. ux.LAWS is the
tuple of the eight slugs, in the order the checks run: the command line validates
--only against the same registry, and the HTTP API publishes it. ux.skill_path()
returns the folder of the agent skill the package ships (see below).
HTTP API
uvicorn sprezzature_ux_laws.api:app --host 127.0.0.1 --port 8000
| Method and path | operation_id |
Answer |
|---|---|---|
GET /health |
health |
{"status": "ok"} |
GET /v1/laws |
list_laws |
The eight slugs, each with a one-line note on what it checks. |
POST /v1/audit |
audit_interface |
Body {"html": "...", "laws": [...]}; an empty laws runs all eight. Returns findings (law, severity, line, message) and the errors and warnings counts. |
An unknown slug in laws returns HTTP 400, rather than a clean report for checks that
never ran. Interactive documentation is served at /docs and /redoc. Run this way,
uvicorn serves the routes only: the MCP endpoint is mounted by sprezzature-ux-laws-mcp
(below), which serves the same routes and /mcp together.
Docker
docker compose up -d
curl -s localhost:8000/health
docker compose run --rm api sprezzature-ux-laws-audit --json /work/index.html
The image runs sprezzature-ux-laws-mcp, so one process on port 8000 serves both the
HTTP routes (/health, /v1/...) and the MCP endpoint at /mcp. Compose mounts
./work at /work for the pages to audit.
MCP server
The Model Context Protocol (MCP) lets an agent host call tools directly. The server
wraps the same FastAPI app with fastapi-mcp, so each route's operation_id is the tool
name: health, list_laws, audit_interface.
sprezzature-ux-laws-mcp # 127.0.0.1:8000, MCP endpoint at /mcp
sprezzature-ux-laws-mcp --host 0.0.0.0 --port 9000
--host and --port default to SPREZZATURE_UX_LAWS_HOST and
SPREZZATURE_UX_LAWS_PORT when those are set; a port that is not a number is a usage
error (exit 2). -V prints the version. python -m sprezzature_ux_laws.mcp is
equivalent.
Agent skill
The fifth surface is the skill: the folder an agent such as Claude Code or OpenCode reads
to know when to apply these laws and which command to run. It ships inside the package,
at sprezzature_ux_laws/skill/: a SKILL.md, plus references/laws-of-ux.md (the
thirty laws, with sources) and references/triggers.md (the trigger catalogue). The
agent reads its own copy, not the one pip installed, so a command keeps the two in step.
sprezzature-ux-laws-skill # is the installed copy in step?
sprezzature-ux-laws-skill --install # copy it into ~/.claude/skills
sprezzature-ux-laws-skill --install --agent opencode # into ~/.opencode/skills instead
sprezzature-ux-laws-skill --path # where pip put it
Without --install the command only reports which files differ, and exits 0 either
way (1 only when the build ships no skill). --install first moves an older copy aside,
to skills-superseded/ beside the skills folder: a folder left inside it would itself be
read as a skill. From Python, sprezzature_ux_laws.skill_path() returns the shipped
folder. sprezzature-ux-laws is a single command, not a group, so there is no
sprezzature-ux-laws skill.
The routing rules and the tool table for agents are in
TRIGGERS.md.
The sprezzature hub gathers the
skills of every brick of the suite.
Honest scope
The auditor catches mechanical, source-decidable violations of eight laws out of the thirty on lawsofux.com. It does not judge whether a screen answers the right question or whether a flow makes sense: that stays a human call. Response time (the Doherty threshold) is not a fact about source, and is not checked. It is a fast gate, not a substitute for design review.
License
The three-clause Berkeley Software Distribution license, BSD-3-Clause, a permissive open-source license: anyone may reuse the code, even commercially, if they keep this notice: © Warith Harchaoui. Part of the sprezzature toolkit.
Metadata
Release files for sprezzature-ux-laws 1.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sprezzature_ux_laws-1.5.1.tar.gz | 97.2 kB | Without provenance | Details for sprezzature_ux_laws-1.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sprezzature_ux_laws-1.5.1-py3-none-any.whl | Python 3 | none | any | Details for sprezzature_ux_laws-1.5.1-py3-none-any.whl |
Total release size: 165.1 kB
Release files / sprezzature_ux_laws-1.5.1.tar.gz
| Download URL | sprezzature_ux_laws-1.5.1.tar.gz |
|---|---|
| Size | 97.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50319b4ae8149bdaba2af9cbd5fe34a6ae9c974580d9dbb95fd2a2df0a2d5618
|
|
BLAKE2b-256 checksum How to use checksums |
8796d586e05b3d6de078704b7ce4e0a11dddd4687ec677aef34c52b44026ff00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / sprezzature_ux_laws-1.5.1-py3-none-any.whl
| Download URL | sprezzature_ux_laws-1.5.1-py3-none-any.whl |
|---|---|
| Size | 67.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f014ad6e9097566e15794553af6d644ae17a14c9b474cece0b4e0433570ff09
|
|
BLAKE2b-256 checksum How to use checksums |
c217ea038e8428472289c855700d75bacbd2c7ac81ebe120202c420373421730
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for sprezzature-ux-laws 1.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.