Edit these docs Rate these docs

React Bootstrap Checkbox MDB Pro component

React checkbox - Bootstrap 4 & Material Design

Checkbox is a component used for allowing a user to make a multiple choice. Broadly used in the forms and surveys.

Checkboxes are for selecting one or several options in a list, while radios are for selecting one option from many.


Basic examples

Default styling for Bootstrap Checkbox component


            import React from 'react';
            import { MDBInput } from 'mdbreact';

            const InputPage = () => {
              return (
                <div>
                  {/* Filled-in unchecked */}
                  <MDBInput label="Filled-in unchecked" filled type="checkbox" id="checkbox1" />

                  {/* Filled-in checked */}
                  <MDBInput label="Filled-in unchecked" filled checked type="checkbox" id="checkbox2" />

                  {/* Filled-in unchecked disabled */}
                  <MDBInput label="Filled-in unchecked" filled disabled type="checkbox" id="checkbox3" />

                  {/* Filled-in checked disabled */}
                  <MDBInput label="Filled-in unchecked" filled checked disabled type="checkbox" id="checkbox4" />
                </div>
              )
            }

            export default InputPage;
          

Material checkboxes

Material Design styling for Bootstrap Checkbox component


              import React from 'react';
              import { MDBInput } from 'mdbreact';

              const InputPage = () => {
                return (
                  <div>
                    {/* Material unchecked */}
                    <MDBInput label="Filled-in unchecked" type="checkbox" id="checkbox1" />

                    {/* Material checked */}
                    <MDBInput label="Filled-in unchecked" checked type="checkbox" id="checkbox2" />

                    {/* Material unchecked disabled */}
                    <MDBInput label="Filled-in unchecked" disabled type="checkbox" id="checkbox3" />

                    {/* Material checked disabled */}
                    <MDBInput label="Filled-in unchecked" checked disabled type="checkbox" id="checkbox4" />
                  </div>
                )
              }

              export default InputPage;
            

Checked state

Add checked prop to the <Input> component to pre-select checkbox when the page loads. The checked prop is a boolean attribute.The checked attribute can be used with <Input type="checkbox"> and <Input type="radio">.

Default checkbox


            import React from 'react';
            import { MDBInput } from 'mdbreact';

            const InputPage = () => {
              return (
                <div>
                  {/* Filled-in checked */}
                  <MDBInput label="Filled-in unchecked" filled checked type="checkbox" id="checkbox2" />
                </div>
              )
            }

            export default InputPage;
            

Material checkbox


              import React from 'react';
              import { MDBInput } from 'mdbreact';

              const InputPage = () => {
                return (
                  <div>
                    {/* Material checked */}
                    <MDBInput label="Filled-in unchecked" checked type="checkbox" id="checkbox2" />
                  </div>
                )
              }

              export default InputPage;
            

Disabled state

Add the disabled boolean attribute to the <Input> component and the custom indicator and label description will be automatically styled and blocked. A disabled <Input> component is unusable and un-clickable.

Default checkbox


            import React from 'react';
            import { MDBInput } from 'mdbreact';

            const InputPage = () => {
              return (
                <div>
                  {/* Filled-in unchecked disabled */}
                  <MDBInput label="Filled-in unchecked" filled disabled type="checkbox" id="checkbox3" />

                  {/* Filled-in checked disabled */}
                  <MDBInput label="Filled-in unchecked" filled checked disabled type="checkbox" id="checkbox4" />
                </div>
              )
            }

            export default InputPage;
            

Material checkbox


              import React from 'react';
              import { MDBInput } from 'mdbreact';

              const InputPage = () => {
                return (
                  <div>
                    {/* Material unchecked disabled */}
                    <MDBInput label="Filled-in unchecked" disabled type="checkbox" id="checkbox3" />

                    {/* Material checked disabled */}
                    <MDBInput label="Filled-in unchecked" checked disabled type="checkbox" id="checkbox4" />
                  </div>
                )
              }

              export default InputPage;
            

Inline

Group checkboxes or radios on the same horizontal row by wraping <Input> components in <FormInline> component.

Default checkboxes


            import React from 'react';
            import { MDBInput, MDBFormInline } from 'mdbreact';

            const InputPage = () => {
              return (
                <div>
                  {/* Filled-in inline */}
                  <MDBFormInline>
                    <MDBInput label="1" filled type="checkbox" id="checkbox1" />
                    <MDBInput label="2" filled type="checkbox" id="checkbox2" />
                    <MDBInput label="3" filled type="checkbox" id="checkbox3" />
                  </MDBFormInline>
                </div>
              )
            }

            export default InputPage;
            

Material checkboxes


            import React from 'react';
            import { MDBInput, MDBFormInline } from 'mdbreact';

            const InputPage = () => {
              return (
                <div>
                  {/* Material inline */}
                  <MDBFormInline>
                    <MDBInput label="1" type="checkbox" id="checkbox1" />
                    <MDBInput label="2" type="checkbox" id="checkbox2" />
                    <MDBInput label="3" type="checkbox" id="checkbox3" />
                  </MDBFormInline>
                </div>
              )
            }

            export default InputPage;
            

Install MDB CLI
It's the fastest way to create and host MDB projects
Free Download

Edit these docs Rate these docs

Checkbox - API

In this section you will find advanced information about the React Checkbox component. You will learn which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use to work with it.


Import statement

In order to use Checkbox component make sure you have imported proper module first.


        import React from 'react';
        import { MDBInput } from 'mdbreact';
        

API Reference: Properties

The table below shows the configuration options of the MDBInput component.

Name Type Default Description Example
checked Boolean false Pre-selects checkbox/radio button when the page loads. <MDBInput checked />
className String Adds custom class to Input component <MDBInput className="myClass" />
containerClass String Adds custom class to wrapping div <MDBInput containerClass="wrapper" />
disabled Boolean false Disables input component <MDBInput disabled />
error String Sets the error message for the labels data-error attribute <MDBInput error="Whoops!" />
filled Boolean false Add filled-in style to checkbox/radio button <MDBInput type="checkbox" filled />
gap Boolean false Creates gap inside checkbox/radio button <MDBInput type="checkbox" gap />
group Boolean false Add .form-group class to the wrapping div <MDBInput group />
hint String Sets the placeholder for the Input <MDBInput hint="Placeholder" />
icon String Adds font-awesome icon <MDBInput icon="caret-right" />
iconBrand Boolean false Use this property to set brand icon (fab) <MDBInput icon="twitter" iconBrand />
iconClassName String Adds custom classes to icon element <MDBInput icon="envelope" iconClassName="customClass" />
iconLight Boolean false Use this property to set light icon (fal) <MDBInput icon="twitter" iconLight />
iconRegular Boolean false Use this property to set regular icon (far) <MDBInput icon="twitter" iconRegular />
iconSize String Sets icon size <MDBInput icon="pencil-alt" size="5x" />
id String Required! Set the id of the input element <MDBInput id="myId" />
inputRef Function Allows to attach React Ref to the input component; accepts only Callback Ref <MDBInput inputRef={ref => this.myRef = ref } />
label String Add label to the component; you can attach jsx elements (f.e. links) <MDBInput label="My custom input" />
labelClass String Adds custom class to the label <MDBInput labelClass="labelCustomClass" />
size String Changes size of the component; available lg and sm <MDBInput size="sm" />
success String Sets the success message for the labels data-success attribute <MDBInput success="Yeah!" />
tag String input Changes default input tag <MDBInput tag="div" />
type String text The type of the input element <MDBInput type="checkbox" />
validate Boolean false Adds .validate class to the Input component <MDBInput validate />
value String The value of the input element (use with the controlled input) <MDBInput value="I am controlled" onChange={this.handleChange} />
valueDefault String The default value of the input (use with the uncontrolled input) <MDBInput valueDefault="I am uncontrolled" />

API Reference: Methods

The table below shows the methods which you can use with MDBInput component.

Name Parameters Description Example
getValue Method called on input change event; returns input value <MDBInput getValue={this.getValue} />
onBlur Method called on blur event, the blur event is raised when an element loses focus; returns event object <MDBInput onBlur={this.handleBlur} />
onChange Method called on change event; returns event object <MDBInput onChange={this.handleChange} />
onFocus Method called on focus event, the focus event is raised when the user sets focus on en element; returns event object <MDBInput onFocus={this.handleFocus} />
onInput Method called on input event; returns event object <MDBInput onInput={this.handleInput} />
Edit these docs Rate these docs

React Checkbox - examples & customization

Quickly get a project started with any of our examples.


Checkbox color change


        import React from 'react';
        import { MDBInput } from 'mdbreact';

        const InputPage = () => {
          return (
            <div>
              {/* Teal example */}
              <MDBInput containerClass="form-check checkbox-teal" labelClass="form-check-label" label="Teal checkbox" type="checkbox"
                id="tealExample" checked />

              {/* Filled-in orange example */}
              <MDBInput containerClass="form-check checkbox-warning-filled" filled labelClass="form-check-label" label="Filled-in orange example"
                type="checkbox" id="orangeExample" checked />
            </div>
          )
        }

        export default InputPage;
      


          .checkbox-teal [type="checkbox"]:checked+label:before {
            border-color: transparent #009688 #009688 transparent;
          }

          .checkbox-warning-filled [type="checkbox"][class*='filled-in']:checked+label:after {
            border-color: #FF8800;
            background-color: #FF8800;
          }

      

Rounded checkbox


        import React from 'react';
        import { MDBInput } from 'mdbreact';
        import './index.css'

        const InputPage = () => {
          return (
            <div>
              {/* Filled-in rounded example */}
              <MDBInput containerClass="form-check checkbox-rounded" labelClass="form-check-label" label="Filled-in rounded example"
                type="checkbox" className="checkbox-rounded" filled id="roundedExample" checked />
            </div>
          )
        }

        export default InputPage;
      


        .checkbox-rounded [type="checkbox"][class*='filled-in']+label:after {
          border-radius: 50%;
        }