0
0
NextJSframework~20 mins

Responsive images in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Responsive Image Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Next.js Image component?

Consider this Next.js Image component usage:

import Image from 'next/image';

export default function Example() {
  return (
    <Image
      src='/photo.jpg'
      alt='Sample photo'
      width={800}
      height={600}
      sizes='(max-width: 600px) 480px, 800px'
      priority
    />
  );
}

What will the browser do regarding image loading and size?

AThe image will load lazily and use 480px width on all screen sizes.
BThe image will load eagerly with priority and use 480px width on screens up to 600px wide, otherwise 800px width.
CThe image will load eagerly but ignore the sizes attribute and always use 600px width.
DThe image will load lazily and always use 800px width regardless of screen size.
Attempts:
2 left
💡 Hint

Check the priority prop and the sizes attribute.

📝 Syntax
intermediate
2:00remaining
Which option correctly uses Next.js Image component for responsive images?

Choose the correct syntax to make an image responsive using Next.js Image component with automatic layout adjustment.

A<Image src='/img.png' alt='desc' sizes='100vw' layout='fixed' />
B<Image src='/img.png' alt='desc' width='400' height='300' layout='responsive' />
C<Image src='/img.png' alt='desc' width={400} height={300} layout='responsive' />
D<Image src='/img.png' alt='desc' width={400} height={300} layout='fill' />
Attempts:
2 left
💡 Hint

Check the correct prop types and layout values.

🔧 Debug
advanced
2:00remaining
Why does this Next.js Image component cause a layout shift?

Given this code:

import Image from 'next/image';

export default function Demo() {
  return (
    <Image
      src='/landscape.jpg'
      alt='Landscape'
      width={0}
      height={0}
      style={{ width: '100%', height: 'auto' }}
    />
  );
}

Why does the page experience layout shift when the image loads?

ABecause the src path is incorrect, so the image never loads.
BBecause style uses percentages, which Next.js does not support for images.
CBecause the alt attribute is missing, causing rendering issues.
DBecause width and height are zero, Next.js cannot reserve space, causing layout shift.
Attempts:
2 left
💡 Hint

Think about how Next.js reserves space for images.

🧠 Conceptual
advanced
2:00remaining
What is the main benefit of using Next.js Image component for responsive images?

Why should developers use Next.js Image component instead of a regular <img> tag for responsive images?

AIt automatically optimizes images, serves correct sizes, and improves performance and SEO.
BIt disables lazy loading by default to speed up page load.
CIt requires no width or height props, making coding faster.
DIt converts all images to SVG format for better scalability.
Attempts:
2 left
💡 Hint

Think about performance and image delivery.

state_output
expert
2:00remaining
What is the rendered output width of this Next.js Image on a 500px wide screen?

Given this component:

import Image from 'next/image';

export default function ResponsiveImg() {
  return (
    <Image
      src='/banner.jpg'
      alt='Banner'
      width={1200}
      height={400}
      sizes='(max-width: 600px) 100vw, 50vw'
      style={{ width: 'auto', height: 'auto' }}
    />
  );
}

On a screen 500px wide, what width will the image render?

A500px, because sizes says 100vw for max-width 600px screens.
B600px, because sizes uses 600px as max-width breakpoint.
C600px, because width prop is 1200 but style overrides it.
D1200px, because width prop sets fixed width regardless of screen.
Attempts:
2 left
💡 Hint

Check the sizes attribute and screen width.