# Day and night toggle

> A switch where the sun rolls across a blue sky and becomes a moon on a starry night.

- Category: [Toggles](https://library.aimran.es/components/toggles)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tg-daynight
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A day and night toggle is the friendliest way to offer a dark mode switch. It fits the header of a personal blog, a portfolio or a documentation site where you want the theme choice to have some character. The sun slides over, turns into a grey moon with craters, the sky goes deep blue and three stars appear.

It only changes its own look, so you still need to connect it to your site's light and dark styles. It's a bit wider than a normal switch; give it space in the header instead of squeezing it between menu links.

## Code

### HTML

```html
<label class="uv-dn"><input type="checkbox"><span><i></i><b></b><b></b><b></b></span></label>
```

### CSS

```css
.uv-dn {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-dn {
  display: inline-block;
  font-size: var(--s);
  cursor: pointer;
}

.uv-dn input {
  display: none;
}

.uv-dn span {
  position: relative;
  display: block;
  width: 4.4em;
  height: 2.2em;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(#7dd3fc,#3b82f6);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.2);
  transition: background calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn i {
  position: absolute;
  left: .25em;
  top: .25em;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: #fcd34d;
  box-shadow: 0 0 .8em #fde68a,inset -.15em -.15em 0 #f59e0b;
  transition: all calc(0.6s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-dn b {
  position: absolute;
  width: .18em;
  height: .18em;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  transform: translateY(.6em);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn b:nth-of-type(1) {
  left: .9em;
  top: .5em;
}

.uv-dn b:nth-of-type(2) {
  left: 1.6em;
  top: 1.3em;
  transition-delay: calc(0.1s / var(--k));
}

.uv-dn b:nth-of-type(3) {
  left: 2.1em;
  top: .6em;
  transition-delay: calc(0.2s / var(--k));
}

.uv-dn input:checked+span {
  background: linear-gradient(#0f172a,#312e81);
}

.uv-dn input:checked+span i {
  left: calc(100% - 1.95em);
  background: #e2e8f0;
  box-shadow: 0 0 .6em rgba(226,232,240,.5),inset -.5em -.1em 0 #94a3b8;
}

.uv-dn input:checked+span b {
  opacity: 1;
  transform: none;
}
```

### React

```tsx
import type { CSSProperties } from "react";

const css = `
.uv-dn {
  display: inline-block;
  font-size: var(--s);
  cursor: pointer;
}

.uv-dn input {
  display: none;
}

.uv-dn span {
  position: relative;
  display: block;
  width: 4.4em;
  height: 2.2em;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(#7dd3fc,#3b82f6);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.2);
  transition: background calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn i {
  position: absolute;
  left: .25em;
  top: .25em;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: #fcd34d;
  box-shadow: 0 0 .8em #fde68a,inset -.15em -.15em 0 #f59e0b;
  transition: all calc(0.6s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-dn b {
  position: absolute;
  width: .18em;
  height: .18em;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  transform: translateY(.6em);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn b:nth-of-type(1) {
  left: .9em;
  top: .5em;
}

.uv-dn b:nth-of-type(2) {
  left: 1.6em;
  top: 1.3em;
  transition-delay: calc(0.1s / var(--k));
}

.uv-dn b:nth-of-type(3) {
  left: 2.1em;
  top: .6em;
  transition-delay: calc(0.2s / var(--k));
}

.uv-dn input:checked+span {
  background: linear-gradient(#0f172a,#312e81);
}

.uv-dn input:checked+span i {
  left: calc(100% - 1.95em);
  background: #e2e8f0;
  box-shadow: 0 0 .6em rgba(226,232,240,.5),inset -.5em -.1em 0 #94a3b8;
}

.uv-dn input:checked+span b {
  opacity: 1;
  transform: none;
}
`;

export default function TgDaynight() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-dn"><input type="checkbox" /><span><i></i><b></b><b></b><b></b></span></label>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Day and night toggle” block (Toggles) from AIMRAN Library to my project.

## What it is
A switch where the sun rolls across a blue sky and becomes a moon on a starry night.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import type { CSSProperties } from "react";

const css = `
.uv-dn {
  display: inline-block;
  font-size: var(--s);
  cursor: pointer;
}

.uv-dn input {
  display: none;
}

.uv-dn span {
  position: relative;
  display: block;
  width: 4.4em;
  height: 2.2em;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(#7dd3fc,#3b82f6);
  box-shadow: inset 0 2px 6px rgba(0,0,0,.2);
  transition: background calc(0.6s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn i {
  position: absolute;
  left: .25em;
  top: .25em;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  background: #fcd34d;
  box-shadow: 0 0 .8em #fde68a,inset -.15em -.15em 0 #f59e0b;
  transition: all calc(0.6s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-dn b {
  position: absolute;
  width: .18em;
  height: .18em;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  transform: translateY(.6em);
  transition: all calc(0.5s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-dn b:nth-of-type(1) {
  left: .9em;
  top: .5em;
}

.uv-dn b:nth-of-type(2) {
  left: 1.6em;
  top: 1.3em;
  transition-delay: calc(0.1s / var(--k));
}

.uv-dn b:nth-of-type(3) {
  left: 2.1em;
  top: .6em;
  transition-delay: calc(0.2s / var(--k));
}

.uv-dn input:checked+span {
  background: linear-gradient(#0f172a,#312e81);
}

.uv-dn input:checked+span i {
  left: calc(100% - 1.95em);
  background: #e2e8f0;
  box-shadow: 0 0 .6em rgba(226,232,240,.5),inset -.5em -.1em 0 #94a3b8;
}

.uv-dn input:checked+span b {
  opacity: 1;
  transform: none;
}
`;

export default function TgDaynight() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-dn"><input type="checkbox" /><span><i></i><b></b><b></b><b></b></span></label>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
