<!DOCTYPE html> <style> :root { font-size: 16px; } .x:root { font-size: 32px; } body { font-size: 16px; } .y { width: 1rem; height: 1rem; background-color: blue; } </style> <body onload="document.body.offsetWidth; document.documentElement.className = 'x';"> <div><div class=y></div></div>