forms

Tailwind CSS Radio

The radio component allows users to select one option from multiple choices. It comes in various styles, variants, and colors.

Class Name
Type
Description
radioComponentComponent class for radio.
custom-optionComponentFor custom option container.
custom-soft-optionComponentFor custom option container with background.
label-textPartBase class for title label text.
helper-textPartBase class for helper label text.
radio-insetStyleTargets radio input.
radio-primaryColorAdds ‘primary’ color to radio.
radio-secondaryColorAdds ‘secondary’ color to radio.
radio-accentColorAdds ‘accent’ color to radio.
radio-infoColorAdds ‘info’ color to radio.
radio-successColorAdds ‘success’ color to radio.
radio-warningColorAdds ‘warning’ color to radio.
radio-errorColorAdds ’error’ color to radio.
is-validStateAdds success style to the input.
is-invalidStateAdds error style to the input.
radio-xsSizeradio with extra small size.
radio-smSizeradio with small size.
radio-mdSizeradio with medium(default) size.
radio-lgSizeradio with large size.
radio-xlSizeradio with extra large size.

Basic radio example.

Please use label-text for the label and helper-text for the text that appears at the bottom as helper text.

Apply the radio class to style radio buttons.

Use radio-inset alongside radio to create an inset radio.

Example of semantic color in default and inset radio.

Add color to the radio button by utilizing the radio-{semantic-color} class in conjunction with the radio class.

Use the radio-{semantic-color} class in combination with the radio-inset class.

Example of custom color in default and custom radio.

Got it! Here’s the rephrased explanation:

To create a custom radio button, you can use checked:text-*, but you’ll need to apply the checked: modifier. Alternatively, you can use --input-color, which automatically applies the color when the radio button is checked, without needing the checked: modifier.

Custom inset radio.

Add responsive class radio-{size} where {size} = xs|sm|md|lg|xl for radio of different sizes.

Add responsive class radio-{size} where {size} = xs|sm|md|lg|xl for radio inset of different sizes.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

Disable the radio component to prevent user selection by applying the disabled attribute.

A group of radio components.

A vertical group of radio components.

Here’s an example of a radio in dropdown that you can use right away.

Below given example can be used to show a list of radio buttons inside a grouped list.

Use below example to group up radio button components inside a list.

Create a radio button group using the join and btn component classes.

Utilizing the custom-option class within the label enables the creation of custom radio buttons with improved styling and functionality.

Utilize the hidden TailwindCSS utility class to conceal the radio button.

Utilizing the custom-soft-option class within the label demonstrates this distinctive styling approach, where the label background becomes primary when checked.

Customize the styling using utility classes according to your custom preferences, as illustrated below.

This example displays an image as a radio button.