Home >Web Front-end >CSS Tutorial >How to Style a Checked Radio Button's Label Using CSS?

How to Style a Checked Radio Button's Label Using CSS?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-15 03:42:19336browse

How to Style a Checked Radio Button's Label Using CSS?

How to Style the Label of a Checked Radio Button

Styling the label of a checked radio button using CSS can be achieved through the use of the adjacent sibling combinator ( ).

Problem:

Attempting to style the label of a checked radio button using the "label:checked" selector may not produce the desired result.

Solution:

Employ the adjacent sibling combinator ( ) in the CSS selector to target the label that immediately follows the checked radio button input.

input[type="radio"]:checked+label {
  font-weight: bold;
}

Example Markup:

<input>

This CSS rule will apply the specified style only to the label that is adjacent to a checked radio button input. It is compatible with any HTML structure where the label follows the input, regardless of the presence of additional elements.

The above is the detailed content of How to Style a Checked Radio Button's Label Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn