/Advent

Day 23: Radio ๐Ÿ“ฑ


A radio 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 ๐ŸŽน

A details component contains the summary and the complete information, which could be toggled between visible and hidden states.
Check the component

Day 23: Radio ๐Ÿ“ฑ

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

Day 22: Checkbox ๐Ÿงฆ

A checkbox component is a form item used when multiple selectable objects are in a list.
Check the component

Day 21: Notification ๐Ÿคซ

A notification component usually displays a message that communicates information to the user.
Check the component

Day 20: Code block ๐Ÿ’ป

A code block UI component represents a block of code that is formatted neatly.
Check the component

Day 19: Pagination ๐Ÿ“–

Pagination helps users browse through the sequence of related content.
Check the component

Day 18: Social share ๐Ÿ”—

A social share is a component that displays anchors holding social sharing links of a current page.
Check the component

Day 17: Card ๐ŸŽด

A card component usually displays an image and extra information in card-like format.
Check the component

Day 16: Table ๐ŸŽถ

A table is used to display tabular data.
Check the component

Day 15: Breadcrumb ๐Ÿž

A breadcrumb is an element that helps users understand the hierarchy of the page and site.
Check the component

Day 14: Blockquote ๐Ÿ’ฌ

A blockquote is used to highlight a quote on a page.
Check the component

Day 13: List ๐Ÿ—’๏ธ

An (unordered) list usually consists of items displayed as bullets.
Check the component

Day 12: Figure ๐Ÿ–ผ๏ธ

A figure element represents a graphic asset with an optional caption.
Check the component

Day 11: Video Embed ๐Ÿ“บ

A video embed is a code snippet that allows us to embed the video from a third-party platform like YouTube or Video to our site.
Check the component

Day 10: Footer ๐Ÿ‘‡

A footer is a component that sits at the bottom of every page. It usually consists of navigation and additional information, like website copyright and legal links.
Check the component

Day 9: Header โ˜๏ธ

A header usually consists of navigation that has links to different parts of the website.
Check the component

Day 8: Hero ๐Ÿฆธโ€โ™‚๏ธ

A hero component usually displays the page title, description, and, sometimes, a CTA.
Check the component

Day 7: Intro ๐Ÿ’ฌ

An intro components usually provides basic information of the page. It is one of the first components on the page.
Check the component

Day 6: Horizontal Rule ใ€ฐ๏ธ

A horizontal rule is usually used as a visual divider between two textual elements.
Check the component

Day 5: Split ๐Ÿ’”

A split component consists of two elements, usually image and text, sitting next to each other horizontally.
Check the component

Day 4: Banner ๐Ÿšฉ

A banner is an element that serves to highlight information, like a website page or an event or Advent of UI Components.
Check the component

Day 3: Gallery ๐Ÿฟ

Galleries are an inevitable part of every respected site. Here's a Christmas gallery.
Check the component

Day 2: Tag ๐ŸŽ

Tags often represent information like category, state, or additional information.
Check the component

Day 1: Button ๐ŸŽ…

Let's start with a classic button. Every website needs one, right?
Check the component