FormCheckbox
A form checkbox component with built-in label, description, and error handling capabilities.
FormCheckbox
A comprehensive checkbox component that combines labels, descriptions, and validation states. Perfect for creating accessible, user-friendly forms that require selection inputs with proper labeling and helpful context.
Default
The default FormCheckbox includes a label and optional description text, providing clear context for users.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S1:-helper" id=":S1:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S1:" id=":S1:-label" > I agree to receive marketing emails </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":S1:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> We'll send you occasional updates about our products </span> </output> </div> </fieldset>
Checkbox States
Required Field
Use the required prop to indicate mandatory fields. This automatically adds a "Required" tag to the label.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S2:-helper" aria-required id=":S2:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S2:" id=":S2:-label" > I agree to the Terms of Service <span className="inline-flex items-center rounded border px-1 py-0.5 text-xs font-sans ml-2 border-warning-4 text-warning-11 bg-warning-3 dark:border-warning-4 dark:text-warning-11 dark:bg-warning-3"> Required </span> </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":S2:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> You must accept our terms to continue </span> </output> </div> </fieldset>
Required Field with Error
When a required field has an error, the "Required" tag changes to error styling to draw more attention.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S3:-error" aria-invalid aria-required color="danger" id=":S3:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S3:" id=":S3:-label" > I agree to the Terms of Service <span className="inline-flex items-center rounded border px-1 py-0.5 text-xs font-sans ml-2 border-error-4 text-error-11 bg-error-3"> Required </span> </label> </div> </div> <div className="text-[13px] leading-5"> <div className="text-error-11 flex gap-2 items-center" id=":S3:-error" role="alert" > <svg aria-hidden="true" className="flex-shrink-0" height="12" size="sm-regular" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="6" cy="10.125" fill="currentColor" r=".875" strokeWidth="0" /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" x1="6" x2="6" y1="4.75" y2="7.75" /> <path d="m8.625,10.25h1.164c1.123,0,1.826-1.216,1.265-2.189L7.265,1.484c-.562-.975-1.969-.975-2.53,0L.946,8.061c-.561.973.142,2.189,1.265,2.189h1.164" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" /> </g> </svg> <span className="flex-1"> You must accept the terms to continue </span> </div> </div> </fieldset>
Optional Field
Use the optional prop to explicitly indicate non-mandatory fields. This adds an "Optional" badge to the label.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S4:-helper" id=":S4:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S4:" id=":S4:-label" > Subscribe to our newsletter <span className="inline-flex items-center rounded border border-grayA-4 text-grayA-11 px-1 py-0.5 text-xs font-sans bg-grayA-3 ml-2"> Optional </span> </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":S4:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Get the latest updates directly to your inbox </span> </output> </div> </fieldset>
Success State
Indicates successful validation or acceptance of selection. The success icon and text provide positive feedback.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S5:-helper" color="success" defaultChecked id=":S5:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S5:" id=":S5:-label" > Two-factor authentication enabled </label> </div> </div> <div className="text-[13px] leading-5"> <output className="flex gap-2 items-start text-success-11" id=":S5:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Your account is now more secure </span> </output> </div> </fieldset>
Warning State
Used for potentially impactful selections that should be made with caution. Includes a warning icon and explanatory text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S6:-helper" color="warning" id=":S6:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S6:" id=":S6:-label" > Share usage data with developers </label> </div> </div> <div className="text-[13px] leading-5"> <output className="flex gap-2 items-start text-warning-11" id=":S6:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height="12" size="sm-regular" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="6" cy="10.125" fill="currentColor" r=".875" strokeWidth="0" /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" x1="6" x2="6" y1="4.75" y2="7.75" /> <path d="m8.625,10.25h1.164c1.123,0,1.826-1.216,1.265-2.189L7.265,1.484c-.562-.975-1.969-.975-2.53,0L.946,8.061c-.561.973.142,2.189,1.265,2.189h1.164" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" /> </g> </svg> </div> <span className="flex-1"> This includes anonymous activity information </span> </output> </div> </fieldset>
Error State
Shows validation errors or other issues that need user attention. Features prominent error styling and message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S7:-error" aria-invalid color="danger" id=":S7:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S7:" id=":S7:-label" > Delete my account </label> </div> </div> <div className="text-[13px] leading-5"> <div className="text-error-11 flex gap-2 items-center" id=":S7:-error" role="alert" > <svg aria-hidden="true" className="flex-shrink-0" height="12" size="sm-regular" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="6" cy="10.125" fill="currentColor" r=".875" strokeWidth="0" /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" x1="6" x2="6" y1="4.75" y2="7.75" /> <path d="m8.625,10.25h1.164c1.123,0,1.826-1.216,1.265-2.189L7.265,1.484c-.562-.975-1.969-.975-2.53,0L.946,8.061c-.561.973.142,2.189,1.265,2.189h1.164" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="1.5" /> </g> </svg> <span className="flex-1"> This action cannot be undone </span> </div> </div> </fieldset>
Disabled State
Apply when the field should be non-interactive, such as during form submission or based on other field values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S8:-helper" disabled id=":S8:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S8:" id=":S8:-label" > Admin privileges </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":S8:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Only available to authorized personnel </span> </output> </div> </fieldset>
Checked State
Pre-selected checkbox with an initial checked state that users can toggle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":S9:-helper" defaultChecked id=":S9:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":S9:" id=":S9:-label" > Remember my preferences </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":S9:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Save your settings for future visits </span> </output> </div> </fieldset>
Variants
Outline Variant
A subtler alternative to the primary variant with transparent background when checked.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sa:-helper" id=":Sa:" size="md" variant="outline" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sa:" id=":Sa:-label" > Send me weekly reports </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sa:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> A summary of your account activity </span> </output> </div> </fieldset>
Ghost Variant
The most minimal styling for checkboxes that need less visual emphasis.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sb:-helper" id=":Sb:" size="md" variant="ghost" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sb:" id=":Sb:-label" > Show advanced settings </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sb:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Display additional configuration options </span> </output> </div> </fieldset>
Different Sizes
Checkboxes can be sized appropriately for different UI needs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sc:-helper" id=":Sc:" size="lg" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sc:" id=":Sc:-label" > I confirm that all information is correct </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sc:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Please verify before submission </span> </output> </div> </fieldset>
Complex Usage
Example of FormCheckboxes with multiple props configured for a specific use case, such as a cookie consent form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
<div className="space-y-4"> <fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0 border-b pb-2"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sd:-helper" id=":Sd:" size="md" variant="primary" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sd:" id=":Sd:-label" > Accept all cookies </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sd:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Enable all cookie types for the best experience </span> </output> </div> </fieldset> <div className="pl-6 space-y-2"> <fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Se:-helper" defaultChecked disabled id=":Se:" size="sm" variant="outline" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Se:" id=":Se:-label" > Essential cookies </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Se:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Required for the website to function </span> </output> </div> </fieldset> <fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sf:-helper" id=":Sf:" size="sm" variant="outline" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sf:" id=":Sf:-label" > Performance cookies </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sf:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Help us improve site performance and usability </span> </output> </div> </fieldset> <fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sg:-helper" id=":Sg:" size="sm" variant="outline" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sg:" id=":Sg:-label" > Functional cookies </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sg:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Enable advanced features and personalization </span> </output> </div> </fieldset> <fieldset className="flex flex-col gap-1.5 border-0 m-0 p-0"> <div className="flex items-center gap-3"> <Unknown aria-describedby=":Sh:-helper" id=":Sh:" size="sm" variant="outline" /> <div className="flex flex-col gap-1"> <label className="text-gray-12 text-[13px] leading-5 flex items-center cursor-pointer" htmlFor=":Sh:" id=":Sh:-label" > Marketing cookies </label> </div> </div> <div className="text-[13px] leading-5"> <output className="text-gray-9 flex gap-2 items-start" id=":Sh:-helper" > <div className="size-[14px]"> <svg aria-hidden="true" className="flex-shrink-0 mt-[3px]" height={12} viewBox="0 0 18 18" width={12} xmlns="http://www.w3.org/2000/svg" > <g fill="currentColor"> <circle cx="9" cy="9" fill="none" r="7.25" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} /> <line fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} x1="9" x2="9" y1="12.819" y2="8.25" /> <path d="M9,6.75c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z" fill="currentColor" stroke="none" /> </g> </svg> </div> <span className="flex-1"> Allow us to provide relevant advertisements </span> </output> </div> </fieldset> </div> </div>
Props
The FormCheckbox component extends the standard Checkbox component props with additional form-specific properties:
Prop | Type | Default |
---|---|---|
label | string | - |
description | ReactNode | - |
required | boolean | - |
optional | boolean | - |
error | string | - |
variant | "default" | "primary" | "outline" | "ghost" | - |
color | "default" | "success" | "warning" | "danger" | "info" | - |
size | "sm" | "md" | "lg" | "xlg" | - |
Accessibility
FormCheckbox is built with accessibility in mind:
- Labels are properly associated with checkboxes using htmlFor/id
- Error messages are announced to screen readers using role="alert"
- Required fields are marked both visually and via aria-required
- Helper text is linked to checkboxes using aria-describedby
- Error states are indicated using aria-invalid
- Checkboxes maintain proper focus states for keyboard navigation
Best Practices
When using the FormCheckbox component:
- Always provide clear, concise labels that describe the action being taken
- Use description text to provide additional context about the implications of selection
- Write labels as positive statements (what will happen if checked)
- Keep error messages specific and actionable
- Use required fields sparingly and logically
- Group related checkboxes together with a descriptive heading
- Consider the mobile experience with appropriate touch targets
- Maintain consistent validation patterns across your form
- Test with screen readers and keyboard navigation to ensure accessibility
Layout Guidelines
- Labels should be positioned to the right of the checkbox
- Error messages should appear immediately below the checkbox
- Description text should be helpful but not too lengthy
- Consider using the optional badge for clarity in forms with many fields
- For groups of related checkboxes, consider using a fieldset with legend
- Maintain consistent spacing between multiple checkboxes in a group
- Use appropriate visual hierarchy when nesting checkboxes (e.g., for "select all" patterns)