React Chakra UI Form Switch
Last Updated :
28 Apr, 2025
Chakra UI Form Switch is a component provided by Chakra UI for creating toggle switches in React applications. It is an alternative to checkboxes, allowing users to switch between enabled and disabled states. Using the props of the Chakra UI Form Switch we can customize its appearance by changing the state, behavior, sizes, appearance, etc. In this article, we will explore the practical implementation of the Chakra UI Form Switch component by demonstrating all the types of switches.
Prerequisites:
Approach:
We have created different Chakra UI Form Switch components like a size-based, disabling switch, focused switch, invalid, read-only state, etc. Using this Chakra UI Form Switch component, we can embed it into the real-time application as an alternative to the traditional checkboxes. This increases the modern perspective of the application and enables the user to engage with the application.
Steps to Create React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app chakra
Step 2: After creating your project folder(i.e. chakra), move to it by using the following command:
cd chakra
Step 3: After creating the React application, Install the required package using the following command:
npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
Project Structure:

The updated dependencies are in the package.json file.
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"framer-motion": "^6.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: Below is the practical implementation of the Chakra UI Form Switch.
JavaScript
import React from 'react';
import {
ChakraProvider,
Box,
Flex,
FormControl,
FormLabel,
Switch,
Stack,
Heading,
} from '@chakra-ui/react';
function App() {
return (
<ChakraProvider>
<Box p={5}>
<Heading as="h1" mb={4}
color="green.500">
GeeksforGeeks
</Heading>
<Heading as="h3" mb={4}>
Chakra UI Form Switch
</Heading>
<Flex
direction={{
base: 'column',
md: 'row'
}}
alignItems={{
base: 'center',
md: 'flex-start'
}}
mb={4}
>
<FormLabel htmlFor='email-alerts'
mb={{ base: '2', md: '0' }}>
Receive Email Alerts?
</FormLabel>
<Switch id='email-alerts'
colorScheme='green' />
</Flex>
<Stack align='center' direction='row'
spacing={4} mb={4}>
<Switch size='sm' colorScheme='teal' />
<Switch size='md' colorScheme='teal' />
<Switch size='lg' colorScheme='teal' />
</Stack>
<Stack direction='row' spacing={4} mb={4}>
<Switch colorScheme='red' size='lg' />
<Switch colorScheme='teal' size='lg' />
</Stack>
<Stack
direction={{ base: 'column', md: 'row' }}
spacing={4}
mb={4}
>
<FormControl as={Stack} spacing={4}
mb={{ base: '4', md: '0' }}>
<FormLabel htmlFor='isChecked'>
Receive Updates:
</FormLabel>
<Switch id='isChecked'
isChecked colorScheme='purple' />
<FormLabel htmlFor='isDisabled'>
Disable Notifications:
</FormLabel>
<Switch id='isDisabled' isDisabled
defaultChecked colorScheme='blue' />
<FormLabel htmlFor='isFocusable'>
Focusable (Disabled):
</FormLabel>
<Switch id='isFocusable' isFocusable
isDisabled colorScheme='green' />
</FormControl>
<FormControl as={Stack} spacing={4}>
<FormLabel htmlFor='isInvalid'>
Invalid State:
</FormLabel>
<Switch id='isInvalid' isInvalid
colorScheme='red' />
<FormLabel htmlFor='isReadOnly'>
Read-Only State:
</FormLabel>
<Switch id='isReadOnly' isReadOnly
colorScheme='orange' />
<FormLabel htmlFor='isRequired'>
Required Field:
</FormLabel>
<Switch id='isRequired' isRequired
colorScheme='teal' />
</FormControl>
</Stack>
</Box>
</ChakraProvider>
);
}
export default App;
Step to run the application: Run the application using the following command:
npm run start
Output: Now go to http://localhost:3000 in your browser:

Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
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
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read