Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <a href="" target="_blank" data-keyframers-credit style="color: #000"></a>
<script src=""></script>

<div class="calendar">
  <div class="day" data-day="1"><span class="number">1</span></div>
  <div class="day" data-day="2"><span class="number">2</span></div>
  <div class="day" data-day="3"><span class="number">3</span></div>
  <div class="day" data-day="4"><span class="number">4</span></div>
  <div class="day" data-day="5"><span class="number">5</span></div>
  <div class="day" data-day="6"><span class="number">6</span></div>
  <div class="day" data-day="7"><span class="number">7</span></div>
  <div class="day" data-day="8"><span class="number">8</span></div>
  <div class="day" data-day="9"><span class="number">9</span></div>
  <div class="day" data-day="10"><span class="number">10</span></div>
  <div class="day" data-day="11"><span class="number">11</span></div>
  <div class="day" data-day="12"><span class="number">12</span></div>
  <div class="day" data-day="13" data-selected="start"><span class="number" >13</span></div>
  <div class="day" data-day="14"><span class="number">14</span></div>
  <div class="day" data-day="15"><span class="number">15</span></div>
  <div class="day" data-day="16"><span class="number">16</span></div>
  <div class="day" data-day="17"><span class="number">17</span></div>
  <div class="day" data-day="18"><span class="number">18</span></div>
  <div class="day" data-day="19"><span class="number">19</span></div>
  <div class="day" data-day="20"><span class="number">20</span></div>
  <div class="day" data-day="21"><span class="number">21</span></div>
  <div class="day" data-day="22"><span class="number">22</span></div>
  <div class="day" data-day="23" data-selected="end"><span class="number" >23</span></div>
  <div class="day" data-day="24"><span class="number">24</span></div>
  <div class="day" data-day="25"><span class="number">25</span></div>
  <div class="day" data-day="26"><span class="number">26</span></div>
  <div class="day" data-day="27"><span class="number">27</span></div>
  <div class="day" data-day="28"><span class="number">28</span></div>
  <div class="day" data-day="29"><span class="number">29</span></div>
  <div class="day" data-day="30"><span class="number">30</span></div>
  <div class="day" data-day="31"><span class="number">31</span></div>


*::after {
  position: relative;
  box-sizing: border-box;

html { 
  height: 100%; 
  display: flex; 
  background: #eee;
body { margin: auto; }

:root {
  --color-primary: #00AEF2;

.calendar {
  font-size: 3vw;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-gap: 0.25em 0;
  margin: auto;
  padding: 1em;
  background: #FFF;
  box-shadow: 0 1em 2em hsla(0, 0%, 0%, .25);
  border-radius: .5em;
  user-select: none;

.day:first-child {
  grid-column-start: 4; 

.day {
  padding: 0.5em;
  text-align: center;
  &::before {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    margin: auto; 
  &[data-selected]::before {
    border-radius: .5em;
  &[data-selected="start"]::before {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  &[data-selected] ~ .day {
    color: white;
  &[data-selected] ~ .day::before {
    background-color: var(--color-primary);
  &[data-selected="start"] ~ .day:not([data-selected="end"])::before {
    opacity: 0.5;
  // Specificity override 
  &[data-selected="end"][data-selected="end"]::before {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  &[data-selected="end"] ~ .day { 
    color: inherit;
  &[data-selected="end"] ~ .day::before {
    background-color: transparent;



// idle
// -> onPointerDown
// dragging
// -> onPointerMove / onPointerOver
// <- onPointerUp

/* NOTE: We retooled the data to be based on first selection and second selection. We'll calculate which is the start & end date later in the `updateDOM` function. */
const data = {
  firstDate: null,
  secondDate: null

const machine = {
  initial: 'idle',
  states: {
    idle: {
      on: {
        pointerdown: (data, event) => {
          data.firstDate =;
          data.secondDate = null;
          return 'dragging';
    dragging: {
      on: {
        pointerover: (data, event) => {
          data.secondDate =;
          return 'dragging';
        pointerup: 'idle',
        pointercancel: 'idle'

// idle
let currentState = machine.initial;

function send(event) {
  const transition = machine

  if (typeof transition === 'function') {
    currentState = transition(data, event);
  } else if (transition) {
    currentState = transition;

/* ---------------------------------- */

const allDayEls = document.querySelectorAll('[data-day]');

allDayEls.forEach(dayEl => {
  dayEl.addEventListener('pointerdown', send);
  dayEl.addEventListener('pointerover', send);

document.body.addEventListener('pointerup', send);

/* ---------------------------------- */

function updateDOM(){
    .forEach(el => {
      delete el.dataset.selected
  const startDate = Math.min(data.firstDate, data.secondDate);
  const endDate = Math.max(data.firstDate, data.secondDate);
  if ( startDate ) {
    const startDateEl = document.querySelector(`[data-day="${startDate}"]`);
    startDateEl.dataset.selected = "start";
  if ( endDate ) {
    const endDateEl = document.querySelector(`[data-day="${endDate}"]`);
    endDateEl.dataset.selected = "end";