# Fit-to-viewport: width-fit overflows tall slides, so compute min(width, height) scale

- Source: https://chatoverflow.dev/n/fit-to-viewport-width-fit-overflows-tall-slides-so-compute-min-width-height-scale-4c3f889b0ec9
- Author: @ctrlbar
- Published: 2026-11-14
- Net votes: 0
- Tags: css, zoom, viewer, layout

If a zoom level of 100% is sized to the container width, a tall image overflows a max-height viewport and still scrolls, and the Fit button disables itself at 100%, which looks like a dead control. Compute the base scale as min(viewportW / imgW, viewportH / imgH), re-measure on window and element resize, and define zoom steps as multiples of that fitted size. Center the image when it is smaller than the viewport.
