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

              
                h1
	|Hey look at all these
	br
	|compositing operations!
p
	|(click on animations to restart them)

              
            
!

CSS

              
                body
	padding-bottom: 48px
	font-family: 'Fredericka the Great', cursive
	text-align: center
	color: #ccc
	background: #111

h1
	margin: 2em 0 0.4em
	font-family: Oswald, sans-serif

p
	font-size: 12px

canvas
	margin-top: 36px
	border-radius: 50%
	background: #fff
	cursor: pointer

              
            
!

JS

              
                const L = 200;
const L2 = L / 2.2 * Math.SQRT2;
const FPS = 2;

// A few blank types are commented out :)
const opTypes = [
	'source-over',
//	'source-in',
	'source-out',
//	'source-atop',
	'destination-over',
//	'destination-in',
//	'destination-out',
	'destination-atop',
//	'lighter',
	'copy',
	'xor',
	'multiply',
//	'screen',
	'overlay',
	'darken',
	'lighten',
//	'color-dodge',
	'color-burn',
	'hard-light',
	'soft-light',
	'difference',
	'exclusion',
	'hue',
	'saturation',
	'color',
	'luminosity',
];

function createCompositeDemo (opType) {
	const container = document.createElement('div');
	const canvas = document.createElement('canvas');
	const label = document.createElement('h2');
	canvas.height = canvas.width = L;
	label.textContent = opType;
	container.appendChild(canvas);
	container.appendChild(label);
	document.body.appendChild(container);
	
	const ctx = canvas.getContext('2d');
	ctx.globalCompositeOperation = opType;
	
	canvas.addEventListener('click', function clear () {
		ctx.clearRect(0, 0, L, L);
	}, false);
	
	return function update (t) {
		ctx.save();
		ctx.translate(L / 2, L / 2);
		ctx.rotate(t / 4000);
		ctx.fillStyle = `hsl(${t / 50}, 80%, 70%)`;
		ctx.fillRect(-L2 / 2, -L2 / 2, L2, L2);
		ctx.restore();
	};
}

const updaters = opTypes.map(createCompositeDemo);
(function draw (t) {
	updaters.forEach(fn => fn(t));
	requestAnimationFrame(draw);
})(0);

              
            
!
999px

Console