skills/nextjs-image-art-direction/SKILL.md
Implement art direction for Next.js images using getImageProps(). Use when showing different images for different viewport sizes, such as homepage carousels with mobile vs desktop assets, different cropping/composition, or when mobile and desktop images differ completely.
npx skillsauth add Chris-Maskey/opencode-config nextjs-image-art-directionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Art direction means showing completely different images based on viewport size — not just resizing the same image. Common use cases include homepage carousels with different assets for mobile vs desktop, switching from landscape (desktop) to portrait (mobile), or showing cropped vs full compositions.
| Approach | Purpose | Implementation |
|----------|---------|----------------|
| Art Direction | Different image content/composition | <picture> with multiple <source> elements |
| Responsive Images | Same image, different sizes | sizes prop with srcset |
Use Art Direction When:
Use Responsive Images When:
getImageProps()The getImageProps() function (stable since Next.js 14.1.0) generates the necessary props without calling React useState(), making it ideal for art direction.
import { getImageProps } from 'next/image'
export default function ArtDirectedImage() {
// Common props shared across all image versions
const common = {
alt: 'Mountain landscape',
sizes: '100vw'
}
// Desktop version (landscape, higher quality)
const {
props: { srcSet: desktop },
} = getImageProps({
...common,
src: '/hero-desktop.jpg',
width: 1440,
height: 875,
quality: 80,
})
// Mobile version (portrait, smaller dimensions)
const {
props: { srcSet: mobile, ...rest },
} = getImageProps({
...common,
src: '/hero-mobile.jpg',
width: 750,
height: 1334,
quality: 70,
})
return (
<picture>
{/* Desktop: min-width 1000px */}
<source media="(min-width: 1000px)" srcSet={desktop} />
{/* Mobile: min-width 500px */}
<source media="(min-width: 500px)" srcSet={mobile} />
{/* Fallback img element (rendered if no media query matches) */}
<img {...rest} style={{ width: '100%', height: 'auto' }} />
</picture>
)
}
Props to Vary by Breakpoint:
src: Different image filewidth / height: Different dimensionsquality: Different compression levelsCommon Props (Shared):
alt: Accessibility text (must work for all versions)sizes: Responsive size hints for browserHTML Structure:
<picture> wrapper element<source> elements with media attribute for each breakpoint<img> element last as fallback (required)Order matters! The browser uses the first matching <source>. List from largest to smallest (desktop-first) or smallest to largest (mobile-first).
<picture>
<source media="(min-width: 1000px)" srcSet={desktop} />
<source media="(min-width: 500px)" srcSet={tablet} />
<img {...rest} style={{ width: '100%', height: 'auto' }} />
</picture>
<picture>
<source media="(max-width: 499px)" srcSet={mobile} />
<source media="(max-width: 999px)" srcSet={tablet} />
<img {...rest} style={{ width: '100%', height: 'auto' }} />
</picture>
preload or loading="eager"These would cause all images to load immediately, defeating the purpose of art direction:
// BAD: Would load both desktop and mobile
getImageProps({
src: '/desktop.jpg',
preload: true, // Don't do this!
})
// BAD: Same problem
getImageProps({
src: '/desktop.jpg',
loading: 'eager', // Don't do this!
})
Solution: Use fetchPriority="high" if you need to prioritize the LCP image:
const common = {
alt: 'Hero image',
fetchPriority: 'high', // Only load the matching image eagerly
}
The alt text is shared across all image versions. Make sure it accurately describes all possible images:
// BAD: Only describes desktop version
const common = { alt: 'Wide panoramic mountain landscape' }
// GOOD: Describes both versions
const common = { alt: 'Mountain landscape with snow-capped peaks' }
placeholder PropgetImageProps() doesn't support the placeholder prop because the placeholder would never be removed. Handle loading states manually if needed.
Missing images will cause broken image icons on certain devices. Always test on actual devices or browser dev tools with different viewport sizes.
import { getImageProps } from 'next/image'
export default function Hero() {
const common = {
alt: 'Team collaboration in modern office',
sizes: '100vw',
fetchPriority: 'high',
}
// Large desktop: Full office scene
const { props: { srcSet: desktop } } = getImageProps({
...common,
src: '/hero-office-wide.jpg',
width: 1920,
height: 1080,
quality: 85,
})
// Tablet: Focused team shot
const { props: { srcSet: tablet } } = getImageProps({
...common,
src: '/hero-team-focused.jpg',
width: 1024,
height: 768,
quality: 80,
})
// Mobile: Single person portrait
const { props: { srcSet: mobile, ...rest } } = getImageProps({
...common,
src: '/hero-person-portrait.jpg',
width: 750,
height: 1334,
quality: 75,
})
return (
<section className="relative">
<picture>
<source media="(min-width: 1200px)" srcSet={desktop} />
<source media="(min-width: 768px)" srcSet={tablet} />
<source media="(min-width: 500px)" srcSet={mobile} />
<img
{...rest}
className="w-full h-auto object-cover"
style={{ maxHeight: '80vh' }}
/>
</picture>
<div className="absolute inset-0 flex items-center justify-center">
<h1 className="text-white text-4xl font-bold drop-shadow-lg">
Welcome to Our Platform
</h1>
</div>
</section>
)
}
You can use getImageProps() to optimize background images with image-set():
import { getImageProps } from 'next/image'
function getBackgroundImage(srcSet = '') {
const imageSet = srcSet
.split(', ')
.map((str) => {
const [url, dpi] = str.split(' ')
return `url("${url}") ${dpi}`
})
.join(', ')
return `image-set(${imageSet})`
}
export default function HeroBackground() {
const {
props: { srcSet },
} = getImageProps({
alt: '',
width: 1920,
height: 1080,
src: '/hero-bg.jpg',
quality: 80,
})
const backgroundImage = getBackgroundImage(srcSet)
return (
<main
style={{
height: '100vh',
width: '100vw',
backgroundImage,
backgroundSize: 'cover',
backgroundPosition: 'center',
}}
>
<h1>Content Here</h1>
</main>
)
}
getImageProps() for multiple image versionsalt and sizes across all versions<source> elements correctly (first match wins)fetchPriority="high" for LCP images (not preload)preload prop (loads all images)loading="eager" (loads all images)placeholder prop with getImageProps()<img> elementtools
Anti-patterns and mistakes to avoid as a product manager. Use when evaluating leadership behaviors, improving team dynamics, reflecting on management practices, or onboarding new product managers.
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
testing
Design effective CTAs using visual attention and gaze psychology principles. Use when designing landing pages, button hierarchies, conversion elements, or optimizing user attention flow through interfaces.
tools
Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include "Vercel Sandbox browser", "microVM Chrome", "agent-browser in sandbox", "browser automation on Vercel", or any task requiring Chrome in a Vercel Sandbox.