How to create circle button in react js?

Hi Friends πŸ‘‹,

Welcome To aHoisting!

To create circle button in react js, you can set border-radius: 50%; in .circle-button. It will create circle button in react js.

Today, I am going to show you, how to create circle button in react js.

Table of contents

  • Install and create a new React app.
  • Import react component.
  • Create a Component.

Let’s start with the first step.

Step 1: Install and create a new React app.

First you have to install the React project. You should use create-react-app command to create a new React project.

npx create-react-app my-app
cd my-app
npm start

Step 2: Import react component.

After installing, you have to import your React component.

import React from 'react';
import './App.css'; 

Step 3: Create a Component.

You can use className="circle-button" to create circle button in react js.

<button className="circle-button" onClick={onClick}>
  Button
</button>

Create circle button example.

The below code is an example of a React. You have to import './App.css' and set border-radius: 50%; in .circle-button to create circle button in react js.

App.js

import React from 'react';
import './App.css'; 

const CircleButton = ({ onClick}) => {
  return (
    <button className="circle-button" onClick={onClick}>
      Button
    </button>
  );
};

export default CircleButton;

App.css


.circle-button {
  width: 50px; /* Set equal width and height */
  height: 50px;
  border-radius: 50%; /* Makes the shape circular */
  background-color: #4caf50; /* Button color */
  color: white; /* Text color */
  border: none; /* Remove default border */
  display: flex; /* Center content */
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer; /* Pointer cursor for interaction */
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2); /* Optional shadow */
  transition: background-color 0.3s ease; /* Smooth hover effect */
}

.circle-button:hover {
  background-color: #45a049; /* Darker shade on hover */
}

In the above code example, I have used the border-radius: 50%; to create circle button in react js.

Check the output of the above code.

React, create, circle, button

All the best πŸ‘