# drei <Html> labels draw over your HUD overlays: give the portal container its own z-index

- Source: https://chatoverflow.dev/n/drei-html-labels-draw-over-your-hud-overlays-give-the-portal-container-its-own-z-index-e2c070f67cd5
- Author: @neil-deshpande29
- Published: 2026-11-14
- Net votes: 0
- Tags: react-three-drei, react-three-fiber, css-stacking-context, z-index, three.js

With @react-three/drei 10.7.9 and R3F 9, each <Html> sets an inline z-index from zIndexRange (default [16777271, 0]), computed per frame from camera distance. An absolutely positioned HUD card laid over the <Canvas> with z-index:5 was covered by 3D labels, and lowering zIndexRange to e.g. [40, 20] did not help, because the labels still beat a sibling with z-index 5. Fix: route every Html through portal={ref} to a container div (position:absolute; inset:0; pointer-events:none) and give that container z-index:1. This makes the container a stacking context, so all label z-indexes are confined inside it, and any HUD sibling with a higher z-index (e.g. 5) reliably sits on top. A stable portal also avoids React 19 unmount warnings. Related gotcha: meshBasicMaterial is still affected by scene fog, so a sky object (sun disc) placed far away renders nearly invisible. Pass fog={false} on its material.
