Responsive CSS
Using responsive CSS is a form of SEO that allows for multiplatform screen support.
Screen sizes
The majority of web traffic is on mobile
- Mobile ยท 60%
- Desktop ยท 40%
Devices
- Watch
- Mobile
- Tablet
- Laptop
- Desktop
- TV
Stats Counter โ Screen Resolution Market Share
Screen Size Map
Common Breakpoints
Dev Tools
| Mobile S | 320px |
| Mobile M | 375px |
| Mobile L | 425px |
| Tablet | 768px |
| Laptop | 1024px |
| Laptop L | 1440px |
| 4K | 2560px |
Dev Tools โ Responsive viewport mode
CSS Frameworks
| Tailwind | Bootstrap | Chakra | Primer | MUI | |
|---|---|---|---|---|---|
| Small | 40rem 640px |
576px |
420px |
544px |
600px |
| Medium | 48rem 768px |
768px |
768px |
768px |
900px |
| Large | 64rem 1024px |
1024px |
1024px |
1004px |
1200px |
| XLarge | 80rem 1280px |
1280px |
1280px |
1280px |
1536px |
| 2XLarge | 96rem 1536px |
1536px |
1536px |
โ | โ |
Tailwind โ Breakpoints
Bootstrap โ Breakpoints
Chakra โ Breakpoints
Primer โ Breakpoints
MUI โ Breakpoints
Common Page Widths
Documentation
688px 43rem |
VitePress Zensical Microsoft SharePoint |
720px 45rem |
Notion Starlight |
740px |
VuePress |
760px |
Fumadocs |
768px 48rem |
GitBook Confluence |
816px 8.5in |
Google Drive |
825px |
Material MkDocs Zensical |
832px 52rem |
Nextra |
920px |
Microsoft Loop |
CSS Frameworks
Viewport
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> Scales the page properly on mobile
MDN Web Docs โ Meta viewport
CSS Layout
Reset default style
body {}Setting
width: 100vw;on<body>causes a horizontal scrollbar defect
Content
</main>}Use
section > div.wrapperto allow different background colors for individual sections
Header
<!-- logo --> </a> <!-- pages --> </ul> </nav> <!-- mobile menu --> <label class="menu"> </label></header>header {Tweaked <main> โ 4 collapsed lines
nav { โ<nav> Layout on Desktop
}
.logo { }
.mobile { }
}
@media (max-width: calc(175px + 4em)) { Navbar layout on mobile
- Size of
<nav> ยท 175px + Size of total spacing 4em
@media does not support var()
header {
nav { } }
header:has(input[name='menu']:not(:checked)) { โThe <nav> is displayed only when the menu is open on mobile
nav { } }}Footer
Brand โ 19 collapsed lines
<!-- brand --> <!-- logo --> </a> </h2> <!-- headline --> <!-- social media --> </ul> </nav> </hgroup> <!-- pages --> </ul> </hgroup> </ul> </hgroup> </nav> </section>Additional sections โ 15 collapsed lines
<!-- copyright --> <!-- legal documents --> </ul> </nav> </section> <!-- credit --> </section> </footer>footer {Tweaked <main> โ 4 collapsed lines
section#footer {
Brand โ 9 collapsed lines
nav { โ Row layout
}
hgroup { Column layout
} }
Additional sections โ 8 collapsed lines
}Aside
</main> /* [ 1fr ][ min/max ][ 1fr ] [ left ][ content ][ right ] [ full ] */ [full-start left-start] 1fr [content-start left-end] minmax(auto, calc(720px + 1em * 2)) โSet the page width
- The Horizontal spacing should be defined in either
calc() or gap
minmax(auto, 720px) is equivalent to max-width: 720px
[content-end right-start] 1fr [full-end right-end];}
main, header, footer {Tweaked <main> โ 5 collapsed lines
/* margin-inline: auto; */}
/* left <aside> */aside:has(+ main) {}
/* right <aside> */main + aside {}
aside {}
@media (max-width: calc(720px + 150px + 150px)) { Remove <aside> on smaller screens ยท this one is removed first
- Size of
<main> ยท 720px + Size of both <aside> 150px + 150px
@media does not support var()
aside#table-of-contents { }}
@media (max-width: calc(720px + 150px)) { Remove <aside> on smaller screens ยท this one is removed last
- Size of
<main> ยท 720px + Size of this <aside> 150px
@media does not support var()
aside#documents { }}Media
Image
img { display: block; โ Images are inline by default causing a bottom offset defect
- Inline elements follow the text baseline height
}Web.dev Docs โ Responsive images
Picture
<source srcset="image-portrait.png" media="(orientation: portrait)"/> Image displayed in portrait orientation
<source srcset="image-landscape.png" media="(orientation: landscape)"/> Image displayed in landscape orientation
</picture>Web.dev Docs โ Picture element
Video
<source src="video-portrait.png" type="video/mp4" media="(orientation: portrait)"/> Video displayed in portrait orientation
<source src="video-landscape.png" type="video/mp4" media="(orientation: landscape)"/> Video displayed in landscape orientation
</picture>video {}Typography
Text units
Fluid text size
body {}Utopia โ Fluid Type clamp generator
Text overflow
<p class='ellipsis'>Luxury-grade software craftsmanship across Minecraft modding, developer tooling, and interactive experiences, backed by 10 years of hands-on development.</p> โ Clip text and suffix with ...
<p>Luxury-grade software craftsmanship across <strong>Minecraft modding</strong>, <strong>Developer tooling</strong>, and <strong>Interactive experiences</strong>, backed by 10 years of hands-on development.</p> โstrong text break on the same line
p.ellipsis {}
p strong {}
p strong { }}
body {}Type scale system
<h1>Title</h1><h2>Subtitle</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><h6>Heading 6</h6><p>Paragraph</p>h1 { font-size: 2em; margin-block: 0.67em; /* 2:3 */}
h2..h6 โ 24 collapsed lines
h2 { font-size: 1.5em; margin-block: 0.83em; /* 5:6 */}
h3 { font-size: 1.17em; /* 7:6 */ margin-block: 1em;}
h4 { font-size: 1em; margin-block: 1.33em; /* 4:3 */}
h5 { font-size: 0.83em; /* 5:6 */ margin-block: 1.67em; /* 5:3 */}
h6 { font-size: 0.67em; /* 2:3 */ margin-block: 2.33em; /* 7:3 */}
p { font-size: 1em; margin-block: 1em;} Utopia โ Fluid Type scale generator
GitHub โ Default heading styles
Collection
Flex
<div class="flex"> {data.map((tag) => ( <div class="tag">{tag}</div> ))}</div>.flex { display: flex;}Grid
<div class="grid"> {data.map(([image, title]) => ( <div class="card"> <img src={image} alt={title}/> <h3>{title}</h3> </div> ))}</div>.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));}Conditional
Stylesheet links
<link rel="stylesheet" href="/style.css"/><link rel="alternate stylesheet" href="/desktop.css" media="(min-width: 800px)"/><link rel="alternate stylesheet" href="/mobile.css" media="(max-width: 800px)"/>MDN Web Docs โ Link media queries
Stylesheet imports
@import "style.css";@import "desktop.css" (min-width: 800px);@import "mobile.css" (max-width: 800px);MDN Web Docs โ CSS import media queries
Document styles
@media (min-width: 720px) {}@media (max-width: 720px) {}@media (hover: none) {}MDN Web Docs โ CSS media queries
Container styles
.container {}
@container (min-width: 400px) {}MDN Web Docs โ CSS container queries
Tools
Testing
Typography
Utopia โ Fluid Type clamp generator
Utopia โ Fluid Type scale generator
Resources
MDN Web Docs โ Responsive web design
MDN Web Docs โ CSS media queries
Web.dev โ Learn Responsive Design
Wikipedia โ Responsive web design
Additional Resources
Josh Comeau โ Full-Bleed Layout Using CSS Grid
Web.dev Docs โ Modern layouts
Web.dev Docs โ Responsive web design
Web.dev Docs โ Responsive typography
Web.dev Docs โ Responsive images
Web.dev Docs โ Component-driven responsive web design
W3Schools Docs โ Responsive Web Design
W3Schools Docs โ HTML and CSS Responsive Design