Home > Web Front-end > CSS Tutorial > How Can I Style Radio Buttons with CSS?

How Can I Style Radio Buttons with CSS?

Barbara Streisand
Release: 2024-12-22 03:24:13
Original
613 people have browsed it

How Can I Style Radio Buttons with CSS?

Styling Radio Buttons with CSS

Customizing the appearance of radio buttons goes beyond their basic functionality. To modify their styling, including both the shape and the indicator dot, CSS offers several possibilities.

One solution is to use the :after pseudo-class to overlay a custom style on top of the radio button input. By carefully defining the size, position, shape, and colors, developers can create personalized radio buttons.

For instance, the following CSS code modifies the appearance of radio buttons:

input[type='radio']:after {
  width: 15px;
  height: 15px;
  border-radius: 15px;
  top: -2px;
  left: -1px;
  position: relative;
  background-color: #d1d3d1;
  content: '';
  display: inline-block;
  visibility: visible;
  border: 2px solid white;
}

input[type='radio']:checked:after {
  width: 15px;
  height: 15px;
  border-radius: 15px;
  top: -2px;
  left: -1px;
  position: relative;
  background-color: #ffa500;
  content: '';
  display: inline-block;
  visibility: visible;
  border: 2px solid white;
}
Copy after login

Using this code, you can easily apply different colors and shapes to both the radio button shape and the indicator dot, giving your form controls a more refined and customized look.

The above is the detailed content of How Can I Style Radio Buttons with 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