| name | responsive-design |
| description | Implement mobile-first responsive design using modern CSS techniques. Support various screen sizes and devices effectively. |
| triggers | ["/responsive","/mobile first"] |
Responsive Web Design
This skill covers implementing mobile-first responsive designs that work effectively across all device sizes using modern CSS techniques.
When to use this skill
Use this skill when you need to:
- Build responsive layouts
- Implement mobile-first designs
- Create flexible grid systems
- Handle responsive images and typography
- Support various device capabilities
Prerequisites
- Understanding of CSS fundamentals
- Knowledge of viewport meta tags
- Familiarity with CSS Grid and Flexbox
- Testing devices or browser DevTools
Guidelines
Mobile-First Approach
Philosophy
- Design for mobile by default
- Progressive enhancement for larger screens
- Content priority drives layout decisions
- Touch-friendly interactions
Viewport Configuration
<meta name="viewport" content="width=device-width, initial-scale=1.0">
CSS Strategy
.card {
padding: 1rem;
width: 100%;
}
@media (min-width: 768px) {
.card {
padding: 1.5rem;
width: 50%;
}
}
@media (min-width: 1024px) {
.card {
padding: 2rem;
width: 33.333%;
}
}
Breakpoint Strategy
Standard Breakpoints
@media (min-width: 768px) { }
@media (min-width: 1024px) { }
@media (min-width: 1280px) { }
@media (min-width: 1536px) { }
Content-Based Breakpoints
- Break when content breaks, not at device widths
- Use relative units (em, rem) for breakpoints
- Test with actual content
.container {
max-width: 100%;
padding: 1rem;
}
@media (min-width: 65ch) {
.container {
max-width: 65ch;
margin: 0 auto;
}
}
Layout Techniques
CSS Grid
.grid {
display: grid;
gap: 1rem;
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 1024px) {
.grid {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
}
.grid-auto {
display: grid;
gap: 1rem;
grid-template-columns: repeat(
auto-fit,
minmax(min(100%, 300px), 1fr)
);
}
Flexbox
.nav {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
@media (min-width: 768px) {
.nav {
flex-direction: row;
gap: 2rem;
}
}
.card-container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
flex: 1 1 300px;
min-width: 0;
}
Responsive Typography
Fluid Typography
h1 {
font-size: clamp(1.5rem, 4vw + 1rem, 3rem);
}
p {
font-size: clamp(1rem, 0.5vw + 0.875rem, 1.25rem);
line-height: 1.6;
}
Responsive Line Height
body {
font-size: 1rem;
line-height: 1.5;
}
@media (min-width: 768px) {
body {
font-size: 1.125rem;
line-height: 1.6;
}
}
Responsive Images
Art Direction
<picture>
<source
media="(max-width: 767px)"
srcset="hero-mobile.jpg"
>
<source
media="(min-width: 768px)"
srcset="hero-desktop.jpg"
>
<img src="hero-default.jpg" alt="Description">
</picture>
Resolution Switching
<img
srcset="
image-400.jpg 400w,
image-800.jpg 800w,
image-1200.jpg 1200w
"
sizes="
(max-width: 600px) 400px,
(max-width: 1000px) 800px,
1200px
"
src="image-800.jpg"
alt="Description"
>
Object Fit
.image-container {
width: 100%;
aspect-ratio: 16 / 9;
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
}
Container Queries
Modern Responsive Alternative
.card-container {
container-type: inline-size;
container-name: card;
}
@container card (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 200px 1fr;
}
}
@container card (min-width: 700px) {
.card {
grid-template-columns: 300px 1fr;
}
}
Touch and Input Considerations
Touch Targets
button,
.nav-link,
.form-input {
min-height: 44px;
min-width: 44px;
}
.nav-list li {
margin-bottom: 0.5rem;
}
Hover Capability
@media (hover: hover) {
.button:hover {
background-color: #0056b3;
}
}
@media (hover: none) {
.button:active {
background-color: #0056b3;
}
}
Dark Mode Support
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1a1a1a;
--text-color: #e0e0e0;
}
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
Testing
Device Testing Checklist
Browser DevTools
- Responsive Design Mode
- Device emulation
- Network throttling
- Touch simulation
Examples
See the examples/ directory for:
grid-layouts/ - Responsive grid patterns
navigation-patterns/ - Responsive nav designs
typography-system/ - Fluid type scales
dark-mode/ - Dark mode implementation
References