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.


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.


                <p>Here's a simple vanilla JS solution to increase session length and decrease the frequency with which users navigate away from your site using an external link.</p>

	<li><a href="">This goes to Google</a></li>
	<li><a href="#">This is a non-external link</a></li>
	<li><a href="">External link 2</a></li>
	<li><a href="">External link (but this one goes to my website so it's fine lol)</a></li>
	<li><a href="">External link 2</a></li>


                body {
	padding: 1rem;
	width: 100vw;
	height: 100vh;
p {
	max-width: 30ch;
li {
	list-style-type: none;
a {
	display: inline-block;
	max-width: max-content;
	padding: .25rem;



                const links = document.querySelectorAll(

const lerp = (min, max, t) => min * (1 - t) + max * t;
const handleMoveElement = (link) => {
	const { x, width, y, height } = link.getBoundingClientRect();
	const angle = Math.random() * Math.PI * 2;
	const targetX = parseFloat(
		(Math.cos(angle) * width + (x + width / 2)).toFixed(2)
	const targetY = parseFloat(
		(Math.sin(angle) * width + (y + height / 2)).toFixed(2)

	let animationComplete = false;
	const animate = () => {
		const raf = requestAnimationFrame(animate);

		const style = getComputedStyle(link);
		const currentX = parseFloat(style.getPropertyValue("--x"));
		const currentY = parseFloat(style.getPropertyValue("--y"));

		if (
			targetX - 0.2 <= currentX &&
			currentX <= targetX + 0.2 &&
			targetY - 0.2 <= currentY &&
			currentY <= targetY + 0.2
			animationComplete = true;

		if (animationComplete) {
		} else {"--x", lerp(currentX, targetX, 0.2).toFixed(2));"--y", lerp(currentY, targetY, 0.2).toFixed(2));
links.forEach((link) => {
		`translateX(calc(var(--x) * 1px)) translateY(calc(var(--y) * 1px))`
	);"--x", 0);"--y", 0);
	link.addEventListener("mouseover", (e) => handleMoveElement(link));