# Railway semaphore toggle

> The arm of a railway signal rises to 45 degrees with a mechanical bounce and the lamp turns from red to green.

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

## Where to use it

Old railway lines used semaphore signals, and this switch draws one with a mast, ladder, base and a striped red arm. Turning it on lifts the arm to 45 degrees with a slight overshoot, like a heavy lever settling, and the lamp beside the pivot changes from red to green. It is a clear way to show go and stop in route planners, deploy tools or model railway sites.

The main color is the arm and the stop lamp, the second one the clear lamp. Keep the classic red and green for meaning, or use the brand color for the arm and leave the lamp green.

## Code

### HTML

```html
<label class="uvq03-rsg"><input type="checkbox" role="switch"><span class="sg"><i class="ms"></i><i class="ld"></i><i class="bs"></i><i class="am"></i><i class="pv"></i><i class="lp"></i></span>Line clear</label>
```

### CSS

```css
.uvq03-rsg {
  --c1: #d62b32;
  --c2: #38e07b;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq03-rsg {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-rsg input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-rsg .sg {
  position: relative;
  display: block;
  flex: none;
  width: 3.9em;
  height: 4.7em;
  border-radius: .4em;
}

.uvq03-rsg .sg i {
  position: absolute;
  display: block;
}

.uvq03-rsg .ms {
  left: .86em;
  top: 1.7em;
  bottom: .3em;
  width: .28em;
  border-radius: .12em .12em 0 0;
  background: linear-gradient(90deg,#2a2c30,#62656d 50%,#2a2c30);
}

.uvq03-rsg .ms::before {
  content: "";
  position: absolute;
  left: -.08em;
  top: -.22em;
  width: .44em;
  height: .26em;
  border-radius: 50% 50% .05em .05em;
  background: #2a2c30;
}

.uvq03-rsg .ld {
  left: 1.25em;
  top: 2.95em;
  bottom: .3em;
  width: .3em;
  border-left: .05em solid #4a4d55;
  border-right: .05em solid #4a4d55;
  background: repeating-linear-gradient(180deg,#4a4d55 0 .06em,transparent .06em .3em);
}

.uvq03-rsg .bs {
  left: .35em;
  bottom: 0;
  width: 1.6em;
  height: .32em;
  border-radius: .1em;
  background: #3a3c42;
}

.uvq03-rsg .am {
  left: 1em;
  top: 2.11em;
  box-sizing: border-box;
  width: 2.65em;
  height: .48em;
  border: .05em solid #1d1e21;
  border-radius: .06em .2em .2em .06em;
  background: linear-gradient(90deg,var(--c1) 0 64%,#fff 64% 78%,var(--c1) 78%);
  box-shadow: 0 .1em .2em rgba(0,0,0,.35);
  transform-origin: 0 50%;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.4,1.7,.5,1);
}

.uvq03-rsg .pv {
  left: .82em;
  top: 2.17em;
  width: .36em;
  height: .36em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,#c9cbd0,#3a3c42);
}

.uvq03-rsg .lp {
  left: .12em;
  top: 2.05em;
  width: .56em;
  height: .56em;
  border-radius: 50%;
  background: var(--c1);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .6em .1em var(--c1);
  transition: background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k)),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k));
}

.uvq03-rsg:hover input:not(:checked) + .sg .am {
  transform: rotate(-6deg);
}

.uvq03-rsg:active .sg {
  scale: .97;
}

.uvq03-rsg input:checked + .sg .am {
  transform: rotate(-45deg);
}

.uvq03-rsg input:checked + .sg .lp {
  background: var(--c2);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .7em .15em var(--c2);
}

.uvq03-rsg input:focus-visible + .sg {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-rsg,.uvq03-rsg *,.uvq03-rsg *::before,.uvq03-rsg *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### React

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

const css = `
.uvq03-rsg {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-rsg input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-rsg .sg {
  position: relative;
  display: block;
  flex: none;
  width: 3.9em;
  height: 4.7em;
  border-radius: .4em;
}

.uvq03-rsg .sg i {
  position: absolute;
  display: block;
}

.uvq03-rsg .ms {
  left: .86em;
  top: 1.7em;
  bottom: .3em;
  width: .28em;
  border-radius: .12em .12em 0 0;
  background: linear-gradient(90deg,#2a2c30,#62656d 50%,#2a2c30);
}

.uvq03-rsg .ms::before {
  content: "";
  position: absolute;
  left: -.08em;
  top: -.22em;
  width: .44em;
  height: .26em;
  border-radius: 50% 50% .05em .05em;
  background: #2a2c30;
}

.uvq03-rsg .ld {
  left: 1.25em;
  top: 2.95em;
  bottom: .3em;
  width: .3em;
  border-left: .05em solid #4a4d55;
  border-right: .05em solid #4a4d55;
  background: repeating-linear-gradient(180deg,#4a4d55 0 .06em,transparent .06em .3em);
}

.uvq03-rsg .bs {
  left: .35em;
  bottom: 0;
  width: 1.6em;
  height: .32em;
  border-radius: .1em;
  background: #3a3c42;
}

.uvq03-rsg .am {
  left: 1em;
  top: 2.11em;
  box-sizing: border-box;
  width: 2.65em;
  height: .48em;
  border: .05em solid #1d1e21;
  border-radius: .06em .2em .2em .06em;
  background: linear-gradient(90deg,var(--c1) 0 64%,#fff 64% 78%,var(--c1) 78%);
  box-shadow: 0 .1em .2em rgba(0,0,0,.35);
  transform-origin: 0 50%;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.4,1.7,.5,1);
}

.uvq03-rsg .pv {
  left: .82em;
  top: 2.17em;
  width: .36em;
  height: .36em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,#c9cbd0,#3a3c42);
}

.uvq03-rsg .lp {
  left: .12em;
  top: 2.05em;
  width: .56em;
  height: .56em;
  border-radius: 50%;
  background: var(--c1);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .6em .1em var(--c1);
  transition: background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k)),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k));
}

.uvq03-rsg:hover input:not(:checked) + .sg .am {
  transform: rotate(-6deg);
}

.uvq03-rsg:active .sg {
  scale: .97;
}

.uvq03-rsg input:checked + .sg .am {
  transform: rotate(-45deg);
}

.uvq03-rsg input:checked + .sg .lp {
  background: var(--c2);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .7em .15em var(--c2);
}

.uvq03-rsg input:focus-visible + .sg {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-rsg,.uvq03-rsg *,.uvq03-rsg *::before,.uvq03-rsg *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

export default function TgRailSignal() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#d62b32",
          "--c2": "#38e07b",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-rsg"><input type="checkbox" role="switch" /><span className="sg"><i className="ms"></i><i className="ld"></i><i className="bs"></i><i className="am"></i><i className="pv"></i><i className="lp"></i></span>Line clear</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 “Railway semaphore toggle” block (Toggles) from AIMRAN Library to my project.

## What it is
The arm of a railway signal rises to 45 degrees with a mechanical bounce and the lamp turns from red to green.

## Chosen settings
- Main color: #d62b32
- Secondary color: #38e07b
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Vía libre"

## 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 = `
.uvq03-rsg {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-rsg input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-rsg .sg {
  position: relative;
  display: block;
  flex: none;
  width: 3.9em;
  height: 4.7em;
  border-radius: .4em;
}

.uvq03-rsg .sg i {
  position: absolute;
  display: block;
}

.uvq03-rsg .ms {
  left: .86em;
  top: 1.7em;
  bottom: .3em;
  width: .28em;
  border-radius: .12em .12em 0 0;
  background: linear-gradient(90deg,#2a2c30,#62656d 50%,#2a2c30);
}

.uvq03-rsg .ms::before {
  content: "";
  position: absolute;
  left: -.08em;
  top: -.22em;
  width: .44em;
  height: .26em;
  border-radius: 50% 50% .05em .05em;
  background: #2a2c30;
}

.uvq03-rsg .ld {
  left: 1.25em;
  top: 2.95em;
  bottom: .3em;
  width: .3em;
  border-left: .05em solid #4a4d55;
  border-right: .05em solid #4a4d55;
  background: repeating-linear-gradient(180deg,#4a4d55 0 .06em,transparent .06em .3em);
}

.uvq03-rsg .bs {
  left: .35em;
  bottom: 0;
  width: 1.6em;
  height: .32em;
  border-radius: .1em;
  background: #3a3c42;
}

.uvq03-rsg .am {
  left: 1em;
  top: 2.11em;
  box-sizing: border-box;
  width: 2.65em;
  height: .48em;
  border: .05em solid #1d1e21;
  border-radius: .06em .2em .2em .06em;
  background: linear-gradient(90deg,var(--c1) 0 64%,#fff 64% 78%,var(--c1) 78%);
  box-shadow: 0 .1em .2em rgba(0,0,0,.35);
  transform-origin: 0 50%;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.4,1.7,.5,1);
}

.uvq03-rsg .pv {
  left: .82em;
  top: 2.17em;
  width: .36em;
  height: .36em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%,#c9cbd0,#3a3c42);
}

.uvq03-rsg .lp {
  left: .12em;
  top: 2.05em;
  width: .56em;
  height: .56em;
  border-radius: 50%;
  background: var(--c1);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .6em .1em var(--c1);
  transition: background calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k)),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1) calc(0.2s / var(--k));
}

.uvq03-rsg:hover input:not(:checked) + .sg .am {
  transform: rotate(-6deg);
}

.uvq03-rsg:active .sg {
  scale: .97;
}

.uvq03-rsg input:checked + .sg .am {
  transform: rotate(-45deg);
}

.uvq03-rsg input:checked + .sg .lp {
  background: var(--c2);
  box-shadow: 0 0 0 .1em #1d1e21,0 0 .7em .15em var(--c2);
}

.uvq03-rsg input:focus-visible + .sg {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-rsg,.uvq03-rsg *,.uvq03-rsg *::before,.uvq03-rsg *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

export default function TgRailSignal() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#d62b32",
          "--c2": "#38e07b",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-rsg"><input type="checkbox" role="switch" /><span className="sg"><i className="ms"></i><i className="ld"></i><i className="bs"></i><i className="am"></i><i className="pv"></i><i className="lp"></i></span>Line clear</label>
      </div>
    </>
  );
}
```

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