09Checkbox đồng ý điều khoản
Chạm vào ô vuông sẽ vẽ dấu check theo từng nét, cùng lúc màu viền thẻ đổi theo dòng chữ 'Tôi đồng ý với điều khoản' bên cạnh.
Dùng choĐồng ý điều khoản dịch vụ và quyền riêng tư ở bước cuối đăng ký, checkbox đồng ý nhận marketing
stroke-dashoffset 드로잉:has(:checked):focus-visible outline

<main class="stage">
<div class="consent-card is-demo">
<label class="consent">
<input class="consent__input" type="checkbox">
<span class="consent__box">
<svg class="consent__svg" viewBox="0 0 20 20" aria-hidden="true">
<path class="consent__check" d="M4 10.5l4 4 8-9" pathLength="1" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
I agree to the Terms and Privacy Policy
</label>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
$duration: $dur-base; // 체크 선이 그려지는 시간
$easing: $ease-out;
$color: $subject-blue; // 체크·테두리 색
@include stage($stage-ink);
.consent-card {
width: min(240px, 88vw);
padding: $sp-4;
border: 1.5px solid #e6e2d8;
border-radius: $r-card;
background: $stage-paper;
transition: border-color $duration $easing;
}
.consent {
display: flex;
align-items: flex-start;
gap: $sp-2;
font-size: 12px;
line-height: 1.5;
color: $stage-ink;
font-family: inherit;
cursor: pointer;
}
.consent__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.consent__box {
flex: 0 0 auto;
width: 20px; height: 20px;
border-radius: $r-xs;
border: 2px solid #c9c2b2;
color: $color;
display: grid;
place-items: center;
transition: border-color $duration $easing;
}
.consent__svg { width: 14px; height: 14px; }
.consent__check {
stroke-dasharray: 1;
stroke-dashoffset: 1;
transition: stroke-dashoffset $duration $easing;
}
.consent__input:checked ~ .consent__box { border-color: $color; }
.consent__input:checked ~ .consent__box .consent__check { stroke-dashoffset: 0; }
.consent__input:focus-visible ~ .consent__box { outline: 2px solid $color; outline-offset: 2px; }
.consent-card:has(.consent__input:checked) { border-color: $color; }
.consent-card.is-demo .consent__box { animation: box-cycle $dur-loop $easing infinite; }
.consent-card.is-demo .consent__check { animation: check-cycle $dur-loop $easing infinite; }
.consent-card.is-demo { animation: card-cycle $dur-loop $easing infinite; }
@keyframes card-cycle {
0%, 20% { border-color: #e6e2d8; }
45%, 100% { border-color: $color; }
}
@keyframes box-cycle {
0%, 20% { border-color: #c9c2b2; }
45%, 100% { border-color: $color; }
}
@keyframes check-cycle {
0%, 20% { stroke-dashoffset: 1; }
45%, 100% { stroke-dashoffset: 0; }
}
@media (prefers-reduced-motion: reduce) {
.consent-card, .consent__box, .consent__check { transition: none; }
.consent-card.is-demo,
.consent-card.is-demo .consent__box,
.consent-card.is-demo .consent__check { animation: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.consent-card {
width: min(240px, 88vw);
padding: 16px;
border: 1.5px solid #e6e2d8;
border-radius: 16px;
background: #ffffff;
transition: border-color 300ms ease-out;
}
.consent {
display: flex;
align-items: flex-start;
gap: 8px;
font-size: 12px;
line-height: 1.5;
color: #17141a;
font-family: inherit;
cursor: pointer;
}
.consent__input {
position: absolute;
opacity: 0;
width: 1px;
height: 1px;
}
.consent__box {
flex: 0 0 auto;
width: 20px;
height: 20px;
border-radius: 4px;
border: 2px solid #c9c2b2;
color: #2f6df6;
display: grid;
place-items: center;
transition: border-color 300ms ease-out;
}
.consent__svg {
width: 14px;
height: 14px;
}
.consent__check {
stroke-dasharray: 1;
stroke-dashoffset: 1;
transition: stroke-dashoffset 300ms ease-out;
}
.consent__input:checked ~ .consent__box {
border-color: #2f6df6;
}
.consent__input:checked ~ .consent__box .consent__check {
stroke-dashoffset: 0;
}
.consent__input:focus-visible ~ .consent__box {
outline: 2px solid #2f6df6;
outline-offset: 2px;
}
.consent-card:has(.consent__input:checked) {
border-color: #2f6df6;
}
.consent-card.is-demo .consent__box {
animation: box-cycle 2s ease-out infinite;
}
.consent-card.is-demo .consent__check {
animation: check-cycle 2s ease-out infinite;
}
.consent-card.is-demo {
animation: card-cycle 2s ease-out infinite;
}
@keyframes card-cycle {
0%, 20% {
border-color: #e6e2d8;
}
45%, 100% {
border-color: #2f6df6;
}
}
@keyframes box-cycle {
0%, 20% {
border-color: #c9c2b2;
}
45%, 100% {
border-color: #2f6df6;
}
}
@keyframes check-cycle {
0%, 20% {
stroke-dashoffset: 1;
}
45%, 100% {
stroke-dashoffset: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.consent-card, .consent__box, .consent__check {
transition: none;
}
.consent-card.is-demo,
.consent-card.is-demo .consent__box,
.consent-card.is-demo .consent__check {
animation: none;
}
}import { useState, type CSSProperties, type ChangeEvent } from "react";
import styles from "./ConsentCheckbox.module.scss";
export type ConsentCheckboxProps = {
label: string;
/** 체크 선이 그려지는 시간 (기본 300ms) */
duration?: number;
easing?: string;
color?: string;
onChange?: (checked: boolean) => void;
};
/** 실제 input[type=checkbox] 을 감춰 쓴다 — 스크린리더·키보드는 그 checkbox 를 그대로 읽고 조작한다 */
export default function ConsentCheckbox({
label,
duration = 300,
easing = "ease-out",
color = "#2f6df6",
onChange,
}: ConsentCheckboxProps) {
const [checked, setChecked] = useState(false);
const style = { "--duration": `${duration}ms`, "--easing": easing, "--color": color } as CSSProperties;
return (
<div className={styles.card} data-checked={checked} style={style}>
<label className={styles.consent}>
<input
className={styles.input}
type="checkbox"
checked={checked}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setChecked(e.target.checked);
onChange?.(e.target.checked);
}}
/>
<span className={styles.box}>
<svg className={styles.svg} viewBox="0 0 20 20" aria-hidden="true">
<path className={styles.check} d="M4 10.5l4 4 8-9" pathLength={1} fill="none" stroke="currentColor" strokeWidth={2.4} strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
{label}
</label>
</div>
);
}09 Checkbox đồng ý điều khoản — Diện tích đo được 0.647% · khung hình chuyển động 7/23Nguyên tác GODRICH · SCSS và React nằm trong tệp zip · 9 mẫu form đăng ký & đăng nhập copy-paste được
Bài viết chứa demo này
9 mẫu form đăng ký & đăng nhập copy-paste đượcMột mẫu form đăng ký tưởng chỉ có ô email, mật khẩu — nhưng là chín quyết định nhỏ: chất liệu thẻ, layout, tiến trình từ Xem tất cả demo trong bài này


