Create radio button

User
make radio button like attached
Assistant
Got it 👍 You want your radio button styled like the attached screenshot (a green checkmark inside a light green circle).

Here’s a CSS + HTML example to achieve that look:

<style>
.custom-radio {
  display: none;
}

.custom-radio + label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background-color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.custom-radio:checked + label {
  background-color: #d4fbe3; /* light green background */
  border-color: #28a745; /* green border */
}

.custom-radio:checked + label::after {
  content: "âś”";
  color: #28a745;
  font-size: 16px;
}
</style>

<!-- Example Usage -->
<input type="radio" id="option1" name="example" class="custom-radio">
<label for="option1"></label>

<input type="radio" id="option2" name="example" class="custom-radio">
<label for="option2"></label>

âś… Features:
– Circle shape for the radio
– Green checkmark when selected
– Light green background highlight

Do you want **only the checkmark style** (like your screenshot), or should I also include the **default unselected circle** (like a normal radio button)?

User
we are generating radio button like this
uniquePrices.forEach(({ hours, price }, priceKey) => {
const isNoRush = price.purchase_rush_surcharge === 0 && !noRushMarked;
const displayPrice = (price.purchase_price_incl_vat * amount).toFixed(2);

const label = document.createElement("label");
label.style.display = "block";
label.style.marginBottom = "8px";

label.innerHTML = `

${hours}h – €${displayPrice}
${isNoRush
? `(No Rush)`
: price.purchase_rush_surcharge > 0
? `(+ Rush Fee: €${(price.purchase_rush_surcharge*amount).toFixed(2)})`
: ""}
`;

deliveryOptionsContainer.appendChild(label);

if (isNoRush) noRushMarked = true;
});

Assistant
Nice—here’s a drop‑in way to get that green check-in-circle style with your existing loop.

### 1) CSS

/* Container label */
.delivery-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 8px;
  user-select: none;
}

/* Visually hide the native radio but keep it accessible */
.delivery-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

/* The custom circle */
.delivery-option .radio-ui {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #d0d5dd;             /* light gray border when unchecked */
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, border-color .2s, box-shadow .2s;
}

/* Checkmark */
.delivery-option .radio-ui::after {
  content: "";
  width: 12px;
  height: 6px;
  border-left: 2px solid transparent;
  border-bottom: 2px solid transparent;
  transform: rotate(-45deg);
}

/* Checked state (light green bg + green border + check) */
.delivery-option input[type="radio"]:checked + .radio-ui {
  background: #d4fbe3;                    /* light green */
  border-color: #22c55e;                  /* green */
}
.delivery-option input[type="radio"]:checked + .radio-ui::after {
  border-left-color: #22c55e;
  border-bottom-color: #22c55e;
}

/* Keyboard focus ring */
.delivery-option input[type="radio"]:focus + .radio-ui,
.delivery-option input[type="radio"]:focus-visible + .radio-ui {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, .35);
}

/* Text block */
.delivery-option .delivery-text { line-height: 1.2; }
.delivery-option .delivery-text span { margin-left: 6px; font-size: 0.9em; opacity: 0.8; }

### 2) Update your JS (add a `.radio-ui` span right after the input)

uniquePrices.forEach(({ hours, price }, priceKey) => {
  const isNoRush = price.purchase_rush_surcharge === 0 && !noRushMarked;
  const displayPrice = (price.purchase_price_incl_vat * amount).toFixed(2);

  const label = document.createElement("label");
  label.className = "delivery-option"; // for styling

  label.innerHTML = `
    <input type="radio" name="delivery_time" value="${hours}">
    <span class="radio-ui" aria-hidden="true"></span>
    <span class="delivery-text">
      ${hours}h – €${displayPrice}
      ${
        isNoRush
          ? `<span>(No Rush)</span>`
          : price.purchase_rush_surcharge > 0
          ? `<span>(+ Rush Fee: €${(price.purchase_rush_surcharge * amount).toFixed(2)})</span>`
          : ""
      }
    </span>
  `;

  deliveryOptionsContainer.appendChild(label);

  if (isNoRush) noRushMarked = true;
});

That will render radios exactly like your screenshot: a light green circle with a green checkmark when selected, clean unselected state otherwise, plus proper keyboard focus.

Leave a Comment

Your email address will not be published. Required fields are marked *