Home >Web Front-end >CSS Tutorial >How Can I Style Checked Radio Button Labels Using Only CSS?

How Can I Style Checked Radio Button Labels Using Only CSS?

Linda Hamilton
Linda HamiltonOriginal
2024-12-24 16:15:18788browse

How Can I Style Checked Radio Button Labels Using Only CSS?

Styling Checked Radio Button Labels

In CSS, it is possible to apply styles to labels associated with checked radio buttons, even without using additional elements like divs.

The Adjacent Sibling Combinator

To target a label that follows a checked radio button input immediately, use the CSS adjacent sibling combinator ( ). This combinator matches labels that are adjacent to and follow a specific element.

Syntax:

input[type="radio"]:checked + label {
  /* Styles */
}

Example:

Consider the following HTML markup:

<input>

Using the adjacent sibling combinator, you can style the label of the checked radio button as follows:

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

Result:

After selecting a radio button, the corresponding label will become bold, indicating its checked state. This technique can be used with various CSS properties to customize the appearance of checked radio buttons.

The above is the detailed content of How Can I Style Checked Radio Button Labels Using Only 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