← 全部工具

CSS 切換開關產生器

建立純 CSS 開關,保留原生選取狀態、可見焦點及可調整的動態效果。

css-switch-generator本機處理

正在啟用本機工具…

工具設定

設定只留在本頁。重新載入後會恢復預設值。

功能參考查閱日期 2026-11-21 · ZeroServer

即時預覽與匯出

CSS

.switch-label {
  display: inline-flex;
  gap: 0.6rem;
  align-items: center;
  cursor: pointer;
  min-height: 44px;
}

.custom-switch {
  appearance: none;
  position: relative;
  width: 52px;
  height: 28px;
  margin: 0;
  flex-shrink: 0;
  background: #d1d5db;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
}

.custom-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  background: #ffffff;
  border-radius: 50%;
}

.custom-switch:checked {
  background: #22d3ee;
}

.custom-switch:checked::before {
  inset-inline-start: 27px;
}

.custom-switch:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
  .custom-switch {
    transition: background-color 0.3s;
  }
  
  .custom-switch::before {
    transition: inset-inline-start 0.3s;
  }
}

@media (forced-colors: active) {
  .custom-switch { appearance: auto; }
  .custom-switch::before { content: none; }
}

HTML

<label class="switch-label"><input class="custom-switch" type="checkbox" role="switch"><span>通知</span></label>

如何使用這個工具

選擇預設或修改設定,查看即時預覽,再複製或下載樣式,以及可用的標記。

不適合用在什麼情況

請在實際使用匯出樣式的元件驗證色彩對比、位置及瀏覽器行為。