Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


Save Automatically?

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.


                <div class="stage">
  <i class="target" id="raw"></i>
  <span class="label">Raw value</span>
<div class="stage">
  <i class="target" id="interpolated"></i>
  <span class="label">Interpolated value</span>


                body {
  background-color: rgb(2, 62, 80);
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  color: #fff;
  font-size: 14px;

.stage {
  width: 40vw;
  height: 40vw;
  border: 1px solid #fff;
  margin: 1vw;
  position: relative;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='' width='10' height='10'%3E%3Cpath d='M0 0v10h10' stroke='rgba(255,255,255,0.15)' fill='none'/%3E%3C/svg%3E");

.target {
  width: 5%;
  height: 5%;
  background: #fff;
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  transition-property: top, left;
  transition-duration: 200ms;
  transition-timing-function: ease-out;

.label {
  position: absolute;
  bottom: calc(100% + 0.5vw);
  left: 0;
  right: 0;
  text-align: center;


                interface Coordinates {
  lat: number;
  lng: number;

const interpolateCoordinates = (interpolation: number = 0.5): {
  get: () => Coordinates | null;
  set: (newValue: Coordinates) => Coordinates;
} => {
  // Initial states
  let lastValue: Coordinates | null = null;
  let currentValue: Coordinates | null = null;
   * Gets the interpolated coordinates between the last and current values
  const get = (): Coordinates | null => {
    if (!lastValue || !currentValue) return null;
    // Calculate difference in stored values
    const latDiff = ( -;
    const lngDiff = (currentValue.lng - lastValue.lng);
    // Calculate interpolated values
    return {
      lat: + (latDiff * interpolation),
      lng: lastValue.lng + (lngDiff * interpolation),
   * Stores the current interpolation as the last value and updates the current value
  const set = (newValue: Coordinates): Coordinates => {
    // Update last value with current interpolated value if available
    const interpolatedValue = get() ?? newValue;
    lastValue = {...interpolatedValue};
    // Update current value
    currentValue = {...newValue};
    // Return new interpolated value
    return get();
  return {

// Demo
const coordinates = interpolateCoordinates(0.1);

const targetRaw = document.getElementById('raw');
const targetInterpolated = document.getElementById('interpolated');

setInterval(() => {
  // Generate random coordinates
  const newCoordinates: Coordinates = {
    lat: Math.random() * 100,
    lng: Math.random() * 100,
  // Use raw new coordinates = `${}%`; = `${newCoordinates.lng}%`;
  // Interpolate coordinates
  const interpolated = coordinates.set(newCoordinates); = `${}%`; = `${interpolated.lng}%`;
}, 200);