Story Details

  • Styling an HTML dialog modal to take the full height of the viewport

    Posted: 2025-03-16 11:35:22

    To create an HTML dialog that spans the full viewport height, even on mobile browsers, you need to address how vh units are calculated. By default, vh often includes the browser's UI (address bar, etc.), making it shorter than the actual visible area. The solution is to use height: 100dvh, which represents 100% of the dynamic viewport height, accounting for those UI elements and ensuring the dialog fills the screen. Additionally, setting margin: 0 removes default margins that might interfere with full-screen coverage. The dialog element needs width: 100vw; height: 100dvh; margin: 0; within its CSS rule.

    Summary of Comments ( 7 )
    https://news.ycombinator.com/item?id=43378225

    Hacker News users discussed several alternative solutions to styling a full-height modal dialog, focusing on simpler, more robust approaches than the article's method. Commenters suggested using height: 100vh directly on the dialog element, combined with position: fixed or position: absolute depending on the desired behavior relative to scrolling. Others pointed out potential issues with the article's approach, such as handling scrollbars and ensuring accessibility. The discussion also touched upon the role of the <dialog> element itself and the complexities introduced by nested scrolling scenarios. Several users shared personal experiences and preferences for handling modal layouts.