How to add Color Picker in NextJS?
Last Updated :
25 Jul, 2024
To add a color picker in Next.js, integrate a third-party library available on npm. This allows users to select colors easily, enhancing the interactivity and user experience of your application. In this article, we are going to learn how we can add a color picker in NextJS.
Approach
To add our color picker we are going to use the react-color-palette package. The react-color-palette package helps us to integrate different types of color pickers. So first, we will install the react-color-palette package, and then we will add a color picker on our homepage.
Steps to Create NextJS Application
You can create a new NextJs project using the below command:
npx create-next-app gfg
cd gfg
Install the required package: Now we will install the react-color-palette package using the below command:
npm i react-color-palette
Project Structure:

The updated dependencies in the package.json file are:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-color-palette": "^7.2.1",
"react-dom": "^18"
}
After installing the package we can easily add color picker on any page in our app. For this example, we are going to add color picker to our homepage.
Example: This example demonstrates adding color picker in nextjs app with the help of react-color-palette npm package.
JavaScript
// Filename - pages/index.js
import React from "react";
import { ColorPicker, useColor } from "react-color-palette";
import "react-color-palette/lib/css/styles.css";
export default function SkeletonLoading() {
const [color, setColor] = useColor("hex", "#121212");
return (
<div>
<h2>NextJs Color Picker - GeeksforGeeks</h2>
<ColorPicker width={456} height={228}
color={color} onChange={setColor} hideHSV dark />
</div>
);
}
Explanation: In the above example first, we are importing the Color Picker component and after that, we are using useColor hook to store the value of the selected color. Then we are adding our color picker using the imported component.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
How to create Emoji Picker in NextJS ? Adding an emoji picker to your Next.js app makes it easy for users to express themselves with emojis. By integrating a simple and intuitive emoji picker, you can enhance user interactions and make your app more engaging and fun. In this article, we are going to learn how we can add Emoji Picker in N
2 min read
How to add Slider in Next.js ? Adding a slider in Next.js involves integrating a slider component, like react-range, managing its state using React hooks and applying styles for customization, enhancing user interaction and input precision in your application.ApproachTo add our Slider we are going to use the react-range package.
2 min read
How to Add ChartJS in NextJS 13? Chart.js in Next.js is the package used to create interactive and visually appealing charts, such as line charts, bar charts, and more, seamlessly integrated into Next.js applications. In this article, we will explore the demonstration of various charts in the NextJS application. Table of Content Im
3 min read
How to add Calendar in Next.js ? Adding a calendar to a Next.js application enhances scheduling and event management. We can just install and use the available npm package. In this article, we are going to learn how we can add a calendar loader in NextJS.ApproachTo add our calendar we are going to use the react-calendar package. Th
2 min read
How to Add Simple DatePicker in Next.js ? In this article, we are going to learn how we can add a Simple Datepicker in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components
2 min read
How to Add Spinner Loader in Next.js ? In web applications, providing a smooth and responsive user experience is very important. One way to achieve this is by adding a spinner loader to indicate that a process is ongoing, such as fetching data or loading a new page. In this article, we'll explore how to add a spinner loader in a Next.js
2 min read