Examples

CSS owns layout. React Viewport exposes geometry to logic.

Rendering budget

A search overlay or lightweight virtualizer can use the visible height to choose how many optional items React creates. CSS can size a container; JavaScript chooses which items exist. A single consumer could use VisualViewport directly; multiple React consumers can share this store.

Measuring viewport…

Example policy: reserve 320px for search controls, allow 48px per row, cap at 8. This is a viewport-derived budget, not a measurement of this card.

ResultBudget.tsx · actual source

Coordinate visibility and scroll correction

A canvas annotation or editor selection is application data. Compare it with the visible document bounds. The optional scroll algorithm re-evaluates after keyboard or viewport changes. Coordinate system assumptions →

Target visible? Place a target

A selected 20 × 20 document-coordinate target. Place it near the visible bottom, then open the keyboard, scroll or zoom. Its document coordinates stay fixed.

Keep the target selected while the actual keyboard changes the viewport. This field is not stored or sent.

Keyboard-aware scroll correction

The application recalculates a vertical scroll correction when viewport geometry changes. CSS cannot call a selection algorithm. Try the default observation first; opt in only to test correction.

Suggested vertical correction: Pending

Correction runs after selection, viewport-size, scale or keyboard-state changes, not ordinary scrolling. Opt-in page scrolling can be clamped at document boundaries. It does not manage focus, defeat native browser panning, or guarantee visibility inside nested scrollers.

CoordinateVisibility.tsx · actual source
geometry-logic.ts · actual source

Zoom-aware tools and safe-area data

A custom rendering engine needs numerical inputs for hit testing and protected drawing regions. Ordinary CSS padding and responsive styling need no library.

Optional annotation hit tolerance: Pending

A canvas tool can convert a 12 CSS-pixel tolerance at unit scale using 12 / visual.scale. This is an algorithm input, not a smaller button or text size.

Pinch zoom is user viewport geometry, not responsive design. Essential controls remain available at every scale.

Safe-area input for a custom drawing surface: Pending.

Use these raw protected-edge values only after mapping the drawing surface into the same coordinate system. For ordinary padding, use env() directly.

ZoomLogic.tsx · actual source

CSS integration

Use useViewportCssVariables() when JS logic and CSS need the same normalized geometry. Measure once in the shared store, then let styles consume the result. Copying env() into JS and back to CSS adds little value for CSS-only padding.

Install the shared CSS bridge

Secondary recipe: bottom constraints

If an application already needs measured geometry, an overlap-aware bottom constraint can consume it. This is an educational recipe, not a universal keyboard-layout fix; visual offsets and browser timing can require a different application policy.

CSS geometry composition

When you don’t need React Viewport

CSS-only composer

Use normal grid or flex layout, 100dvh and safe-area padding. Request interactive-widget=resizes-content where supported. If browser-native layout meets your requirements, stop here.

Open CSS Baseline →

CSS-only modal footer

Let the form body scroll while its action row remains in normal grid flow. A modal implementation must separately own focus and accessibility.

Modal body and action row
Safe-area padding

Try actual browser changes

Live Geometry Lab → Observe the input data, rendering budget and coordinate test on your device. No simulated keyboard.