What Happens When You Type a URL and Press Enter
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →Most of your visitors are on phones, and search engines index the mobile version of your site. How to build layouts that adapt gracefully: mobile-first CSS, fluid sizing, breakpoints and testing.
For most websites, the majority of visitors arrive on a phone. Search engines also primarily look at the mobile version of a page when deciding how to rank it. So "responsive" isn't a nice extra; it's the main version of your site.
Here's how to build responsive layouts that hold up on any screen.
Without this, mobile browsers render your page at a desktop width and shrink it down:
<meta name="viewport" content="width=device-width, initial-scale=1">
Most frameworks include it by default. Check anyway.
Mobile-first means writing your base CSS for small screens, then adding styles for larger screens with min-width media queries.
/* Base: phones */
.products { display: grid; gap: 1rem; }
/* Tablets and up */
@media (min-width: 640px) {
.products { grid-template-columns: repeat(2, 1fr); }
}
/* Desktops and up */
@media (min-width: 1024px) {
.products { grid-template-columns: repeat(4, 1fr); }
}
Why this order works better:
Don't design for specific devices. There are thousands of screen sizes. Instead, widen your browser slowly and add a breakpoint where the layout starts to look wrong: lines get too long, cards get too wide, navigation gets cramped.
A few well-chosen breakpoints are better than many. And modern CSS often needs none at all:
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
}
(More Grid and Flexbox patterns.)
Use relative units and let things scale smoothly:
rem for font sizes and spacing, so everything respects the user's font settings.%, fr, vw and vh for proportional layouts.max-width on content, so lines stay readable on wide screens (around 60 to 75 characters is comfortable).clamp() for fluid typography:h1 { font-size: clamp(2rem, 1.2rem + 3vw, 3.5rem); }
That heading scales with the viewport but never goes below 2rem or above 3.5rem.
Media queries respond to the viewport. Container queries respond to the size of a component's container, which is far more useful for reusable components:
.card-wrapper { container-type: inline-size; }
@container (min-width: 400px) {
.card { display: flex; gap: 1rem; }
}
The same card can appear in a narrow sidebar and a wide main column and lay itself out correctly in both. Container queries are supported in all modern browsers.
max-width: 100%; height: auto; on images so they never overflow.srcset and sizes so phones download smaller files. (Image optimisation guide.)width and height attributes (or aspect-ratio) to prevent layout shift.aspect-ratio: 16 / 9.type="email", type="tel", inputmode="numeric") to bring up the correct mobile keyboard.Collapsing a menu behind a button is fine, but:
<button> with an accessible label.* { outline: 1px solid red; } temporarily.Writing base styles for small screens, then using min-width media queries to enhance the layout for larger screens. It keeps CSS simpler and prioritises the most constrained experience.
Use breakpoints where your content needs them rather than for specific devices. Common starting points are around 640px, 768px, 1024px and 1280px, but adjust to your design.
Media queries respond to the viewport size. Container queries respond to the size of an element's container, so reusable components can adapt to wherever they're placed.
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →There are dozens of HTTP status codes, but about fifteen cover nearly everything. What each one means, when to return it, and the mix-ups (401 vs 403, 301 vs 302) that confuse everyone.
Read →A, AAAA, CNAME, MX, TXT and NS records in plain English, why DNS changes seem slow, and the troubleshooting commands that tell you what is really going on.
Read →