Pra mim sem dúvidas essa é a melhor maneira de centralizar uma div
<body>
<div class="content" style="width: 200px; height: 200px; background: red;">
<!-- Conteúdo da div -->
</div>
<script>
function responsiveDiv() {
const container = document.querySelector('body');
const content = document.querySelector('.content');
const maxWidth = 200;
const windowWidth = window.innerWidth;
const margin = (windowWidth - maxWidth) / 2;
container.style.marginLeft = margin + 'px';
container.style.marginRight = margin + 'px';
}
window.addEventListener('resize', responsiveDiv);
responsiveDiv();
</script>
</body>