Advent

Day 23: Radio button 📱

A radio button component is a form item used when only one selection is possible in a group of mutually exclusive choices.

The example component is visible below.



A few notes about this notification component:

  • CSS Variables are used for colors and spacing,
  • CSS Flexbox is used for layout,
  • the before and after components are used to style the checkbox,
  • the :checked selector is used to determine if the checkbox is checked,
  • the ~ sibling selector is used to target the sibling label,
  • the inline SVG is used to add a custom checkbox.

The code:

<div class="advent-radio">
  <input type="radio" id="radio1" name="radio" checked>
  <label for="radio1">TV 📺</label>
</div>
<div class="advent-radio">
  <input type="radio" id="radio2" name="radio">
  <label for="radio2">Phone 📱</label>
</div>
<div class="advent-radio">
  <input type="radio" id="radio3" name="radio">
  <label for="radio3">Game console 🎮</label>
</div>
.advent-radio {
  --color-xmas-alpha: #f7efef;
  --color-xmas-beta: #d72621;
  --color-xmas-gamma: #639565;
  --size-xmas: 1em;

  position: relative;
  margin-bottom: var(--size-xmas);
  padding: calc(var(--size-xmas) / 6) calc(var(--size-xmas) / 3);
  overflow: hidden;
}

.advent-radio input[type="radio"] {
  position: absolute;
  left: -100vw;
}

.advent-radio label {
  color: var(--color-xmas-beta);
  display: inline-flex;
  align-items: center;
  position: relative;
  cursor: pointer;
}

.advent-radio input[type="radio"]:checked ~ label {
  color: var(--color-xmas-gamma);
}

.advent-radio label:before,
.advent-radio label:after {
  content: "";
  display: inline-block;
  min-height: var(--size-xmas);
  min-width: var(--size-xmas);
}

.advent-radio label:before {
  background-color: var(--color-xmas-alpha);
  box-shadow: 0 0 0 1px currentColor;
  border-radius: 50%;
  margin-right: calc(var(--size-xmas) / 2);
}

.advent-radio label:after {
  background-position: center;
  background-repeat: no-repeat;
  background-size: calc(var(--size-xmas) / 2);
  position: absolute;
  left: 0;
}

.advent-radio input[type="radio"]:checked ~ label:after {
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='-4 -4 8 8'><circle r='3'/></svg>");
}

.advent-radio input[type="radio"]:focus ~ label:before {
  outline: 1px solid currentColor;
  outline-offset: calc(var(--size-xmas) / 4);
}

Advent of UI components 🎄

Check other UI components.

Day 24: Details 🎹

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 24: Details.

Day 22: Checkbox 🧦

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 22: Checkbox.

Day 21: Notification 🤫

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 21: Notification.

Day 20: Code block 💻

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 20: Code block.

Day 19: Pagination 📖

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 19: Pagination.

Day 18: Social share 🔗

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 18: Social share.

Day 17: Card 🎴

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 17: Card.

Day 16: Table 🎶

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 16: Table.

Day 15: Breadcrumb 🍞

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 15: Breadcrumb.

Day 14: Blockquote 💬

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 14: Blockquote.

Day 13: List 🗒️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 13: List.

Day 12: Figure 🖼️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 12: Figure.

Day 11: Video embed 📺

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 11: Video embed.

Day 10: Footer 👇

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 10: Footer.

Day 9: Header ☝️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 9: Header.

Day 8: Hero 🦸‍♂️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 8: Hero.

Day 7: Intro 💬

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 7: Intro.

Day 6: Horizontal rule 〰️

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 6: Horizontal rule.

Day 5: Split 💔

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 5: Split.

Day 4: Banner 🚩

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 4: Banner.

Day 3: Gallery 🍿

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 3: Gallery.

Day 2: Tag 🎁

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 2: Tag.

Day 1: Button 🎅

During every day of the Advent of UI components, I am showcasing a new UI Component built with HTML, CSS, and JavaScript. Day 1: Button.