Next.js Image Component

Image Properties

Practice different properties of the Next.js Image component and understand how they help with performance, responsiveness, accessibility, and user experience.

A quick reference for the most useful properties of the Next.jsImagecomponent.

#PropertyPurposeExample
01srcImage sourcesrc="/images/photo.png"
02altAccessibility descriptionalt="Profile photo"
03widthImage widthwidth={400}
04heightImage heightheight={300}
05fillMakes the image fill its parentfill
06priorityLoads an important image earlypriority
07loadingControls loading behaviorloading="eager"
08sizesHelps responsive image optimizationsizes="(max-width: 768px) 100vw, 50vw"
09qualityControls image qualityquality={75}
10placeholderShows a placeholder while loadingplaceholder="blur"
11blurDataURLProvides a custom blur placeholderblurDataURL="data:image/..."
12classNameAdds CSS or Tailwind stylingclassName="rounded-xl"
13styleAdds inline CSS stylingstyle={{ objectFit: "cover" }}
14unoptimizedSkips Next.js image optimizationunoptimized

Total properties covered: 14

Sofian Hasan profile

Width & Height

Define the intrinsic dimensions of an image using thewidth andheight properties.

Sofian Hasan

Fill

Thefillproperty makes the image fill its parent container.

Sofian Hasan portrait

Priority

Thepriorityproperty tells Next.js that an important image should load earlier.

Profile image

Loading

Theloadingproperty controls when the browser loads the image.

Sofian Hasan

Quality

Thequalityproperty controls the requested image quality during optimization.

Modern workspace

Responsive Sizes

Thesizesproperty tells Next.js how much space the image occupies at different screen sizes.

Profile image

Blur Placeholder

Theplaceholder="blur"option displays a blurred preview while the image loads.

Sofian Hasan

Styling

UseclassNameto apply Tailwind CSS classes and customize the appearance of the image.

Sofian Hasan

Unoptimized

Theunoptimizedproperty tells Next.js to serve the image without its normal image optimization process.