پیش‌نمایش زنده
کد HTML
<div class="toggle-container" aria-labelledby="notif-title">
  <div class="toggle-title" id="notif-title">Notifications</div>

  <label class="toggle-label">
    <input
      type="checkbox"
      class="toggle-input"
      role="switch"
      aria-label="Push Notifications"
      checked=""
    />
    <div class="toggle-switch" aria-hidden="true">
      <div class="toggle-handle">
        <svg
          class="toggle-icon icon-cross"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <line x1="18" y1="6" x2="6" y2="18"></line>
          <line x1="6" y1="6" x2="18" y2="18"></line>
        </svg>
        <svg
          class="toggle-icon icon-check"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <polyline points="20 6 9 17 4 12"></polyline>
        </svg>
      </div>
    </div>
    <span class="toggle-text">Push Notifications</span>
  </label>

  <label class="toggle-label">
    <input
      type="checkbox"
      class="toggle-input"
      role="switch"
      aria-label="Email Updates"
    />
    <div class="toggle-switch" aria-hidden="true">
      <div class="toggle-handle">
        <svg
          class="toggle-icon icon-cross"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <line x1="18" y1="6" x2="6" y2="18"></line>
          <line x1="6" y1="6" x2="18" y2="18"></line>
        </svg>
        <svg
          class="toggle-icon icon-check"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <polyline points="20 6 9 17 4 12"></polyline>
        </svg>
      </div>
    </div>
    <span class="toggle-text">Email Updates</span>
  </label>

  <label class="toggle-label">
    <input
      type="checkbox"
      class="toggle-input"
      role="switch"
      aria-label="Monthly Newsletter"
      checked=""
    />
    <div class="toggle-switch" aria-hidden="true">
      <div class="toggle-handle">
        <svg
          class="toggle-icon icon-cross"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <line x1="18" y1="6" x2="6" y2="18"></line>
          <line x1="6" y1="6" x2="18" y2="18"></line>
        </svg>
        <svg
          class="toggle-icon icon-check"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <polyline points="20 6 9 17 4 12"></polyline>
        </svg>
      </div>
    </div>
    <span class="toggle-text">Monthly Newsletter</span>
  </label>

  <label class="toggle-label">
    <input
      type="checkbox"
      class="toggle-input"
      role="switch"
      aria-label="Promotional Offers"
    />
    <div class="toggle-switch" aria-hidden="true">
      <div class="toggle-handle">
        <svg
          class="toggle-icon icon-cross"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <line x1="18" y1="6" x2="6" y2="18"></line>
          <line x1="6" y1="6" x2="18" y2="18"></line>
        </svg>
        <svg
          class="toggle-icon icon-check"
          viewBox="0 0 24 24"
          aria-hidden="true"
        >
          <polyline points="20 6 9 17 4 12"></polyline>
        </svg>
      </div>
    </div>
    <span class="toggle-text">Promotional Offers</span>
  </label>
</div>
کد CSS
.toggle-container {
  --bg-top: #ffffff;
  --bg-btm: #182235;
  --bg: #f7f7f7;
  --card: #acb3bf;
  --card-2: #59616c;

  --shadow-dark: #515151;
  --shadow-light: #526d91;

  --primary: #d7f63b;
  --primary-2: #ebdb25;
  --primary-3: #d8b91d;

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --text: #e2e8f0;
  --muted: #a59c9c;
  --muted-2: #242d3b;
  --ring: rgba(59, 130, 246, 0.55);

  --elev-outer-a: 18px 18px 36px var(--shadow-dark);
  --elev-outer-b: -18px -18px 36px rgba(255, 255, 255, 0.08);

  --card-outer-a: 12px 12px 24px rgba(0, 0, 0, 0.5);
  --card-outer-b: -12px -12px 24px rgba(255, 255, 255, 0.06);

  --switch-outer-a: 6px 6px 12px rgba(0, 0, 0, 0.45);
  --switch-outer-b: -6px -6px 12px rgba(255, 255, 255, 0.07);

  --ao-rim: inset 0 0 0.5px 1px rgba(255, 255, 255, 0.04);
  --shadow-ring: 0 0 0 1px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 310px;
  padding: 35px 25px;
  position: relative;

  background: radial-gradient(
      120% 100% at 0% 0%,
      rgba(255, 255, 255, 0.05) 0%,
      transparent 50%
    ),
    linear-gradient(145deg, var(--bg-top), var(--bg-btm));
  box-shadow:
    inset 2px 2px 2px rgba(0, 0, 0, 0.416),
    -2px -2px 2px rgba(255, 255, 255, 0.438) inset;
  border: 2px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: saturate(110%) blur(0.4px);
  overflow: hidden;
}

.toggle-container::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(
      1px 1px at 25% 30%,
      rgba(255, 255, 255, 0.03) 0,
      transparent 60%
    ),
    radial-gradient(1px 1px at 60% 70%, rgba(0, 0, 0, 0.06) 0, transparent 60%);
  background-size:
    140px 140px,
    180px 180px;
  mix-blend-mode: soft-light;
  opacity: 0.35;
}

.toggle-container::before {
  content: "";
  position: absolute;
  inset: 2px 2px auto 2px;
  height: 44px;
  border-radius: 18px 18px 12px 12px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0)
  );
  pointer-events: none;
}

.toggle-title {
  color: gray;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.2px;
  margin-bottom: 14px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  padding: 14px 16px;
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.02),
      rgba(0, 0, 0, 0.06)
    ),
    linear-gradient(145deg, var(--card), var(--card-2));

  border: 1px solid rgba(255, 255, 255, 0.06);
  transition:
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.toggle-label:hover {
  /* transform: translateY(-1px); */
  box-shadow:
    1px 1px 2px rgba(0, 0, 0, 0.21) inset,
    -1px -1px 2px rgba(255, 255, 255, 0.333) inset,
    var(--shadow-ring);
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.toggle-input:focus-visible + .toggle-switch,
.toggle-input:focus-visible ~ .toggle-text {
  outline: 0;
  box-shadow:
    0 0 0 3px var(--ring),
    0 0 0 6px rgba(59, 130, 246, 0.15),
    var(--card-outer-a),
    var(--card-outer-b);
  border-radius: 16px;
}

.toggle-switch {
  width: 56px;
  height: 32px;
  border-radius: 999px;
  position: relative;
  flex-shrink: 0;
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.06),
      rgba(0, 0, 0, 0.08)
    ),
    linear-gradient(145deg, #2b3b58, #192337);
  box-shadow:
    var(--switch-outer-a),
    var(--switch-outer-b),
    inset 0 0 0 rgba(0, 0, 0, 0);
  transition:
    background 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.toggle-switch::before {
  content: "";
  position: absolute;
  inset: 2px 2px auto 2px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.18),
    rgba(255, 255, 255, 0)
  );
}

.toggle-handle {
  width: 24px;
  height: 24px;
  position: absolute;
  top: 4px;
  left: 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(
      120% 120% at 30% 30%,
      rgba(255, 255, 255, 0.85),
      rgba(255, 255, 255, 0.6) 45%,
      rgba(210, 220, 235, 0.4) 60%,
      rgba(140, 150, 170, 0.18) 80%,
      rgba(100, 110, 130, 0.1) 100%
    ),
    linear-gradient(145deg, #cfd8e3, #aeb9c9);
  box-shadow:
    2px 2px 4px rgba(0, 0, 0, 0.35),
    -2px -2px 4px rgba(255, 255, 255, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.65);
  transition:
    transform 0.35s cubic-bezier(0.23, 1, 0.32, 1),
    background 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.toggle-handle::after {
  content: "";
  position: absolute;
  inset: -20% -20%;
  border-radius: 50%;
  background: conic-gradient(
    from 210deg,
    rgba(255, 255, 255, 0) 0 40%,
    rgba(255, 255, 255, 0.5) 55%,
    rgba(255, 255, 255, 0) 70% 100%
  );
  opacity: 0;
  transform: rotate(0deg);
  transition: opacity 0.25s ease;
}

.toggle-icon {
  position: absolute;
  width: 13px;
  height: 13px;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease,
    filter 0.25s ease;
}
.icon-cross {
  stroke: #4f5d75;
  opacity: 1;
  transform: scale(1);
  filter: drop-shadow(0.5px 1px 0 rgba(0, 0, 0, 0.35));
}
.icon-check {
  stroke: #ffffff;
  opacity: 0;
  transform: scale(0.6);
  filter: drop-shadow(0.5px 1px 0 rgba(0, 0, 0, 0.35));
}

.toggle-text {
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0.2px;
  position: relative;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  transition: color 0.35s ease;
}

.toggle-text::after {
  content: "";
  position: absolute;
  left: 0;
  top: 52%;
  height: 2px;
  width: 100%;
  background-color: var(--muted);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s ease;
  opacity: 0.9;
}

.toggle-input:checked + .toggle-switch {
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.1),
      rgba(0, 0, 0, 0.12)
    ),
    linear-gradient(145deg, var(--primary), var(--primary-2));
  box-shadow:
    inset 8px 8px 16px rgba(0, 0, 0, 0.4),
    inset -8px -8px 16px rgba(255, 255, 255, 0.2),
    2px 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-input:checked + .toggle-switch .toggle-handle {
  transform: translateX(24px);
  background: radial-gradient(
      120% 120% at 30% 30%,
      rgba(255, 255, 255, 0.92),
      rgba(255, 255, 255, 0.72) 45%,
      rgba(220, 228, 240, 0.5) 60%,
      rgba(140, 150, 170, 0.22) 80%,
      rgba(100, 110, 130, 0.12) 100%
    ),
    linear-gradient(145deg, #ffffff, #e7eef8);
}

@keyframes sheen-sweep {
  0% {
    transform: rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  60% {
    transform: rotate(340deg);
    opacity: 1;
  }
  100% {
    transform: rotate(420deg);
    opacity: 0;
  }
}
.toggle-input:checked + .toggle-switch .toggle-handle::after {
  animation: sheen-sweep 800ms ease-out 1;
}

.toggle-input:checked + .toggle-switch .icon-cross {
  opacity: 0;
  transform: scale(0.5);
}
.toggle-input:checked + .toggle-switch .icon-check {
  opacity: 1;
  transform: scale(1);
}

.toggle-input:checked ~ .toggle-text {
  color: var(--muted-2);
}
.toggle-input:checked ~ .toggle-text::after {
  transform: scaleX(1);
}

.toggle-label:active {
  transform: translateY(0);
  filter: saturate(1.02);
}

.toggle-label[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
}
.toggle-label.is-danger .toggle-switch {
  background: linear-gradient(145deg, #7f1d1d, #3f0e0e);
}
.toggle-label.is-success .toggle-switch {
  background: linear-gradient(145deg, #065f46, #064e3b);
}

.theme--clay .toggle-label {
  background: linear-gradient(145deg, #243756, #1b2840);
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.45),
    inset 6px 6px 12px rgba(0, 0, 0, 0.3),
    inset -6px -6px 12px rgba(255, 255, 255, 0.1);
  border: none;
}
.theme--clay .toggle-switch {
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.45),
    inset 6px 6px 12px rgba(0, 0, 0, 0.32),
    inset -6px -6px 12px rgba(255, 255, 255, 0.12);
}

.theme--glass {
  background: radial-gradient(
      120% 100% at 0% 0%,
      rgba(255, 255, 255, 0.05) 0%,
      transparent 50%
    ),
    linear-gradient(145deg, rgba(34, 49, 73, 0.55), rgba(24, 34, 53, 0.55));
  backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.theme--glass .toggle-label {
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.06),
      rgba(0, 0, 0, 0.1)
    ),
    rgba(34, 49, 73, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.theme--glass .toggle-switch {
  background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.14),
      rgba(0, 0, 0, 0.12)
    ),
    rgba(43, 59, 88, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

@media (prefers-reduced-motion: reduce) {
  .toggle-label,
  .toggle-switch,
  .toggle-handle,
  .toggle-icon,
  .toggle-text::after,
  .toggle-handle::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    animation: none !important;
  }
}

@media (forced-colors: active) {
  .toggle-container,
  .toggle-label,
  .toggle-switch,
  .toggle-handle {
    box-shadow: none !important;
    background: Canvas !important;
    border: 1px solid ButtonText;
  }
  .toggle-text {
    color: ButtonText !important;
  }
  .toggle-input:focus-visible + .toggle-switch {
    outline: 2px solid Highlight;
  }
}

@media (max-width: 360px) {
  .toggle-container {
    padding: 16px;
    width: 100%;
  }
  .toggle-label {
    gap: 12px;
    padding: 12px 14px;
  }
  .toggle-switch {
    width: 52px;
    height: 28px;
  }
  .toggle-handle {
    width: 20px;
    height: 20px;
  }
  .toggle-title {
    font-size: 20px;
  }
}
نوع: checkbox
تاریخ ایجاد: 2026/06/05
آخرین بروزرسانی: 2026/06/05