An accessibility tree for a Dear ImGui app
Dear ImGui draws its button, checkbox, slider and text field as pixels, so a browser sees one canvas and nothing inside it.
Here every ImGui widget also has a real element inside the canvas: a <button>, an <input type="checkbox">,
an <input type="range">, an <input type="text">. The elements are never drawn.
updateElementGeometry() puts each one at the rectangle ImGui reports for its widget.
Use the app by touch or mouse, or press Tab and use Space, Enter and the arrow keys. Tap the text field to type.
Turn on the outlines to see where the browser believes each element is.
Starting the ImGui app (0.4 MB of WebAssembly)…
The app hasn't started.
Show the code one DOM node per ImGui widget
- The canvas starts empty.
layoutsubtreegives its children layout boxes. The app adds the children. - C++: the app. Each widget is an ImGui call inside a wrapper:
AButton()isImGui::Button()followed byA11y("button", label). - C++: the report.
A11y()reads the id and rectangle of the item ImGui has just submitted and the window's clip rectangle. The wrappers apply changes that came from the DOM before they call ImGui. - JavaScript inside the C++ file: one node per widget. Create it if it's new, keep DOM order equal to ImGui order, write the name and state, then place it.
- After the last widget. Remove the nodes of widgets that weren't submitted and clear Chromium's hit-test cache.
- Events. A node's
click,inputandfocusgo to ImGui. Pointer events go to ImGui from the canvas, except a press on the text field. - C++: what the page calls.
- C++: the text field. The node holds the text while it has focus. ImGui draws the buffer and the node's caret, or the node's own image.
- The focused node as a texture. Used only when the second checkbox is on.
- C++: the frame function. It draws only when something asked for frames.
- The outlines.
getBoundingClientRect()of each node, drawn as a div over the canvas. - Start the module.
- CSS for the nodes.
- All of main.cpp.
How it works
- ImGui to DOM. The app calls
A11y(role, label, state)after each widget. It reads the rectangle and id of the last item from ImGui (g.LastItemData) and the clip rectangle of the window, and calls the page. The page keeps one element per ImGui id, writeschecked,value,aria-valuetext,aria-expandedor the status text when they changed, sets the element's CSS size to the widget's size, and callsupdateElementGeometry(el, { canvasTransform, canvasClip })when the rectangle changed. - DOM to ImGui. A
clickwhosepointerTypeis empty (Enter, Space,click(), assistive technology) presses the ImGui button through ImGui's keyboard activation ids, or sets the checkbox. Aninputevent on the range node sets the slider. Aninputevent on the text node copies its value into theInputTextbuffer. Afocusevent makes the widget ImGui's focused item, and ImGui draws its focus ring when the node matches:focus-visible. - Pointer. A press lands on a node, because the browser hit tests the nodes. A capture listener on the canvas sends every pointer event to ImGui, so ImGui handles the press, the drag and the hover itself. The
clickthat follows on the node has apointerTypeand is ignored. The text field is the exception: its press isn't sent to ImGui, so the browser focuses the node, raises the keyboard and places the caret. - Tab order. The nodes are in the canvas in the order ImGui submitted the widgets, so the browser's Tab order is ImGui's layout order. The page sends ImGui no keys at all.
- Nothing is drawn from the DOM unless the second checkbox is on. Then the text node is uploaded with
texElementSubImage2D()while it has focus and ImGui draws it as an image in the text field's frame.
Live checks
The checks load a second copy of the app in a small frame, so they do not touch or focus the one above.
| Result | Experiment | Detail |
|---|
Findings
- Yes: an undrawn element in the canvas gives an ImGui widget a role, a name, a state and a box. Measured in headless Chromium 157 on 2026-11-21. The accessibility tree read through the DevTools protocol has a group with a textbox "Title", a checkbox "Autosave" (checked), a slider "Volume" (value, minimum 0, maximum 100), a button "Save", a status node and a button "Advanced" (expanded false), in that order.
getBoundingClientRect()of all 14 nodes equals the rectangle ImGui reported, with a difference of 0 CSS px. - The element doesn't have to be drawn. No call draws a node and no texture is uploaded.
updateElementGeometry()works on an element that is only laid out. The node's CSS width and height set the size of the box, andcanvasTransformsets its place. - Hit testing follows.
elementFromPoint()at each visible widget returns its node. A press therefore lands on the node, and the page forwards it to ImGui from a capture listener on the canvas. canvasClipcuts the hit box but not the reported box. With the ImGui window's clip rectangle ascanvasClip, the part of a row that is scrolled under the title bar isn't hit.getBoundingClientRect()still returns the whole row, and returns positions outside the canvas for rows that are scrolled out. The outlines on this page show that.- A scrolled-out widget keeps its node. ImGui still submits it, so it still has a rectangle. Tab reaches it, and the
focusevent makes ImGui scroll it into view withScrollToItem(). A widget that ImGui stops submitting (inside a closed header) loses its node on that frame. If that node had focus, focus goes to<body>. - Tab order is DOM order. Tab from the page heading went through Title, Autosave, Volume, Save, Advanced and the eight checkboxes in ImGui's order, then on to the controls under the canvas. Space toggled the checkbox, the arrow keys moved the slider and Enter pressed Save. ImGui received no key events.
- ImGui accepts a press from outside through its keyboard activation ids. Setting
NavActivateId,NavActivateDownIdandNavActivatePressedIdto the widget's id before the widget is submitted makesImGui::Button()return true andCollapsingHeader()toggle. These are fields fromimgui_internal.h. The checkbox, slider and text field are set by writing to the variable the widget draws. - ImGui draws the focus ring. A
focusevent callsSetFocusID()for the widget and setsNavCursorVisibleto what:focus-visiblesays for the node. ImGui only keeps the ring whenImGuiConfigFlags_NavEnableKeyboardis set. - The text field works on the DOM node's input. ImGui's own
InputText()takes characters only from key events, which is why it raised no phone keyboard on the earlier page. Here the node has focus and takes the typing, and its value is copied into the ImGui buffer on everyinputevent. ImGui draws the text, and a caret and selection at the node'sselectionStartandselectionEnd. - A click in the text needs the two fonts to agree. The browser places the caret with the node's own text layout. ImGui's font drew "Quarterly report" 128 px wide and the node's monospace font laid it out 144.5 px wide, so a click landed on the wrong letter. The page sets
letter-spacingon the node so that the widths match. With two fixed-pitch fonts a mouse drag from x 40 to x 120 then selected letters 3 to 13, which is where ImGui drew them. With a proportional font this would be approximate. - Drawing the focused node is the alternative. With the second checkbox on, the text node is uploaded with
texElementSubImage2D()while it has focus and ImGui draws that image in the frame, so the caret, the selection and the letters are the browser's. The live check counted 0 uploads before focus, 2 while focused and 0 after blur. - Fallback content isn't enough. The same elements as plain children of a canvas without
layoutsubtreeare in the accessibility tree with the same roles and names and take focus, and Space, Enter and the arrow keys work on them. But every box is 0 by 0 at 0, 0,getClientRects()is empty,elementFromPoint()returns the canvas, and typing into the focused text input changed nothing. Measured in Chromium 157 with the API turned off. - Frames only on demand. 0 ImGui frames and 0 geometry calls during 30 idle animation frames. Geometry is sent only for a node whose rectangle changed.
- Not verified with a screen reader. TalkBack, VoiceOver, NVDA and JAWS weren't run. The bounds a screen reader receives weren't read directly: the DevTools protocol gives the accessibility tree without bounds, and the boxes above come from the DOM. Whether a screen reader's activate gesture arrives as a
clickwith an emptypointerType, and whether touch exploration finds the nodes, needs a phone.
This page follows DOM elements in a Dear ImGui app, which shows real elements as ImGui images. Here the direction is reversed: ImGui's own widgets get elements. Source: native/toolkit-aria. Dear ImGui is MIT licensed.