JSFiddle - React, Tailwind, and code Playground

HTML

<div id="my-div"></div>

CSS

#my-div {
    background-color: orange;
    width: 200px;
    height: 100px;
    position: absolute;
}

JavaScript

var myElement = document.getElementById('my-div');

function centerDiv() {
    var pageWidth = window.innerWidth,
        pageHeight = window.innerHeight,
        myElementWidth = myElement.offsetWidth,
        myElementHeight = myElement.offsetHeight;
		
    myElement.style.top = (pageHeight / 2) - (myElementHeight / 2) + "px";
    myElement.style.left = (pageWidth / 2) - (myElementWidth / 2) + "px";
}
centerDiv();