The viewport refers to the part of the webpage that is visible in its window, and its dimensions are measured in CSS pixels. Do not confuse this with the physical resolution of the screen!
Here are some examples of viewport widths -
Viewport | Width (in CSS pixels) |
---|---|
Fully maximized browser window on a 27 inch monitor | 2993 |
Browser window occupying 35% of the screen on a 27 inch monitor | 1047 |
Fully maximized browser window on a 14 inch MacBook Pro | 1800 |
Browser window occupying 50% of the screen on a 14 inch MacBook Pro | 900 |
Samsung Galaxy S21's screen | 360 |
Below is the CSS I use to set the width of the central div that holds the content for this website -
max-width: min(max(480px, 50vw), 100vw);
The code above essentially follows 3 conditions:
If 50% of the viewport's width > 480px, then use 50% of the viewport's width
If condition #1 is false and 100% of the viewport's width is < 480px, then set the width to 480px
Finally, below are some plots to drive home the message. Hope this was helpful!