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="control">
      <input id="track" type="range" min="0" max="100" value="86" />
      <div aria-hidden="true" class="tooltip"></div>
      <label for="track" class="sr-only">Coffee to Milk Ratio</label>
      <div class="control__track">
        <div class="control__indicator"></div>
      </div>
    </div>
        <a class="bear-link" href="https://jhey.dev/links" target="_blank" rel="noreferrer noopener">
      <svg class="w-9" viewBox="0 0 969 955" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="161.191" cy="320.191" r="133.191" stroke="currentColor" stroke-width="20"></circle><circle cx="806.809" cy="320.191" r="133.191" stroke="currentColor" stroke-width="20"></circle><circle cx="695.019" cy="587.733" r="31.4016" fill="currentColor"></circle><circle cx="272.981" cy="587.733" r="31.4016" fill="currentColor"></circle><path d="M564.388 712.083C564.388 743.994 526.035 779.911 483.372 779.911C440.709 779.911 402.356 743.994 402.356 712.083C402.356 680.173 440.709 664.353 483.372 664.353C526.035 664.353 564.388 680.173 564.388 712.083Z" fill="currentColor"></path><rect x="310.42" y="448.31" width="343.468" height="51.4986" fill="#FF1E1E"></rect><path fill-rule="evenodd" clip-rule="evenodd" d="M745.643 288.24C815.368 344.185 854.539 432.623 854.539 511.741H614.938V454.652C614.938 433.113 597.477 415.652 575.938 415.652H388.37C366.831 415.652 349.37 433.113 349.37 454.652V511.741L110.949 511.741C110.949 432.623 150.12 344.185 219.845 288.24C289.57 232.295 384.138 200.865 482.744 200.865C581.35 200.865 675.918 232.295 745.643 288.24Z" fill="currentColor"></path></svg>
    </a>
    <a class="x-link" href="https://twitter.com/intent/follow?screen_name=jh3yy" target="_blank" rel="noreferrer noopener">
      <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>X</title><path d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z" fill="currentColor"/></svg>
    </a>
              
            
!

CSS

              
                @import "normalize.css" layer(https://unpkg.com/normalize.css);

@font-face {
  font-family: "Geist Sans";
  src: url("https://assets.codepen.io/605876/GeistVF.ttf") format("truetype");
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

body {
  display: flex;
  place-items: center;
  min-height: 100vh;
  font-family:  "Geist Sans", "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui;
  background: hsl(0 0% 6%);
}

body::before {
  --line: hsl(0 0% 95% / 0.15);
  content: "";
  height: 100vh;
  width: 100vw;
  position: fixed;
  background:
    linear-gradient(90deg, var(--line) 1px, transparent 1px 10vmin) 0 -5vmin / 10vmin 10vmin,
    linear-gradient(var(--line) 1px, transparent 1px 10vmin) 0 -5vmin / 10vmin 10vmin;
  mask: linear-gradient(-15deg, transparent 30%, white);
  top: 0;
  z-index: -1;
  transform: translate3d(0, 0, -100vmin);
}

@layer foundation {
  .control {
    position: relative;
    display: grid;
    place-items: center;
    margin: 0 auto;
  }

  .sr-only {
  	position: absolute;
		width: 1px;
		height: 1px;
		padding: 0;
		margin: -1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		white-space: nowrap;
		border-width: 0;
  }

  .control:focus-within,
  .control:hover {
    --active: 1;
  }

  [type="range"] {
    width: 300px;
    opacity: 0;
    height: 60px;
  }

  [type="range"]:hover {
    cursor: -webkit-grab;
  }
  [type="range"]:active {
    cursor: -webkit-grabbing;
  }

  [type=range]:focus-visible {
    outline-offset: 0.25rem;
    outline-color: transparent;
  }

  @property --shift {
  	initial-value: 0;
  	inherits: true;
  	syntax: '<integer>';
  }

  .tooltip {
    font-size: 1rem;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    pointer-events: none;
    transform: translateY(calc(var(--shift, 0) * 50%));
    transition: transform var(--speed) var(--timing);
    z-index: 2;
  }
  @keyframes shift {
  	0%, 31%, 61%, 100% { --shift: 0; }
  	32%, 60% { --shift: 1; }
  }

  .tooltip::after,
  .tooltip::before {
    font-variant: tabular-nums;
    position: absolute;
    top: 50%;
    translate: 0 -50%;
    font-weight: bold;
    color: white;
    font-weight: 40;
    font-family: monospace;
  }

  [type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkitappearance: none;
    height: 120px;
    width: 40px;
    margin-top: 0px;
	  opacity: 1;
	}
	[type="range"]::-webkit-slider-runnable-track {
  	-webkit-appearance: none;
	  height: 120px;
	  background: hsl(10 80% 50% / 0.5);
	  margin-top: -60px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
	  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; 
	}
	[type=range]::-moz-range-track {
	  height: 120px;
	  background: hsl(10 80% 50% / 0.5);
	  margin-top: -60px; /* You need to specify a margin in Chrome, but in Firefox and IE it is automatic */
	  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; 
	}
}


@layer scrolls {
  @property --value {
    initial-value: 0;
    syntax: '<integer>';
    inherits: true;
  }

  @keyframes sync {
    to { --value: 100; }
  }

  [type=range] {
    overflow: hidden;
    opacity: 0;
    touch-action: none;
  }

  .control {
    animation: sync both linear reverse, shift both linear;
    animation-timeline: --thumb;
    animation-range: contain;
  }

  .control__track {
  	--coffee: hsl(24 74% calc(24% + (30% * ((100 - var(--value, 0)) / 100)) / 1) / 0.4);
  	--milk: hsl(0 0% 100% / calc(0.1 + (0.4 * ((100 - var(--value, 0)) / 100))));
  	height: calc(50% + (var(--shift) * 50%));
  	width: 100%;
  	position: absolute;
  	bottom: 0;
  	pointer-events: none;
  	transition: height var(--speed) var(--timing);
  }

  .control__track::before {
  	content: "";
  	position: absolute;
  	top: 0;
  	bottom: 0;
  	left: 0;
  	width: calc(var(--value, 0) * 1% - 0.5rem);
  	background: var(--coffee);
  	border-radius: 4px;
  	transition: width var(--update);
  }
  .control__track::after {
  	content: "";
  	position: absolute;
  	top: 0;
  	bottom: 0;
  	right: 0;
  	width: calc((100 - var(--value, 0)) * 1% - 0.5rem);
  	background: var(--milk);
  	border-radius: 4px;
  	transition: width var(--update);
  }
  .control__indicator {
  	height: 75%;
  	border-radius: 4px;
  	width: 4px;
  	position: absolute;
  	top: 50%;
  	background: hsl(0 0% 100% / calc((var(--active, 0) * 0.5) + 0.5));
  	left:calc(var(--value, 0) * 1%);
  	z-index: 2;
  	translate: -50% -50%;
  	transition: left var(--update);
  }

  :root {
    --speed: 0.65s;
    --update: 0s;
    --timing: linear(
	    0, 0.5007 7.21%, 0.7803 12.29%,
	    0.8883 14.93%, 0.9724 17.63%,
	    1.0343 20.44%, 1.0754 23.44%,
	    1.0898 25.22%, 1.0984 27.11%,
	    1.1014 29.15%, 1.0989 31.4%,
	    1.0854 35.23%, 1.0196 48.86%,
	    1.0043 54.06%, 0.9956 59.6%,
	    0.9925 68.11%, 1
	  );
    timeline-scope: --thumb;
  }

  @supports(animation-timeline: scroll()) {
	  :root {
	    --speed: 0.65s;
	    --update: 0.1s;
	    --timing: linear(
		    0, 0.5007 7.21%, 0.7803 12.29%,
		    0.8883 14.93%, 0.9724 17.63%,
		    1.0343 20.44%, 1.0754 23.44%,
		    1.0898 25.22%, 1.0984 27.11%,
		    1.1014 29.15%, 1.0989 31.4%,
		    1.0854 35.23%, 1.0196 48.86%,
		    1.0043 54.06%, 0.9956 59.6%,
		    0.9925 68.11%, 1
		  );
	    timeline-scope: --thumb;
	  }

	  [type="range"]::-webkit-slider-thumb {
	    view-timeline-name: --thumb;
	    view-timeline-axis: inline;
	  }
  }

}


@layer tip {
  
  .tooltip {
    counter-reset: low var(--value) high calc(100 - var(--value));
  }
  
  .tooltip::before {
  	--range: calc((70 - (var(--value) / 100 * 10)) * 1%);
  	color: hsl(24 74% 54%);
    content: "COFFEE " counter(low) "%";
    mask: linear-gradient(90deg, hsl(0 0% 100% / 0.6) var(--range), hsl(0 0% 100% / 1) var(--range));
    left: 0.5rem;

  }
  .tooltip::after {
    --range: calc((50 - (var(--value) / 100 * 10)) * 1%);
    content: counter(high) "% MILK";
    mask: linear-gradient(90deg, hsl(0 0% 100% / 1) var(--range), hsl(0 0% 100% / 0.5) var(--range));
    right: 0.5rem;
  }

}

/* Socials stuff */
.x-link, .bear-link {
	color: hsl(0 0% 100%);
	position: fixed;
	bottom: 1rem;
	left: 1rem;
	width: 48px;
	aspect-ratio: 1;
	display: grid;
	place-items: center;
	opacity: 0.8;
}

.bear-link {
	bottom: unset;
	top: 1rem;
}

:where(.x-link, .bear-link):is(:hover, :focus-visible) {
	opacity: 1;
}
.bear-link svg {
	width: 75%;
}
.x-link svg {
	width: 50%;
}
              
            
!

JS

              
                if (!CSS.supports('animation-timeline: scroll()')) {
  const CONTROL = document.querySelector('.control')
  const TRACK = CONTROL.querySelector('.control__track')
  const LABEL = CONTROL.querySelector('.tooltip')
  const INPUT = document.querySelector('input')
  const update = () => {
    CONTROL.style.setProperty('--value', INPUT.value)
    TRACK.style.setProperty('--shift', INPUT.value > 40 && INPUT.value < 68 ? 1 : 0)
    LABEL.style.setProperty('--shift', INPUT.value > 40 && INPUT.value < 68 ? 1 : 0)
  }
  INPUT.addEventListener('input', update)
  INPUT.addEventListener('pointerdown', update)
  update()
}
              
            
!
999px

Console