Design responsive layouts with breakpoints, mobile-first approach, and flexible grids. Use when creating responsive designs, implementing breakpoints, or optimizing for multiple screen sizes.
Design responsive layouts that work across all device sizes.
Use mobile-first approach, flexible units (rem, %), CSS Grid/Flexbox, and test on real devices.
Start with mobile, enhance for larger screens:
/* Base styles (mobile) */
.container {
padding: 1rem;
}
/* Tablet */
@media (min-width: 768px) {
.container {
padding: 2rem;
}
}
/* Desktop */
@media (min-width: 1024px) {
.container {
padding: 3rem;
max-width: 1200px;
margin: 0 auto;
}
}
Standard breakpoints:
/* Mobile: 0-639px (default) */
/* Tablet: 640px+ */
@media (min-width: 640px) { }
/* Laptop: 1024px+ */
@media (min-width: 1024px) { }
/* Desktop: 1280px+ */
@media (min-width: 1280px) { }
/* Large: 1536px+ */
@media (min-width: 1536px) { }
Tailwind breakpoints:
<div className="
w-full // Mobile
md:w-1/2 // Tablet
lg:w-1/3 // Desktop
">
Content
</div>
CSS Grid:
.grid {
display: grid;
gap: 1rem;
/* Mobile: 1 column */
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.grid {
/* Tablet: 2 columns */
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 1024px) {
.grid {
/* Desktop: 3 columns */
grid-template-columns: repeat(3, 1fr);
}
}
Auto-fit grid:
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
}
Flexbox:
.flex-container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.flex-item {
flex: 1 1 100%; /* Mobile: full width */
}
@media (min-width: 768px) {
.flex-item {
flex: 1 1 calc(50% - 0.5rem); /* Tablet: 2 columns */
}
}
@media (min-width: 1024px) {
.flex-item {
flex: 1 1 calc(33.333% - 0.667rem); /* Desktop: 3 columns */
}
}
Fluid typography:
h1 {
font-size: clamp(2rem, 5vw, 4rem);
}
p {
font-size: clamp(1rem, 2vw, 1.125rem);
}
Responsive scale:
/* Mobile */
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
p { font-size: 1rem; }
/* Desktop */
@media (min-width: 1024px) {
h1 { font-size: 3rem; }
h2 { font-size: 2rem; }
p { font-size: 1.125rem; }
}
Responsive image:
img {
max-width: 100%;
height: auto;
}
Art direction:
<picture>
<source
media="(min-width: 1024px)"
srcSet="desktop.jpg"
/>
<source
media="(min-width: 768px)"
srcSet="tablet.jpg"
/>
<img src="mobile.jpg" alt="Description" />
</picture>
Responsive background:
.hero {
background-image: url('mobile.jpg');
}
@media (min-width: 768px) {
.hero {
background-image: url('tablet.jpg');
}
}
@media (min-width: 1024px) {
.hero {
background-image: url('desktop.jpg');
}
}
Component-based responsive:
.card-container {
container-type: inline-size;
}
.card {
padding: 1rem;
}
@container (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 1fr 2fr;
}
}
Mobile menu:
function Navigation() {
const [isOpen, setIsOpen] = useState(false);
return (
<nav>
{/* Mobile: Hamburger */}
<button
className="md:hidden"
onClick={() => setIsOpen(!isOpen)}
>
Menu
</button>
{/* Mobile: Drawer */}
<div className={`
fixed inset-0 bg-white transform transition-transform
${isOpen ? 'translate-x-0' : '-translate-x-full'}
md:relative md:translate-x-0
`}>
<ul className="flex flex-col md:flex-row">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</nav>
);
}
Minimum size:
button, a {
min-height: 44px; /* iOS recommendation */
min-width: 44px;
padding: 0.75rem 1rem;
}
Touch-friendly spacing:
.button-group button {
margin: 0.5rem; /* Space between touch targets */
}
Full height:
.hero {
height: 100vh; /* Viewport height */
height: 100dvh; /* Dynamic viewport (mobile) */
}
Responsive spacing:
.section {
padding: 5vw; /* Scales with viewport */
}
Sidebar layout:
.layout {
display: grid;
gap: 2rem;
/* Mobile: Stack */
grid-template-columns: 1fr;
}
@media (min-width: 1024px) {
.layout {
/* Desktop: Sidebar + main */
grid-template-columns: 250px 1fr;
}
}
Card grid:
.cards {
display: grid;
gap: 1rem;
/* Mobile: 1 column */
grid-template-columns: 1fr;
}
@media (min-width: 640px) {
.cards {
/* Tablet: 2 columns */
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: 1024px) {
.cards {
/* Desktop: 3 columns */
grid-template-columns: repeat(3, 1fr);
}
}
@media (min-width: 1280px) {
.cards {
/* Large: 4 columns */
grid-template-columns: repeat(4, 1fr);
}
}
Hero section:
.hero {
padding: 2rem 1rem;
text-align: center;
}
@media (min-width: 768px) {
.hero {
padding: 4rem 2rem;
}
}
@media (min-width: 1024px) {
.hero {
padding: 6rem 3rem;
text-align: left;
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
}
}
Browser DevTools:
Test on real devices:
Responsive testing tools:
Layout:
Typography:
Images:
Navigation:
Performance:
Use relative units:
/* Good */
padding: 1rem;
font-size: 1.125rem;
width: 80%;
/* Avoid */
padding: 16px;
font-size: 18px;
width: 800px;
Test early and often:
Progressive enhancement:
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer