Skip to content

The Grammar

Every WebSketch capture is a tree of nodes annotated with a fixed grammar. This page documents the roles, symbols, classification logic, and cleanup passes that produce the final output.

WebSketch maps every visible element to one of 22 UI primitives. The vocabulary is fixed — the same roles appear on every website, so LLMs learn them once and apply them everywhere.

RoleDescription
PAGEThe root node of every capture.
HEADERTop-level banner, typically containing navigation and branding.
FOOTERBottom-level site information, links, and legal text.
SECTIONA thematic grouping of content.
NAVA navigation region containing links.
RoleDescription
TEXTHeadings, paragraphs, and other text content.
IMAGEPhotos, illustrations, and decorative images with meaningful alt text.
ICONSmall symbolic images (logos, favicons, UI icons).
CARDA self-contained content unit, typically with an image, title, and description.
LISTAn ordered or unordered group of similar items.
TABLETabular data with rows and columns.
RoleDescription
BUTTONA clickable control that triggers an action.
LINKA clickable reference that navigates to another page or anchor.
INPUTA text field, textarea, or other typeable control.
CHECKBOXA toggleable on/off control.
RADIOA single-select option within a group.
FORMA container grouping related inputs and controls.
RoleDescription
MODALA dialog or lightbox that overlays the page.
TOASTA transient notification message.
DROPDOWNA collapsible menu or select popover.
RoleDescription
PAGINATIONPage navigation controls (next, previous, page numbers).
RoleDescription
UNKNOWNElements that could not be classified into any other role.

Each line in the tree carries dense, machine-parseable annotations:

├─ *BUTTON <search> {sticky} "Find products"
│ │ │ │ │
│ │ │ │ └─ Visible text
│ │ │ └─ Layout flags
│ │ └─ Semantic hint
│ └─ Interactive (*)
└─ Indentation = parent-child hierarchy
SymbolMeaningExample
* prefixThe element is interactive — a user can click, type, or toggle it.*LINK, *BUTTON, *INPUT
<semantic>An HTML5 or ARIA semantic hint is preserved.<h1>, <main>, <search>, <aside>
{flags}Layout behavior flags.{sticky}, {scrollable}
"label"The visible text content of the element."Sign up free", "Search..."
(N items)The number of items in a list.LIST (12 items)
IndentationNesting depth shows the parent-child hierarchy.HEADER > NAV > LIST > LINK

WebSketch does not just dump the DOM. Every visible element passes through a 5-tier classification pipeline:

TierSourceExample
1. ARIA roleExplicit role="navigation" attributes.NAV
2. HTML tagSemantic HTML elements like <button>, <h1>, <nav>.BUTTON, TEXT <h1>
3. Class heuristicsCSS class name patterns like .card, .modal, .toast.CARD, MODAL, TOAST
4. Structural analysisRepeated sibling patterns (3+ same-role children).LIST
5. FallbackText-only or unclassifiable elements.TEXT, SECTION, UNKNOWN

Higher tiers take priority. If an element has role="navigation", tier 1 wins regardless of its class names or tag.

After classification, WebSketch runs a series of cleanup passes to minimize noise:

  • Transparent table traversal — Intermediate elements like TR, TD, TH, and LI are skipped. Their children are promoted to the surface so the tree reflects content, not markup structure.
  • Zero-content pruning — Empty, non-interactive, and invisible nodes are dropped entirely.
  • Wrapper collapsing — Meaningless single-child SECTION wrappers are removed, pulling the child up one level.
  • Cascading prune — Hollow wrapper chains (nested containers with no actual content) are eliminated entirely.
  • Label extraction — Visible text is pulled from links, buttons, headings, images (alt text), and inputs (placeholder or value) and placed in the "label" annotation.

The result is the minimum set of nodes needed to understand the page.


Back to landing page