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="controls">
		<div class="controls__group controls__group--radio">
			<div class="controls__rbtn">
				<input id="item__1" type="radio" name="cells"  value="item1" checked>
				<label for="item_1">Grid cell 1</label>
			<div class="controls__rbtn">
				<input id="item__2" type="radio" name="cells" value="item2">
				<label for="item_2">Grid cell 2</label>
			<div class="controls__rbtn">
				<input id="item__3" type="radio" name="cells" value="item3">
				<label for="item_3">Grid cell 3</label>
		<div class="controls__group">
			<label for="size">Size</label>
			<input id="size" type="range" min="1" max="6" value="1">
		<div class="controls__group">
			<label for="posX">X Position</label>
			<input id="posX" type="range" min="1" max="6" value="1">
		<div class="controls__group">
			<label for="posY">Y Position</label>
			<input id="posY" type="range" min="1" max="6" value="1">
	<div class="grid">
		<div class="grid__item" data-id="item1"></div>
		<div class="grid__item" data-id="item2"></div>
		<div class="grid__item" data-id="item3"></div>


                * {
	box-sizing: border-box;

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

.wrapper {
	width: 1200px;
	margin: 50px auto;
	display: flex;

.controls {
	margin-right: 40px;

.controls__group {
	margin-bottom: 30px;
	> * {
		display: block;

.controls__rbtn {
	margin-bottom: 10px;

.grid {
	display: grid;
	grid-template-columns: repeat(var(--gridSize), 1fr);
	grid-template-rows: repeat(var(--gridSize), 1fr);
	grid-gap: 5px;
	border: 1px solid grey;
	width: 800px;
	height: 800px;

.grid__item {
	background-color: var(--color);
	grid-column: var(--posX) / span var(--size);
	grid-row: var(--posY) / span var(--size);
	&:nth-child(2) {
		--color: red;
	&:nth-child(3) {
		--color: yellow;


                const ctrlSize = document.querySelector('#size')
const ctrlposX = document.querySelector('#posX')
const ctrlposY = document.querySelector('#posY')
const rBtns = [...document.querySelectorAll(`input[type='radio']`)]
const gridItems = [...document.querySelectorAll('.grid__item')]
const inputs = [ctrlSize, ctrlposX, ctrlposY]

const gridSize = 6

let checked
let currItem
let size
let props

const getValues = (x) => {
	x.props = {
		size: parseInt(getComputedStyle(x).getPropertyValue('--size')),
		posX: parseInt(getComputedStyle(x).getPropertyValue('--posX')),
		posY: parseInt(getComputedStyle(x).getPropertyValue('--posY'))

// Find currently selected item
const findCurrItem = () => {
	rBtns.forEach((el) => {
		if (el.checked) {
			currItem = document.querySelector(`[data-id=${el.value}]`)

// Set sliders to correct positions
rBtns.forEach((el, index) => {
	el.addEventListener('click', () => {
		findCurrItem() // find the currently selected item
		getValues(currItem) //get the current properties of the item
		let currItemProperties = Object.values(currItem.props) // create an array from props
		inputs.forEach((el, index) => {
			el.value = currItemProperties[index] // set the sliders to the corresponding values

ctrlSize.addEventListener('change', (e) => {
	size = parseInt(
	let currPos = currItem.props.posX > currItem.props.posY ? currItem.props.posX : currItem.props.posY
	if (size < gridSize - (currPos - 1)) {
		size = size
	} else {
		size = gridSize - (currPos - 1)
	}'--size', size)

const calcNewProps = (el, str) => {
	let currSize = currItem.props.size
	if (posX < gridSize - (currSize - 1)) {
		posX = posX
	} else {
		posX = gridSize - (currSize - 1)
	}, el)

ctrlposX.addEventListener('change', (e) => {
	posX = parseInt(
	calcNewProps(posX, '--posX')

ctrlposY.addEventListener('change', (e) => {
	posY = parseInt(
	calcNewProps(posY, '--posY')