Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <div class="info">
  <div class="info__scroll">
    <label for="scroll-height">
      <i class="bi bi-arrow-down-up"></i>
      <input name="scroll-height" type="text" id="scroll-height" disabled>
    </label>
    <label for="scroll-top">
      <i class="bi bi-arrow-bar-down"></i>
      <input name="scroll-top" type="text" id="scroll-top" disabled>
    </label>
  </div>
  <div class="info__win-state">
    <label for="win-state">
      <i class="bi bi-broadcast"></i>
      <input name="win-state" type="text" id="win-state" disabled>
    </label>
    <label for="coord-client">
      <i class="bi bi-mouse2"></i>
      <input name="coord-client" type="text" id="coord-client" disabled>
    </label>
    <label for="coord-page">
      <i class="bi bi-arrow-bar-up"></i>
      <input name="coord-page" type="text" id="coord-page" disabled>
    </label>
  </div>
  <div class="info__client-size">
    <label for="client-size">
      <i class="bi bi-aspect-ratio"></i>
      <input name="client-size" type="text" id="client-size" disabled>
    </label>
  </div>
</div>

<div id="ruler">
  <template>
    <div class="ruler">
      <div class="unit"></div>
      <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </template>
</div>

<div id="click-target">
  <template>
    <div class="click" style="--size: 1.5rem; --x: 0; --y: 0">
      
    </div>
  </template>
</div>
              
            
!

CSS

              
                :root {
  --camel: #f5e4bc;
  --camel-rgb: 245,228,188;
  --camel-dark: #f2dba6;
  --camel-dark-rgb: 242,219,166;
  --camel-darker: #ecc979;
  --camel-darker-rgb: 236,201,121;
  --camel-light: #f9edd2;
  --camel-light-rgb: 249,237,210;
  --brown: #292823;
  --brown-rgb: 41,40,35;
  --brown-dark: #0e0d0c;
  --brown-dark-rgb: 14,13,12;
  --brown-light: #45433b;
  --brown-light-rgb: 69,67,59;
  --accent: hotpink;
  --scrollY: 0;
  --blur: 0;
  --client-x: 0;
  --client-y: 0;
}

// scrollbar styles
::-webkit-scrollbar {
  width: 8px;
  height: 5px;
}
::-webkit-scrollbar-thumb {
  background: var(--brown);
  border-radius: 5px;
}
::-webkit-scrollbar-track-piece {
  background-color: var(--camel);
}

body {
  position: relative;
  font-family: monospace;
  font-size: 1.5rem;
  color: var(--brown);
  background-color: var(--camel);
  //background-image: linear-gradient(180deg, rgba(255,255,255,.5) 0%, rgba(255,255,255,0) 100%);
  //background-blend-mode: overlay;
  background-attachment: fixed;
}

 input {
   width: 100%;
   border: 0;
   color: unset;
   background: unset;
   text-align: center;
   font-size: 85%;
}

@mixin unit($color, $width, $height) {
  position: relative;
  &::before {
      content: "";
      position: absolute;
      top: 0;
      height: $height;
      width: $width;
      background: $color;
    }
    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      height: $height;
      width: $width;
      background: $color;
    }
}

.ruler {
  position: relative;
  .unit {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    bottom: .5rem;
    left: 2rem;
    font-size: 0.8rem;
    color: var(--brown-light);
  }
  ul {
    height: 100px;
    @include unit(var(--accent), 2.5rem, 1px);
    &::before {
      z-index: 1;
    }
    li {
      position: above;
      height: 10px;
      @include unit(#b59d6e, 1.5rem, 1px);
      &:nth-child(2n) {
        background: rgb(255 255 255 / .18)
      }
      &:hover {
        background: var(--camel-dark)
      }
    }
  }
}

.info {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-flow: column;
  
  label {
    position: relative;
    display: flex;
    gap: .5rem;
  }

  [class^='info__'] {
    width: 185px;
    background: var(--camel-dark);
    border-radius: 5px;
    box-shadow: 0px 1px 0 0 var(--camel-dark), 2px 2px 8px -2px rgb(0 0 0 / 30%);
    //border: 1px solid var(--camel-dark);
    padding: 0.5rem 1rem;
    display: flex;
    flex-flow: row wrap;
    gap: 1rem;
  }
}

.mouse {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  top: calc(1px * var(--client-y) + 15px);
  left:  calc(1px * var(--client-x) + 5px);
  transition: top 0.3s linear, left 0.3s linear;
  width: 90px;
  height: 90px;
  background: var(--camel-dark);
  box-shadow: 4px 4px 4px -2px rgb(0 0 0 / 30%);
  border-radius: 50%;
  
  & * { cursor: none !important; }
  
  .mouse__coord {
    display: flex;
    flex-flow: column;
    height: 100%;
    justify-content: center;
    align-items: center;
    font-size: .8rem;
    
  }
}

#click-target {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  .click {
    position: absolute;
    top: calc(1px * var(--y) - var(--size) / 2);
    left: calc(1px * var(--x) - var(--size) / 2);
    font-size: var(--size);
  }
}
              
            
!

JS

              
                const win = window
const root = document.documentElement;


/**
 * build ruler
 */
const ruler = document.getElementById('ruler')
const rulerTmp = ruler.querySelector('template')

for(let i = 0; i < 18; i++) {
  const clone = rulerTmp.content.cloneNode(true)
  const unit = clone.querySelector('.unit')
  unit.innerText = `${(i+1)*100}px`
  ruler.appendChild(clone)
}


/**
 * mouse click event
 */
const clickTarget = document.getElementById('click-target')
const clickTargetTmp = clickTarget.querySelector('template')
win.onclick = _.debounce(clickHandler, 100);

function clickHandler(e) {
  const clone = clickTargetTmp.content.cloneNode(true)
  const click = clone.querySelector('.click')
  const emojis = ['😎','🥸','🤩','🥳','😏','🤮']
  click.style.setProperty("--x", e.pageX)
  click.style.setProperty("--y", e.pageY)
  click.innerText = emojis[Math.floor(Math.random() * emojis.length)]
  
  clickTarget.appendChild(clone)
}


/**
 * resize event
 */
const inputClientSize = document.getElementById('client-size')
win.onresize = _.debounce(resizeHandler, 300);

function resizeHandler() {
  inputClientSize.value =`${root.clientWidth}px x ${root.clientHeight}px`
}
 

/**
 * scroll event
 */
const inputScrollHeight = document.getElementById('scroll-height')
const inputScrollTop = document.getElementById('scroll-top')
win.onscroll = _.throttle(scrollHandler, 300);

function scrollHandler(e) {
  inputScrollHeight.value =`${root.scrollHeight}px`
  inputScrollTop.value =`${root.scrollTop}px`
}


/**
 * document events
 */
const inputWinState = document.getElementById('win-state')
win.onload = ()=>winStateHandler('loaded')
win.onfocus = ()=>winStateHandler('focus')
win.onblur = ()=>winStateHandler('blur')

function winStateHandler(state) {
  inputWinState.value = state
}


/**
 * mouse move
 */
const inputCoordClient = document.getElementById('coord-client')
const inputCoordPage = document.getElementById('coord-page')
win.onmousemove = _.throttle(mouseMoveHandler, 200)

function mouseMoveHandler(e) {
  const clientX = e.clientX
  const clientY = e.clientY
  const pageX = e.pageX
  const pageY = e.pageY
  
  inputCoordClient.value = `${clientX}px / ${clientY}px`
  inputCoordPage.value = `${pageY}px`
  
  //root.style.setProperty("--client-x", clientX)
  //root.style.setProperty("--client-y", clientY)
}


/**
 * init
 */
scrollHandler()
resizeHandler()
              
            
!
999px

Console