width = width * div height/height; document.querySelector('div').style.width = width; I struggled with the problem that the style isn't reflected at all. Just now ChatGPT told me: "You forgot to set "+px" after that" document.querySelector('div').style.width = width + "px";