Skip to content
Tutorials Center
My learning

Topics

Lesson 135 of 139 ยท Projects

Project: Browser Window Mockup

Draw a browser window in pure CSS, with traffic-light buttons, tabs, an address bar and a dark variant, using Flexbox, custom properties and no images or JavaScript.

Tutorial sites, landing pages and portfolios often show a "browser window" around a screenshot or a code demo. Designers usually export it as an image, but you can draw the whole thing in CSS: three colored dots, a row of tabs, a rounded address bar and a soft shadow. It stays sharp at any zoom level, costs no extra download, recolors with a few variables, and the real content inside it can be text, an image or even a live <iframe>.

You will build it in three stages, and every editor contains the complete code so far. Along the way you practice Flexbox, border-radius, box-shadow, text truncation and custom properties.

Plan the parts

Look at any browser and you can split its top into two rows and a body:

  1. Title bar: the traffic-light buttons on the left, and the tabs.
  2. Toolbar: back, forward and reload buttons, and the address bar.
  3. Viewport: the page itself.

All of this chrome is decoration. It carries no information a screen reader user needs, so the title bar and toolbar get aria-hidden="true". Only the viewport is real content. If your mockup shows a screenshot, put the description in the alt text of the image inside the viewport.

Stage 1: the frame and the traffic lights

The frame is a block with a width limit, centered with margin-inline: auto, rounded corners and overflow: hidden. The overflow rule matters: without it, the square corners of the title bar and the viewport poke out of the rounded frame.

The shadow has two layers. The first is a large, soft, tinted shadow that lifts the window off the page. The second, 0 0 0 1px, is a zero-blur "shadow" that works as a hairline border without adding to the box size.

The three dots are empty <span> elements with equal width and height and border-radius: 50%. A flex container with a gap lines them up.

Stage 1: frame, title bar and traffic lights

The lights use red, amber and green, the common convention for close, minimize and zoom. They are just colored dots here; nothing happens when you click them.

Stage 2: tabs and the address bar

Now the title bar holds two things side by side, so the flex container gets align-items: flex-end. The tabs sit on the bottom edge, which is what lets the active tab merge with the toolbar below it. The dots get their own .lights wrapper with bottom padding, so they stay visually centered in the bar even though the row is bottom-aligned.

Three details make the tabs look real:

  • The tab has only its top corners rounded (border-radius: 8px 8px 0 0).
  • The active tab has the same color as the toolbar, so the two read as one continuous surface. Both use a shared variable, --chrome-active, so they can never drift apart.
  • Long titles are cut with an ellipsis. The recipe has three lines: overflow: hidden, text-overflow: ellipsis and white-space: nowrap. Inside a flex row the container also needs min-width: 0, because flex items refuse to shrink below their content size otherwise.

The toolbar is another flex row. The address bar has flex: 1 so it takes all the space the buttons leave over, and it uses the same ellipsis recipe. The padlock is not an image: it is a character added through ::before, and the \FE0E after it asks the browser for the plain-text version of the symbol rather than a colorful emoji.

Stage 2: tabs, toolbar and address bar

Notice how the long tab title ends in an ellipsis instead of breaking the layout. Try making the preview narrower to see the URL shorten too.

Stage 3: variables, a dark variant and polish

Look back at the CSS from stage 2: every color of the chrome comes from three variables on .browser: --chrome, --chrome-active and --line. That was on purpose. A dark window now only needs new values for those variables, plus the few text colors that were hard-coded.

The editor below shows the same markup twice, the second time with the extra class dark. The traffic lights also get a small hover effect: when the pointer is over the group, all three dim slightly.

Stage 3: light and dark windows

Everything else, the shapes, spacing and structure, is shared. This is the main reason to prefer variables over copying a second set of rules.

Using the mockup

Put anything you like in .viewport: a screenshot (an <img> with max-width: 100% and display: block), a code sample, or a small <iframe> for a live demo. If your screenshot should touch the edges, remove the viewport's padding; the frame's overflow: hidden already trims the corners.

To follow the visitor's system theme without a class, set the dark values inside @media (prefers-color-scheme: dark) (see Dark Mode).

Challenges

  1. Add a "+" new-tab button after the tabs: a small circle in the same flex row.
  2. Give the inactive tab a hover background (use :hover and a slightly lighter color).
  3. Add a faint "loading" bar under the toolbar with an animated gradient (see animations).
  4. Make the window fill small screens: below 30rem, remove the border radius and the outer padding.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why does the frame have overflow: hidden?

    Children paint over the parent's rounded corners unless the parent clips them, and overflow hidden does that clipping.
  2. 2. Why is the browser chrome marked aria-hidden="true"?

    aria-hidden removes elements from the accessibility tree without changing how they look. Real content, such as the viewport, stays accessible.
  3. 3. Which three declarations truncate a long tab title with an ellipsis?

    The text must stay on one line, the overflow must be clipped, and the clipped end is then drawn as an ellipsis.
  4. 4. What is the benefit of keeping the chrome colors in custom properties?

    Rules refer to variables, so redefining the variables on one element recolors every part that uses them.
  5. 5. Why might a flex item ignore ellipsis truncation until min-width: 0 is set?

    The default min-width: auto of a flex item prevents shrinking below the content width. Setting min-width: 0 lets it shrink so truncation can happen.

Summary

  • A browser mockup is a frame (rounded, overflow: hidden, layered shadow), a title bar with three dots and tabs, a toolbar with an address bar, and a viewport.
  • Flexbox lays out every row; align-items: flex-end lets the active tab merge with the toolbar below.
  • Ellipsis truncation needs overflow: hidden, text-overflow: ellipsis, white-space: nowrap and, inside flex rows, min-width: 0.
  • Decorative chrome gets aria-hidden="true"; the real content stays accessible.
  • Colors live in custom properties, so a dark variant is only a few new values.

Next: Project: Tribute Page โ€” build a single-page tribute with a hero, timeline and quote block.