Next JS Image Optimization: Best Practices for Faster Loading
Last Updated :
23 Jul, 2025
Large and unoptimized images can impact a website's performance on loading time. Optimizing images is necessary to improve the performance of the website. Next.js provides built-in support for image optimization to automate the process, providing a balance between image quality and loading speed.
Prerequisites:
Next JS provides a built-in next/image component for optimizing images. It provides features such as automatic resizing, lazy loading, support for various image formats, and many more. It converts jpg, and png file format into a WebP format. WebP is a modern image format that provides lossless and lossy compression for web images. It allows websites to display high-quality images with much smaller file sizes than traditional formats like PNG and JPEG.
To use this component, import it from the next/image.
import Image from 'next/image';
Props supported by Image Components
Property | Description | Values |
---|
src | Takes a path string. Can be an absolute external URL or an internal path. External URLs must be added to remotePatterns in next.config.js . | Path string (URL or internal) |
width | Takes a width in pixels. Helps render a placeholder of the correct size and prevent layout shifts when the actual image loads. | Pixels |
height | Takes a height in pixels. Helps render a placeholder of the correct size and prevent layout shifts when the actual image loads. | Pixels |
alt | Takes text. Used by search engines and displayed if the image is not found. | Text |
layout | Provides layout for the image. | intrinsic, responsive, fixed |
priority | Ensures that images are prioritized during page loading. | true, false |
placeholder | Enhances perceived loading speed and provides a better user experience. | - |
quality | Defines the quality of the image. Takes a value between 1 and 100. Default is 75. | 1 to 100 (default 75) |
Best Practices for Faster Loading Images
Use the Next.js Image Component: Utilize the built-in <Image> component provided by Next.js, which automatically optimizes images for better performance. This component supports features like lazy loading, resizing, and format selection.
Specify Image Dimensions: Always define the width and height attributes for your images. This practice helps the browser allocate the correct space before the image loads, preventing layout shifts and enhancing page performance.
Optimize Image Quality: Adjust the image quality to balance between visual quality and file size. Reducing the quality for less critical images can significantly decrease load times, improving the overall speed of your site.
Use Layout Options: Choose the appropriate layout option (intrinsic, responsive, or fixed) based on your design needs. The responsive layout is especially useful for images that need to adjust to various screen sizes, ensuring they fit well on different devices.
Prioritize Critical Images: Set high-priority attributes for images essential to the initial page load, such as hero images or key visuals. Prioritizing these images ensures they load quickly, improving the initial load time of your page.
Utilize the Placeholder Attribute: Enhance the perceived loading speed by using the placeholder attribute. This feature provides a blurred or empty placeholder while the image loads, offering a smoother user experience.
Creating Next.js Application
Step 1: Create a Next.js application using the following command.
npx create-next-app@latest gfg
Step 2: After creating your project folder i.e. gfg, move to it using the following command.
cd gfg
Project Structure

The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.1.0"
},
"devDependencies": {
"autoprefixer": "^10.0.1",
"postcss": "^8",
"tailwindcss": "^3.3.0",
"eslint": "^8",
"eslint-config-next": "14.1.0"
}
Example: The below example demonstrates the use of Image Optimization.
Note: Remove the included css file from layout.js file.
JavaScript
//File path: src/app/page.js
import Image from "next/image";
export default function Home() {
return (
<>
<h4>Image component:</h4>
<Image
src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210420155809/gfg-new-logo.png"
width={400}
height={100}
alt="GeeksForGeeks Logo"
placeholder="empty"
priority={true}
/>
<br />
<h4>img tag:</h4>
<img
src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210420155809/gfg-new-logo.png"
alt="GeeksForGeeks Logo" />
</>
);
}
JavaScript
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'media.geeksforgeeks.org',
port: '',
pathname:
'/wp-content/cdn-uploads/20210420155809/gfg-new-logo.png',
},
],
},
};
export default nextConfig;
To run the Application open the terminal in the project folder and enter the following command:
npm run dev
Output:
Here, you can see the actual image size and file type is 6.9kb(png) and the optimized image side and file type is 3.5kb(webp)

Conclusion
Optimizing images in Next.js ensures faster load times and better user experience. Use the <Image> component, define dimensions, optimize quality, choose the right layout, prioritize critical images, and use placeholders. These practices prevent layout shifts, reduce load times, and enhance your website's performance and visual appeal.
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. "Hello, World!" Program in ReactJavaScriptimport React from 'react'; function App() {
6 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides DOM-specific methods to interact with and manipulate the Document Object Model (DOM), enabling efficient rendering and management of web page elements. ReactDOM is used for: Rendering Components: Displays React components in the DOM.DOM Manipulation: Al
2 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsIn lists, React makes it easier to render multiple elements dynamically from arrays or objects, ensuring efficient and reusable code. Since nearly 85% of React projects involve displaying data collectionsâlike user profiles, product catalogs, or tasksâunderstanding how to work with lists.To render a
4 min read
React FormsIn React, forms are used to take input from users, like text, numbers, or selections. They work just like HTML forms but are often controlled by React state so you can easily track and update the input values.Example:JavaScriptimport React, { useState } from 'react'; function MyForm() { const [name,
4 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. When rendering a list, you need to assign a unique key prop to each element in th
4 min read
Components in React
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects