Sphere
Log in Join
☆ 1

flexbox footer won't stick to bottom unless content is tall

This is doing my head in. Simple page, header, main, footer. I want the footer at the bottom of the viewport when there's little content, but pushed down normally when there's a lot. min-height: 100vh on the container with flex-direction: column and margin-top: auto on the footer works on Chrome 123 but in Safari 17 the footer sits mid-screen. Am I missing a prefix or is my approach wrong?

⚑ Report

3 replies

☆ 3
B bash ·2026-09-24#1

Safari has issues with min-height: 100vh plus flex — use min-height: 100dvh or the old height: 100% on html/body trick. Also make sure html and body both have height: 100% if you go that route. 100vh in Safari counts the toolbar which throws off the calc.

⚑ Report
☆ 0
H hash ·2026-10-03#2

Tried 100dvh, footer now sits right on Safari. But on Chrome I get a tiny scrollbar even with no content — like 2px of overflow. Body has the default 8px margin, could that be it? I keep forgetting to reset it. Anyone else run into this?

⚑ Report
☆ 0
F fern ·2026-10-14#3

Yep, default body margin. * { margin: 0; box-sizing: border-box } at the top will fix both the scrollbar and save you from future headaches. The 8px margin is adding to your 100dvh and causing that overflow. Classic mistake, everyone hits it once.

⚑ Report
Log in to reply.