06:has(:checked)로 JS 0 가격 전환
숨긴 라디오 버튼의 선택 상태를 :has()로 읽어, 자바스크립트 없이도 월간·연간 가격이 자연스럽게 교차 페이드됩니다.
쓰임정적 사이트에 자바스크립트 없이 넣는 결제 주기 전환 가격표
:has():checkedopacity

<main class="stage">
<div class="hc-card is-demo">
<div class="hc-toggle">
<input type="radio" name="hc-period" id="hc-monthly" class="hc-radio hc-radio--m" checked>
<input type="radio" name="hc-period" id="hc-yearly" class="hc-radio hc-radio--y">
<label for="hc-monthly">Monthly</label>
<label for="hc-yearly">Yearly</label>
</div>
<div class="hc-price-stack">
<div class="hc-price hc-price--monthly">$29<span>/mo</span></div>
<div class="hc-price hc-price--yearly">$19<span>/mo</span></div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-base;
$easing: $ease-out;
$color: $subject-blue-deep; // 크림 글자가 얹히므로 진한 파랑
@include stage($stage-yellow);
.hc-card {
width: min(220px, 80vw);
box-sizing: border-box;
border-radius: $r-card;
padding: $sp-5;
background: $subject-ink;
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-4;
}
.hc-toggle {
display: flex;
gap: $sp-2;
}
.hc-radio { position: absolute; opacity: 0; pointer-events: none; }
.hc-toggle label {
padding: $sp-1 $sp-3;
border-radius: $r-pill;
cursor: pointer;
color: $subject-cream;
background: rgba(255, 255, 255, .08);
font: 600 11px/1 -apple-system, "Segoe UI", sans-serif;
transition: background $duration $easing;
}
// 순수 CSS: 숨긴 라디오의 :checked 상태를 :has() 로 읽어 카드 전체에서 판단한다 (JS 0)
.hc-card:has(.hc-radio--m:checked) label[for="hc-monthly"],
.hc-card:has(.hc-radio--y:checked) label[for="hc-yearly"] {
background: $color;
}
.hc-price-stack { position: relative; width: 100%; height: 44px; }
.hc-price {
position: absolute;
inset: 0;
display: flex;
align-items: baseline;
justify-content: center;
gap: $sp-1;
color: $subject-cream;
font: 700 26px/1 -apple-system, "Segoe UI", sans-serif;
opacity: 0;
transform: translateY($sp-2);
transition: opacity $duration $easing, transform $duration $easing;
}
.hc-price span { font-size: 12px; font-weight: 500; opacity: .6; }
.hc-price--monthly { opacity: 1; transform: none; }
.hc-card:has(.hc-radio--y:checked) .hc-price--monthly { opacity: 0; transform: translateY(-#{$sp-2}); }
.hc-card:has(.hc-radio--y:checked) .hc-price--yearly { opacity: 1; transform: none; }
// 데모 루프: 헤드리스는 :has(:checked) 를 못 걸어 is-demo 가 같은 크로스페이드를 keyframes 로 반복한다
@keyframes hc-cross-a {
0%, 40% { opacity: 1; transform: none; }
50%, 90% { opacity: 0; transform: translateY(-#{$sp-2}); }
100% { opacity: 1; transform: none; }
}
@keyframes hc-cross-b {
0%, 40% { opacity: 0; transform: translateY($sp-2); }
50%, 90% { opacity: 1; transform: none; }
100% { opacity: 0; transform: translateY($sp-2); }
}
.hc-card.is-demo .hc-price--monthly { animation: hc-cross-a $duration * 4 $easing infinite; }
.hc-card.is-demo .hc-price--yearly { animation: hc-cross-b $duration * 4 $easing infinite; }
@media (prefers-reduced-motion: reduce) {
.hc-price,
.hc-card.is-demo .hc-price { animation: none !important; transition: none !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.hc-card {
width: min(220px, 80vw);
box-sizing: border-box;
border-radius: 16px;
padding: 20px;
background: #17141a;
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.hc-toggle {
display: flex;
gap: 8px;
}
.hc-radio {
position: absolute;
opacity: 0;
pointer-events: none;
}
.hc-toggle label {
padding: 4px 12px;
border-radius: 999px;
cursor: pointer;
color: #fff7e6;
background: rgba(255, 255, 255, 0.08);
font: 600 11px/1 -apple-system, "Segoe UI", sans-serif;
transition: background 300ms ease-out;
}
.hc-card:has(.hc-radio--m:checked) label[for=hc-monthly],
.hc-card:has(.hc-radio--y:checked) label[for=hc-yearly] {
background: #0a4fe8;
}
.hc-price-stack {
position: relative;
width: 100%;
height: 44px;
}
.hc-price {
position: absolute;
inset: 0;
display: flex;
align-items: baseline;
justify-content: center;
gap: 4px;
color: #fff7e6;
font: 700 26px/1 -apple-system, "Segoe UI", sans-serif;
opacity: 0;
transform: translateY(8px);
transition: opacity 300ms ease-out, transform 300ms ease-out;
}
.hc-price span {
font-size: 12px;
font-weight: 500;
opacity: 0.6;
}
.hc-price--monthly {
opacity: 1;
transform: none;
}
.hc-card:has(.hc-radio--y:checked) .hc-price--monthly {
opacity: 0;
transform: translateY(-8px);
}
.hc-card:has(.hc-radio--y:checked) .hc-price--yearly {
opacity: 1;
transform: none;
}
@keyframes hc-cross-a {
0%, 40% {
opacity: 1;
transform: none;
}
50%, 90% {
opacity: 0;
transform: translateY(-8px);
}
100% {
opacity: 1;
transform: none;
}
}
@keyframes hc-cross-b {
0%, 40% {
opacity: 0;
transform: translateY(8px);
}
50%, 90% {
opacity: 1;
transform: none;
}
100% {
opacity: 0;
transform: translateY(8px);
}
}
.hc-card.is-demo .hc-price--monthly {
animation: hc-cross-a 1200ms ease-out infinite;
}
.hc-card.is-demo .hc-price--yearly {
animation: hc-cross-b 1200ms ease-out infinite;
}
@media (prefers-reduced-motion: reduce) {
.hc-price,
.hc-card.is-demo .hc-price {
animation: none !important;
transition: none !important;
}
}import { CSSProperties } from "react";
import styles from "./PriceSwapHasChecked.module.scss";
export interface PriceSwapHasCheckedProps {
duration?: string;
easing?: string;
monthly?: string;
yearly?: string;
name?: string;
}
// 실사용: 숨긴 라디오 상태를 :has() 로 카드 전체에서 읽는다. 자바스크립트 0.
export default function PriceSwapHasChecked({
duration = "300ms",
easing = "ease-out",
monthly = "$29",
yearly = "$19",
name = "hc-period",
}: PriceSwapHasCheckedProps) {
const style = { "--duration": duration, "--easing": easing } as CSSProperties;
return (
<div className={styles.card} style={style}>
<div className={styles.toggle}>
<input type="radio" name={name} id={`${name}-m`} className={styles.radioM} defaultChecked />
<input type="radio" name={name} id={`${name}-y`} className={styles.radioY} />
<label htmlFor={`${name}-m`}>Monthly</label>
<label htmlFor={`${name}-y`}>Yearly</label>
</div>
<div className={styles.stack}>
<div className={`${styles.price} ${styles.priceMonthly}`}>{monthly}<span>/mo</span></div>
<div className={`${styles.price} ${styles.priceYearly}`}>{yearly}<span>/mo</span></div>
</div>
</div>
);
}06 :has(:checked)로 JS 0 가격 전환 — 측정 누적면적 1.061% · 움직인 프레임 8/23GODRICH 원작 · zip 에 SCSS·React 포함 · CSS 가격표 디자인 애니메이션 9종
이 데모가 속한 글
CSS 가격표 디자인 애니메이션 9종가격표 디자인에 마우스를 올렸을 때 카드가 살짝 떠오르거나 가격 숫자가 휙 바뀌는 걸 본 적 있으신가요? 어떤 요금제를 고를지 망설이는 그 짧은 순간, 이런 작은 움직임 하나가 시선을 붙잡아 줍니다. 이 글은 그런 이 글의 데모 전부 보기


