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.


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.


                <div class="wrapper">
	<div class="grid">
		<div class="grid__item grid__item--heading">
			<h1>Hello. And welcome.</h1>
		<div class="grid__item grid__item--lg">
			<img src="" alt="A kingfisher close up">
		<div class="grid__item grid__item--md">
			<img src="" alt="Beautiful sunset">
		<div class="grid__item grid__item--sm">
			<img src="" alt="Pine needles on a tree">
	<button class="btn">Click to change placement</button>



                :root {
	--gridSize: 6;
	--size: 1;
	--posX: 1;
	--posY: 1;

img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;

.wrapper {
	max-width: 1200px;
	margin: 0 auto;

.grid {
	display: grid;
	grid-template-columns: repeat(var(--gridSize), 1fr);
	grid-template-rows: repeat(var(--gridSize), 1fr);
	border: 1px solid grey;
	width: 90vw;
	height: 90vw;
	margin: 100px auto;
	@media (min-width: 960px) {
		width: 33vw;
		height: 33vw;

.grid__item {
	grid-column: var(--posX) / span var(--size);
	grid-row: var(--posY) / span var(--size);
	mix-blend-mode: hard-light;

.grid__item--heading {
	--posX: 4;
	--posY: 1;
	--size: 3;
	z-index: 1;
	border: 2px solid coral;
	padding: 20px;

.grid__item--lg {
	--posY: 2;
	--size: 3;

.grid__item--md {
	--posX: 5;
	--posY: 4;
	--size: 2;

.grid__item--sm {
	--posX: 3;
	--posY: 6;

.btn {
	padding: 10px 20px;
	position: absolute;
	top: 0;
	left: 0;


                const btn = document.querySelector('.btn')
const items = [...document.querySelectorAll('.grid__item')]
const body = document.querySelector('body')

let availablePositions
let props
let x
let y

let getItemProperties = (el) => {
	el.props = {
		posX : parseInt(getComputedStyle(el).getPropertyValue('--posX')),
		posY: parseInt(getComputedStyle(el).getPropertyValue('--posY')),
		size: parseInt(getComputedStyle(el).getPropertyValue('--size'))

const gridSize = getComputedStyle(body).getPropertyValue('--gridSize')

const setNewPosition = () => {
	items.forEach((item) => {
		availablePositions = [...Array(gridSize - (item.props.size - 1))] // creates an empty array of the number of available positions for the grid item - so that it won’t exceed 6 grid tracks
		const itemAvailablePositions =, i) => {
			return i + 1
		const getRandom = () => {
			return itemAvailablePositions[Math.floor(Math.random() * itemAvailablePositions.length)]
		const calcNewPos = (el) => {'--posX', getRandom())'--posY', getRandom())

btn.addEventListener('click', setNewPosition)