<p><button>Add div</button></p>

<main></main>
div {
	transition: background-color 0.5s;
	background-color: transparent;
	
	display: inline-block;
	height: 2em;
	width: 2em;
	outline: 1px solid #ccc;
	margin: 0.5em;
	
	@starting-style {
		background-color: yellow;
	}
}


/* Non-demo styles below */
@layer base {
	@layer reset {
		* {
			box-sizing: border-box;
		}
		body {
			margin: 0;
			padding: 0;
		}
		html, body {
			min-height: 100%;
		}
	}
	@layer layout {
		html {
			max-width: 90ch;
			padding: 3rem 2rem;
			margin: auto;
/* 			line-height: 1.5;
			font-size: 1.25rem; */
		}

		a,
		a:visited {
			color: blue;
		}
		
		h2 {
			margin-top: 2em;
		}
		
		footer {
			margin-top: 4em;
			text-align: center;
			font-style: italic;
		}

	}
	
	@layer code {
		pre {
			border: 1px solid #dedede;
			padding: 1em;
			background: #f7f7f7;
			font-family: "Courier 10 Pitch", Courier, monospace;
			overflow-x: auto;
			border-left: 0.4em solid cornflowerblue;
			tab-size: 4;
		}
		
		code:not(pre code), output:not(code:has(output) output) {
			background: #f7f7f7;
			border: 1px solid rgb(0 0 0 / 0.2);
			padding: 0.1rem 0.3rem;
			margin: 0.1rem 0;
			border-radius: 0.2rem;
			display: inline-block;
		}
	}
}
document.querySelector('button').addEventListener('click', e => {
	const $newDiv = document.createElement('div');
	document.querySelector('main').appendChild($newDiv);
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.