# Compact date range picker

> A one-month calendar: tap a check-in day and a check-out day, and the nights in between fill in.

- Category: [Filters](https://library.aimran.es/components/filters)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-f-mob-dates
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Made for booking filters on small screens. A rural cottage site, a campsite or a boat rental where guests pick arrival and departure in two taps. The days in between are shaded and the header spells out the range, so there's no doubt about the dates. People search for this as a date range picker or booking calendar in CSS.

The demo shows a single month. For real bookings, add arrows to move between months and grey out days that are already taken. Mark today somehow, even with just a dot, so people get their bearings fast.

## Code

### HTML

```html
<div class="uv-fmd"><div class="ph"><div class="cal"><div class="hd"><b>June</b><span class="out">Choose dates</span></div><div class="wk"><span>L</span><span>M</span><span>X</span><span>J</span><span>V</span><span>S</span><span>D</span></div><div class="gd"><button data-d="1">1</button><button data-d="2">2</button><button data-d="3">3</button><button data-d="4">4</button><button data-d="5">5</button><button data-d="6">6</button><button data-d="7">7</button><button data-d="8">8</button><button data-d="9">9</button><button data-d="10">10</button><button data-d="11">11</button><button data-d="12">12</button><button data-d="13">13</button><button data-d="14">14</button><button data-d="15">15</button><button data-d="16">16</button><button data-d="17">17</button><button data-d="18">18</button><button data-d="19">19</button><button data-d="20">20</button><button data-d="21">21</button><button data-d="22">22</button><button data-d="23">23</button><button data-d="24">24</button><button data-d="25">25</button><button data-d="26">26</button><button data-d="27">27</button><button data-d="28">28</button><button data-d="29">29</button><button data-d="30">30</button></div></div></div></div>
```

### CSS

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

.uv-fmd {
  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;
}

.uv-fmd .ph {
  position: relative;
  width: 16em;
  height: 26em;
  padding: .9em;
  border-radius: 2.2em;
  background: var(--bg);
  box-shadow: 0 0 0 2px color-mix(in srgb,var(--fg) 14%,transparent),0 24px 50px rgba(0,0,0,.18);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.uv-fmd .cal {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .7em;
}

.uv-fmd .hd {
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uv-fmd .hd b {
  font-size: calc(var(--s) * 1.15);
  font-weight: 650;
}

.uv-fmd .hd span {
  font-size: calc(var(--s) * .78);
  color: var(--c1);
  font-weight: 600;
}

.uv-fmd .wk {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
  font-size: calc(var(--s) * .68);
  opacity: .45;
  text-align: center;
}

.uv-fmd .gd {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
}

.uv-fmd .gd button {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: calc(var(--s) * .78);
  border-radius: 50%;
  transition: all calc(0.28s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fmd .gd button:hover {
  background: color-mix(in srgb,var(--fg) 8%,transparent);
}

.uv-fmd .gd button.mid {
  background: color-mix(in srgb,var(--c1) 15%,transparent);
  border-radius: 0;
  color: var(--c1);
}

.uv-fmd .gd button.end {
  color: #fff;
  background: var(--c1);
  animation: uv-fmd calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-fmd {
  0% {
    scale: 1;
  }
  45% {
    scale: 1.3;
  }
  100% {
    scale: 1;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uv-fmd").forEach(el => {
  let a=null,b=null;const bs=[...el.querySelectorAll(".gd button")],out=el.querySelector(".out");const draw=()=>{bs.forEach(x=>{const d=+x.dataset.d;x.className="";if(a&&d===a||b&&d===b)x.classList.add("end");else if(a&&b&&d>Math.min(a,b)&&d<Math.max(a,b))x.classList.add("mid")});out.textContent=a?(b?Math.min(a,b)+" – "+Math.max(a,b)+" jun":a+" jun · elige salida"):"Choose dates"};bs.forEach(x=>x.addEventListener("click",()=>{const d=+x.dataset.d;if(a===null||b!==null){a=d;b=null}else b=d;draw()}));draw()
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-fmd {
  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;
}

.uv-fmd .ph {
  position: relative;
  width: 16em;
  height: 26em;
  padding: .9em;
  border-radius: 2.2em;
  background: var(--bg);
  box-shadow: 0 0 0 2px color-mix(in srgb,var(--fg) 14%,transparent),0 24px 50px rgba(0,0,0,.18);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.uv-fmd .cal {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .7em;
}

.uv-fmd .hd {
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uv-fmd .hd b {
  font-size: calc(var(--s) * 1.15);
  font-weight: 650;
}

.uv-fmd .hd span {
  font-size: calc(var(--s) * .78);
  color: var(--c1);
  font-weight: 600;
}

.uv-fmd .wk {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
  font-size: calc(var(--s) * .68);
  opacity: .45;
  text-align: center;
}

.uv-fmd .gd {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
}

.uv-fmd .gd button {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: calc(var(--s) * .78);
  border-radius: 50%;
  transition: all calc(0.28s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fmd .gd button:hover {
  background: color-mix(in srgb,var(--fg) 8%,transparent);
}

.uv-fmd .gd button.mid {
  background: color-mix(in srgb,var(--c1) 15%,transparent);
  border-radius: 0;
  color: var(--c1);
}

.uv-fmd .gd button.end {
  color: #fff;
  background: var(--c1);
  animation: uv-fmd calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-fmd {
  0% {
    scale: 1;
  }
  45% {
    scale: 1.3;
  }
  100% {
    scale: 1;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  let a=null,b=null;const bs=[...el.querySelectorAll(".gd button")],out=el.querySelector(".out");const draw=()=>{bs.forEach(x=>{const d=+x.dataset.d;x.className="";if(a&&d===a||b&&d===b)x.classList.add("end");else if(a&&b&&d>Math.min(a,b)&&d<Math.max(a,b))x.classList.add("mid")});out.textContent=a?(b?Math.min(a,b)+" – "+Math.max(a,b)+" jun":a+" jun · elige salida"):"Choose dates"};bs.forEach(x=>x.addEventListener("click",()=>{const d=+x.dataset.d;if(a===null||b!==null){a=d;b=null}else b=d;draw()}));draw()
}

export default function FMobDates() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-fmd"><div className="ph"><div className="cal"><div className="hd"><b>June</b><span className="out">Choose dates</span></div><div className="wk"><span>L</span><span>M</span><span>X</span><span>J</span><span>V</span><span>S</span><span>D</span></div><div className="gd"><button data-d="1">1</button><button data-d="2">2</button><button data-d="3">3</button><button data-d="4">4</button><button data-d="5">5</button><button data-d="6">6</button><button data-d="7">7</button><button data-d="8">8</button><button data-d="9">9</button><button data-d="10">10</button><button data-d="11">11</button><button data-d="12">12</button><button data-d="13">13</button><button data-d="14">14</button><button data-d="15">15</button><button data-d="16">16</button><button data-d="17">17</button><button data-d="18">18</button><button data-d="19">19</button><button data-d="20">20</button><button data-d="21">21</button><button data-d="22">22</button><button data-d="23">23</button><button data-d="24">24</button><button data-d="25">25</button><button data-d="26">26</button><button data-d="27">27</button><button data-d="28">28</button><button data-d="29">29</button><button data-d="30">30</button></div></div></div></div>
      </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 “Compact date range picker” block (Filters) from AIMRAN Library to my project.

## What it is
A one-month calendar: tap a check-in day and a check-out day, and the nights in between fill in.

## 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
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-fmd {
  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;
}

.uv-fmd .ph {
  position: relative;
  width: 16em;
  height: 26em;
  padding: .9em;
  border-radius: 2.2em;
  background: var(--bg);
  box-shadow: 0 0 0 2px color-mix(in srgb,var(--fg) 14%,transparent),0 24px 50px rgba(0,0,0,.18);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.uv-fmd .cal {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: .7em;
}

.uv-fmd .hd {
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uv-fmd .hd b {
  font-size: calc(var(--s) * 1.15);
  font-weight: 650;
}

.uv-fmd .hd span {
  font-size: calc(var(--s) * .78);
  color: var(--c1);
  font-weight: 600;
}

.uv-fmd .wk {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
  font-size: calc(var(--s) * .68);
  opacity: .45;
  text-align: center;
}

.uv-fmd .gd {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: .15em;
}

.uv-fmd .gd button {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  font-weight: 550;
  line-height: 1;
  padding: .72em 1.25em;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  position: relative;
  transition: color calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),background calc(0.32s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.32s / var(--k)) cubic-bezier(.34,1.56,.64,1);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: calc(var(--s) * .78);
  border-radius: 50%;
  transition: all calc(0.28s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-fmd .gd button:hover {
  background: color-mix(in srgb,var(--fg) 8%,transparent);
}

.uv-fmd .gd button.mid {
  background: color-mix(in srgb,var(--c1) 15%,transparent);
  border-radius: 0;
  color: var(--c1);
}

.uv-fmd .gd button.end {
  color: #fff;
  background: var(--c1);
  animation: uv-fmd calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

@keyframes uv-fmd {
  0% {
    scale: 1;
  }
  45% {
    scale: 1.3;
  }
  100% {
    scale: 1;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  let a=null,b=null;const bs=[...el.querySelectorAll(".gd button")],out=el.querySelector(".out");const draw=()=>{bs.forEach(x=>{const d=+x.dataset.d;x.className="";if(a&&d===a||b&&d===b)x.classList.add("end");else if(a&&b&&d>Math.min(a,b)&&d<Math.max(a,b))x.classList.add("mid")});out.textContent=a?(b?Math.min(a,b)+" – "+Math.max(a,b)+" jun":a+" jun · elige salida"):"Choose dates"};bs.forEach(x=>x.addEventListener("click",()=>{const d=+x.dataset.d;if(a===null||b!==null){a=d;b=null}else b=d;draw()}));draw()
}

export default function FMobDates() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-fmd"><div className="ph"><div className="cal"><div className="hd"><b>June</b><span className="out">Choose dates</span></div><div className="wk"><span>L</span><span>M</span><span>X</span><span>J</span><span>V</span><span>S</span><span>D</span></div><div className="gd"><button data-d="1">1</button><button data-d="2">2</button><button data-d="3">3</button><button data-d="4">4</button><button data-d="5">5</button><button data-d="6">6</button><button data-d="7">7</button><button data-d="8">8</button><button data-d="9">9</button><button data-d="10">10</button><button data-d="11">11</button><button data-d="12">12</button><button data-d="13">13</button><button data-d="14">14</button><button data-d="15">15</button><button data-d="16">16</button><button data-d="17">17</button><button data-d="18">18</button><button data-d="19">19</button><button data-d="20">20</button><button data-d="21">21</button><button data-d="22">22</button><button data-d="23">23</button><button data-d="24">24</button><button data-d="25">25</button><button data-d="26">26</button><button data-d="27">27</button><button data-d="28">28</button><button data-d="29">29</button><button data-d="30">30</button></div></div></div></div>
      </div>
    </>
  );
}
```

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