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="dna" style="--total: 13;">
  <div class="strand" style="--index: 1;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 2;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 3;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 4;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 5;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 6;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 7;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 8;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 9;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 10;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 11;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 12;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
  <div class="strand" style="--index: 13;">
    <div class="strand__node"></div>
    <div class="strand__node"></div>
  </div>
</div>
              
            
!

CSS

              
                @import "normalize.css";

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

body {
	display: grid;
	place-items: center;
	min-height: 100vh;
	font-family:  'Google Sans', sans-serif, system-ui;
	transform-style: preserve-3d;
	perspective: 100vmin;
	background: hsl(210 80% 12%);
}

.dna {
	height: 65vmin;
	aspect-ratio: 2/5;
	display: grid;
	transform-style: preserve-3d;
	transform: rotateX(0deg);
	rotate: 30deg;
	gap: 0.5vmin;
	animation: rotate 14s infinite linear;
}

@keyframes spin {
	to {
		transform: rotateY(360deg);
	}
}

.strand {
	--speed: 2;
	--delay: calc(sin((var(--index) / var(--total)) * 45deg) * var(--speed) * -1s);
	width: 100%;
	transform-style: preserve-3d;
	display: flex;
	justify-content: space-between;
}

@keyframes rotate {
	to {
		transform: rotate(360deg);
	}
}

.strand__node {
	background: var(--bg, white);
	height: 100%;
	aspect-ratio: 1;
	border-radius: 50%;
	animation: jump calc(var(--speed) * 1s) var(--delay, 0) infinite ease-in-out;
	border: 0.5vmin solid black;
}

.strand:before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 94%;
	height: 30%;
	background: white;
	transform: translate3d(-50%, -50%, -2px);
	transform-origin: center;
	animation: scale calc(var(--speed) * 1s) var(--delay, 0) infinite linear;
	border: 0.5vmin solid black;
}

@keyframes scale {
	25%, 75% {
		transform: translate3d(-50%, -50%, -2px) scaleX(0);
	}
	0%, 50%, 100% {
		transform: translate3d(-50%, -50%, -2px) scaleX(1);	
	}
}

.strand__node:first-of-type {
	--destination: calc((65vmin * (2 / 5)) - 100%);
/* 	background: hsl(120 80% 50%); */
}
.strand__node:last-of-type {
	--destination: calc((-65vmin * (2 / 5)) + 100%);
	animation-direction: reverse;
/* 	background: hsl(210 80% 50%); */
}

.strand__node:after {
  display: none;
	content: "";
	height: 15%;
	aspect-ratio: 1;
	background: var(--bg, white);
	position: absolute;
	border-radius: 50%;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) rotate(0deg) translateY(450%);
	animation: orbit calc(var(--speed) * 0.35s) var(--delay, 0) infinite linear;
}

@keyframes orbit {
	100% {
		transform: translate(-50%, -50%) rotate(360deg) translateY(450%);
	}
}

@keyframes jump {
	25% {
		translate: 0 0 1px;
	}
	50% {
		transform: translateX(var(--destination));
	}
	75% {
		translate: 0 0 -1px;
	}
}
              
            
!

JS

              
                /**
 * Based on this rad Dribbble shot: https://dribbble.com/shots/6280755-DNA-in-Motion
 * Then remixed with the Jurassic park color scheme :D
*/

// If they're not supported, add them with JS
if (!CSS.supports('top: calc(sin(1) * 1px)')) {
  // Push the delays in
  const STRANDS = [...document.querySelectorAll('.strand')]
  for (let s = 0; s < STRANDS.length; s++) {
    // --delay: calc(sin((var(--index) / var(--total)) * 45deg) * var(--speed) * -1s);
    const DELAY = Math.sin(((Math.PI / 180) * 45) * ((s + 1) / STRANDS.length));
    STRANDS[s].style.setProperty('--delay', `calc((${DELAY} * var(--speed)) * -1s)`);
  }
}

// Set random colors
const COLORS = ['hsl(44, 98%, 60%)', 'hsl(197, 50%, 44%)', 'hsl(300, 100%, 100%)', 'hsl(331, 76%, 50%)']

const NODES = document.querySelectorAll('.strand__node')
NODES.forEach(NODE => {
  NODE.style.setProperty('--bg', COLORS[Math.floor(Math.random() * COLORS.length)])
})
              
            
!
999px

Console