HTML and CSS Guide
Authoring HTML and CSS for Aperture UI. How a document loads, where the engine differs from a browser, selectors, the cascade, the properties it skips, and what a change costs.
Authoring HTML and CSS for Aperture UI is, in most cases, the same as authoring for a modern web browser. The engine parses HTML5 with Gumbo, runs a CSS cascade, lays boxes out and paints them into a command list. This guide focuses on the conventions that work well at game frame rates and on the places where the engine differs from a browser. It does not list every supported element or property. Web platform support does, and it is generated from the tests, so it cannot drift from the engine the way a hand-written list does.
Writing HTML
A document is an ordinary HTML file. The host loads it with loadHtmlFromFile (or loadHtmlFromString) and the engine fetches everything it links through IAPCFileSystem.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="game-ui.css">
</head>
<body>
<main id="hud"></main>
<script src="hud.js"></script>
</body>
</html>Paths in href, src, @import and url() resolve against the document. A path that leaves the UI resources root and the document's own folder is blocked unless the host trusts it. See File system.
The standard structural and interactive elements are available: <div>, <span>, <p>, headings, lists, <a>, <button>, <input>, <select>, <textarea>, <img>, <canvas>, <svg>, and the semantic landmarks (<header>, <nav>, <main>, <aside>, <footer>).
Elements and features that are absent or different:
<form>never goes anywhere. Asubmitevent fires when a submit button is clicked, andrequestSubmit()runs your listeners. The engine has no navigation, so nothing is sent. Handle the event in JavaScript. A call toform.submit()does nothing.<audio>has no playback. It creates an element in the DOM, but nothing plays it. Use your game's audio engine. In a build with the video stack, the sound of a<video>goes to yourIAPCAudioOutput(see Video).<iframe>has document security rules. Child documents use independent views and script queues. Sandbox permissions and origin checks restrictcontentDocumentandcontentWindowaccess; a child does not inherit a native-binder grant. See Document security.<video>needs a full engine build. The standard SDK download leaves it out. See Video.- Raster images are PNG, JPEG, BMP and GIF. A GIF shows its first frame. WebP and AVIF are not decoded, so convert them before you ship. SVG and Lottie JSON have their own paths: see Canvas and SVG and Lottie.
- Images from files decode on a worker. Until the decode finishes, the image reports no size and layout treats it as still loading, not broken. Give every
<img>awidthandheight, or a CSS size, so the page does not shift when the pixels arrive. Adata:URI decodes immediately. - Text is shaped by the engine's own font stack. Glyph shapes and metrics can differ a little from Chrome's even on a page that passes. See Fonts.
See Web platform support for the authoritative element table.
CSS Architecture for Game UI
A few practical patterns:
- One stylesheet per screen. Easier to scope, easier to load on demand.
- Custom properties for theming.
--color-primary,--font-display,--spacing-unit: change one value, rethemed everywhere. - End selectors in a class or an id. The engine indexes every rule by the rightmost part of its selector. A rule that ends in an id, a class or a tag is looked up directly. A rule that ends in anything else, such as
*, an attribute selector like[hidden], or a bare:hover, is tested against every element. A reset such as* { margin: 0 }is fine once. A universal or attribute selector in a hover style is not. - Keep selectors short. A descendant selector is first checked against a small filter of its ancestors' tags, ids and classes, so one that cannot match is usually rejected without walking up the tree. A short selector is still easier to debug.
:root {
--color-bg: #0c0c1f;
--color-fg: #f3f3ff;
--color-accent: #5b8cff;
--space-1: 4px;
--space-2: 8px;
--space-3: 16px;
--font-display: 'GameDisplay', sans-serif;
}
.panel {
background: var(--color-bg);
color: var(--color-fg);
padding: var(--space-3);
border-radius: var(--space-2);
font-family: var(--font-display);
}Custom properties, var(), calc(), clamp(), media queries (including range syntax), @supports, @container, @layer, @import, @font-face, @keyframes and @starting-style all exist in the engine. The corpus pages for custom properties, @layer, !important inside layers, media queries and escaped class names (the forms Tailwind emits) all pass. Check the support table before you rely on a rarer feature.
Supported CSS Selectors
| Selector class | Examples |
|---|---|
| Element / class / ID | div, .panel, #main-menu |
| Universal | * |
| Attribute | [disabled], [type="text"], [href^="#"], [href$=".pdf"], [class*="btn-"], [class~="active"], [lang|="en"] |
| Pseudo-class (state) | :hover, :focus, :active, :disabled, :enabled, :checked |
| Pseudo-class (structural) | :first-child, :last-child, :only-child, :nth-child(n), :nth-last-child(n), :nth-of-type(n), :first-of-type, :empty, :root |
| Pseudo-class (logical) | :not(), :is(), :where(), :has() |
| Pseudo-element | ::before, ::after, ::first-line, ::first-letter, ::selection, ::marker |
| Combinator | descendant , child >, adjacent +, sibling ~ |
| Selector list | h1, h2, h3 |
The list is not exhaustive. Form-state pseudo-classes such as :required, :invalid and :placeholder-shown exist too.
Two selector forms have a cost that reaches beyond their element. When any rule in any stylesheet, including a rule inside @media, @supports, @container or @layer, uses a sibling combinator (+ or ~) or :has(), a class or attribute change on one element can change which rules match elsewhere. The engine then restyles the whole document after such a change instead of only that element's subtree. Prefer a class that your script toggles on the element itself. See Rendering performance.
The Cascade
Resolution order (highest priority last):
- User-agent default styles
- Author stylesheets, ordered by
@layer, then specificity, then source order - Author inline styles (
style="...") !importantdeclarations, ranked in the same order, so an inline!importantbeats an author!important
Inheritance applies to the properties CSS defines as inherited, such as color, the font properties, line-height, text-align, visibility and cursor.
Properties the Engine Reads and Skips
These properties are recognized but have no effect in this version. Each one is logged as a warning when a stylesheet uses it, so the skip is never silent:
text-rendering, font-variant-numeric, font-variant-caps, font-feature-settings, appearance and touch-action.
A vendor-prefixed property the engine does not know is also logged as a warning, and a property it does not recognize at all is logged as an error. To see these messages, forward the engine log to your own log with SetInternalEngineLogging(true) as shown in Your own C++ host. -webkit-line-clamp and the ::-webkit-scrollbar family are real properties and selectors in the engine and are not part of this list.
CSS Layout
Use flexbox for rows and stacks, grid for two-dimensional arrangements, and block flow for documents. The engine has a formatting context for each of these. The last column says whether the test corpus has pages for it, which is what the support table is built from. The corpus records tested behavior. It is not a claim of complete browser conformance.
| Layout | Notes | Test pages |
|---|---|---|
| Block, inline, floats | Normal flow, inline-block, vertical-align, clear | Yes |
| Positioning | relative, absolute and fixed have test pages. sticky is implemented. | Yes |
| Flexbox | Computed with Yoga | Yes |
| Grid | fr, minmax(), auto-placement, spans | Yes |
| Tables | Fixed and auto layout, border-collapse | Yes |
| Multi-column | Has its own formatting context | No test page covers it |
CSS Animations and Transitions
Briefly: both work, and they share one animation clock with the Web Animations API. See Animations for the full reference.
Performance: What Triggers What
What a change costs depends on what it invalidates. The engine does not compare the old and new style to decide whether layout could have changed. Every element that is restyled is laid out again, together with its ancestors, unless the change takes one of the two paint-only paths: a script's inline-style change confined to paint-only properties, or an animation frame on one.
| Change | Cost |
|---|---|
Inline style from script on opacity, transform, filter, box-shadow, color, background-color or another paint-only property | Restyle and repaint. Layout is skipped. |
A CSS animation or transition frame on opacity, transform or a color | Repaint only |
A CSS animation or transition frame on width, height, margin, padding, top or left | Layout for the affected elements on every frame |
Inline style on any other property, such as display, position or font-size | Restyle, layout and repaint |
| A class or attribute change | Restyle the element's subtree (the whole document if a stylesheet uses +, ~ or :has()), then layout of every restyled element and its ancestors, and repaint |
A :hover or :focus state | Restyle the element, then layout and repaint as above. Its descendants restyle too only if a rule such as .card:hover .title ties them to the state. For :hover, a stylesheet that uses +, ~ or :has() widens this: .a:hover + .b restyles a sibling and :has(:hover) an ancestor, so the engine restyles the subtree of the nearest common ancestor of the old and new hovered elements and marks the ancestors above it for restyle. |
| Adding or removing DOM nodes | Reconcile into the engine's element tree, then layout |
Layout is incremental, so a change in a small subtree stays cheap. For animations that run every frame, prefer transform and opacity. Reach for width or height only when you mean to relayout, and only on small subtrees. The exact paint-only list and the rest of the mechanism are in Rendering performance.
Inline Styles vs. Stylesheets
Both work. Inline styles (style="...") carry the highest author specificity short of !important. For game UI, prefer external stylesheets for everything that is not animated per frame:
- They are easier to swap out for theming
- They are easier to inspect, since DevTools shows one stylesheet instead of scattered attributes
- They are easier for designers to own
Inline style from script is the one exception worth making: writing element.style.transform or opacity every frame is the cheap way to drive a per-frame animation, because the engine skips layout for it.
Dynamic content in 26.08.0.1
Text, language and text-size changes now invalidate measurements used by nested flex and grid layout. Let labels and controls size from their content, and test your longest localized strings and supported text scales. Intrinsic control sizing, input alignment and inline kerning changed; revisit fixed dimensions and offsets added to compensate for older rendering. See the release guide.
CSS and DOM additions in the 26.08 release line
The 26.08 source used for this package also contains the following authoring changes. These are implementation notes, separate from the older corpus pass/fail table.
| Area | Behavior |
|---|---|
| Box alignment | Shared parsing and canonicalization for align-*, justify-* and place-*, including positional and overflow alignment values |
| Display | Two-keyword forms such as display: inline grid and display: block flex |
| Absolute positioning | Self-alignment, grid-area containing blocks and inline static-position handling |
| Grid lanes | display: grid-lanes lane placement, spans, dense packing and stacking-axis alignment; this is evolving CSS syntax, so check interoperability before using it in shared browser content |
| Margins and gaps | margin-trim and corrected gap handling |
| Generated content | ::before and ::after use the regular text paint path; selectors combining two pseudo-elements are rejected |
| First letter | A real inline or floated ::first-letter box, including Unicode punctuation selection and dynamic updates |
| Text transformation | Unicode upper/lower/capitalize with language tailoring; Georgian Mkhedruli is not uppercased |
| Tables | Cells reflow to their column width, percentage and border-box column sizing, and min-content minimums |
| Legacy clipping | clip: rect(...) on absolutely positioned elements |
| DOM | Element.scroll(), scrollTo() and scrollBy(); named Window access resolves elements by ID |
Use explicit element lookup in application code even when named Window access is available, to avoid collisions with browser globals. Test layout-sensitive features with the actual SDK and renderer, particularly when combining table sizing, generated content and localization.