til

today i learned

View on GitHub

Quickly Find the Element That Is Causing Horizontal Scrolling

const documentWidth = document.documentElement.offsetWidth;

document.querySelectorAll("*").forEach((node) => {
  if (node.offsetWidth > documentWidth) {
    console.log(node);
  }
});

The snippet logs all elements that are wider than the document’s width.

source