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

              
                <svg xmlns="http://www.w3.org/2000/svg" id="label" viewBox="0 0 138 26" fill="none" stroke="#26de81" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round">
  <path d="M80 6h-9v14h9 M114 6h-9 v14h9 M111 13h-6 M77 13h-6 M122 20V6l11 14V6 M22 16.7L33 24l11-7.3V9.3L33 2L22 9.3V16.7z M44 16.7L33 9.3l-11 7.4 M22 9.3l11 7.3 l11-7.3 M33 2v7.3 M33 16.7V24 M88 14h6c2.2 0 4-1.8 4-4s-1.8-4-4-4h-6v14 M15 8c-1.3-1.3-3-2-5-2c-4 0-7 3-7 7s3 7 7 7 c2 0 3.7-0.8 5-2 M64 13c0 4-3 7-7 7h-5V6h5C61 6 64 9 64 13z"/>
</svg>
              
            
!

CSS

              
                body {
  width: 100vw;
  height: 100vh;
	background-color: #0f0f13;
	overflow: hidden;
  position: relative;
}

#label {
	position: absolute;
  left: calc(50vw - 150px);
  top: calc(50vh - 28px);
	width: 300px;
	height: 56px;
}
              
            
!

JS

              
                const body = document.querySelector('body')
const label = document.querySelector('#label')

let colors = [ '#26de81', '#fc5c65', '#fd9644', '#fed330', '#2bcbba', '#45aaf2', '#4b7bec', '#a55eea', '#ffc1f3', '#76ead7', '#ff9c71', '#32e0c4', '#d291bc', '#fa744f' ]

let FPS = 60

let width
  , height
  , velocityX = 1
  , velocityY = 1
  , pause = true
  , previousColor = 0
;

setInterval(() => {
	if (pause) return;

	let rect = label.getBoundingClientRect()

	let left = rect.x
	let top = rect.y

	if (left + rect.width >= width || left <= 0) {
		velocityX = -velocityX
    let randomColor = getRandomColor()
		label.style.stroke = randomColor
    
    if (left + 150 <= width / 2) {
      body.style.boxShadow = `inset 4px 0px 0px 0px ${randomColor}`
    } else {
      body.style.boxShadow = `inset -4px 0px 0px 0px ${randomColor}`
    }
	}
	if (top + rect.height >= height || top <= 0) {
		velocityY = -velocityY
    let randomColor = getRandomColor()
		label.style.stroke = randomColor
    
    if (top + 28 <= height / 2) {
      body.style.boxShadow = `inset 0px 4px 0px 0px ${randomColor}`
    } else {
      body.style.boxShadow = `inset 0px -4px 0px 0px ${randomColor}`
    }
	}

	label.style.left = rect.x + velocityX + 'px'
	label.style.top = rect.y + velocityY + 'px'
}, 1000 / FPS)


const reset = () => {
	width =
		window.innerWidth ||
		document.documentElement.clientWidth ||
		document.body.clientWidth
  ;

	height =
		window.innerHeight ||
		document.documentElement.clientHeight ||
		document.body.clientHeight
  ;

	pause =
		width <= label.getBoundingClientRect().width ||
		height <= label.getBoundingClientRect().height
  ;

	label.style.left = 'calc(50vw - 150px)'
	label.style.top = 'calc(50vh - 28px)'
	label.style.stroke = colors[0]
}


const getRandomColor = () => {
  let currentColor = -1
  
  do {
		currentColor = Math.floor(Math.random() * colors.length);
	} while (previousColor == currentColor);
  
  previousColor = currentColor
  
  return colors[currentColor]
}

reset()

window.addEventListener('resize', reset, true)
              
            
!
999px

Console