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
Release: 2024-12-15 03:42:19
Original
329 people have browsed it

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;
}
Copy after login

Example Markup:

<input>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template