css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <body>
	<div class="tree-container">
		<div class="snow-container"></div>
		<div class="topper">⭐</div>
		<svg width="452px" height="520px" viewBox="0 0 452 520" class="main-tree">
		    <defs>
		        <rect id="path-1" x="196" y="449" width="60" height="72"></rect>
		        <filter x="-16.7%" y="-13.9%" width="133.3%" height="127.8%" filterUnits="objectBoundingBox" id="filter-2">
		            <feGaussianBlur stdDeviation="5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="10" dy="0" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <polygon id="path-3" points="226 239 436 449 16 449"></polygon>
		        <filter x="-8.3%" y="-11.9%" width="116.7%" height="133.3%" filterUnits="objectBoundingBox" id="filter-4">
		            <feOffset dx="0" dy="10" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
		            <feGaussianBlur stdDeviation="10" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
		        </filter>
		        <polygon id="path-5" points="226 149 406 329 46 329"></polygon>
		        <filter x="-9.7%" y="-13.9%" width="119.4%" height="138.9%" filterUnits="objectBoundingBox" id="filter-6">
		            <feOffset dx="0" dy="10" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
		            <feGaussianBlur stdDeviation="10" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
		        </filter>
		        <polygon id="path-7" points="226 74 376 224 76 224"></polygon>
		        <filter x="-11.7%" y="-16.7%" width="123.3%" height="146.7%" filterUnits="objectBoundingBox" id="filter-8">
		            <feOffset dx="0" dy="10" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
		            <feGaussianBlur stdDeviation="10" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
		        </filter>
		        <polygon id="path-9" points="226 14 346 134 106 134"></polygon>
		        <filter x="-14.6%" y="-20.8%" width="129.2%" height="158.3%" filterUnits="objectBoundingBox" id="filter-10">
		            <feOffset dx="0" dy="10" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
		            <feGaussianBlur stdDeviation="10" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
		        </filter>
		        <circle id="path-11" cx="74" cy="240" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-12">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-13" cx="106" cy="150" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-14">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-15" cx="344" cy="150" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-16">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-17" cx="376" cy="240" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-18">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-19" cx="46" cy="345" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-20">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-21" cx="406" cy="345" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-22">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-23" cx="16" cy="465" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-24">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		        <circle id="path-25" cx="436" cy="465" r="16"></circle>
		        <filter x="-10.9%" y="-10.9%" width="121.9%" height="121.9%" filterUnits="objectBoundingBox" id="filter-26">
		            <feGaussianBlur stdDeviation="2.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
		            <feOffset dx="2" dy="-2" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
		            <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
		            <feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
		        </filter>
		    </defs>
		    <g id="Artboard" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
		        <g id="Rectangle">
		            <use fill="#8B572A" fill-rule="evenodd" xlink:href="#path-1"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"></use>
		        </g>
		        <g id="Triangle">
		            <use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-3"></use>
		            <use fill="#507E1A" fill-rule="evenodd" xlink:href="#path-3"></use>
		        </g>
		        <g id="Triangle">
		            <use fill="black" fill-opacity="1" filter="url(#filter-6)" xlink:href="#path-5"></use>
		            <use fill="#507E1A" fill-rule="evenodd" xlink:href="#path-5"></use>
		        </g>
		        <g id="Triangle">
		            <use fill="black" fill-opacity="1" filter="url(#filter-8)" xlink:href="#path-7"></use>
		            <use fill="#507E1A" fill-rule="evenodd" xlink:href="#path-7"></use>
		        </g>
		        <g id="Triangle">
		            <use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-9"></use>
		            <use fill="#507E1A" fill-rule="evenodd" xlink:href="#path-9"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--primary-colour)" fill-rule="evenodd" xlink:href="#path-13"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-14)" xlink:href="#path-13"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--secondary-colour)" fill-rule="evenodd" xlink:href="#path-15"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-16)" xlink:href="#path-15"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--secondary-colour)" fill-rule="evenodd" xlink:href="#path-11"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-12)" xlink:href="#path-11"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--primary-colour)" fill-rule="evenodd" xlink:href="#path-17"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-18)" xlink:href="#path-17"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--primary-colour)" fill-rule="evenodd" xlink:href="#path-19"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-20)" xlink:href="#path-19"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--secondary-colour)" fill-rule="evenodd" xlink:href="#path-21"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-22)" xlink:href="#path-21"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--secondary-colour)" fill-rule="evenodd" xlink:href="#path-23"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-24)" xlink:href="#path-23"></use>
		        </g>
		        <g id="Oval">
		            <use fill="var(--primary-colour)" fill-rule="evenodd" xlink:href="#path-25"></use>
		            <use fill="black" fill-opacity="1" filter="url(#filter-26)" xlink:href="#path-25"></use>
		        </g>
		        <g id="lights-container">
		        </g>
		    </g>
		</svg>
		<div class="ground"></div>
		<div class="present-container"></div>
	</div>
	<div class="controls">
		<h3>Customise your tree!</h3>
		<div class="control">
			<select name="toppers" class="toppers">
				<option value="⭐">⭐</option>
				<option value="👼">👼</option>
			</select>
		</div>
		<div class="control">
			<button id="add-present">Add a present! 🎁</button>
		</div>
		<div class="control">
			<label for="primary-colour">Change primary bauble colour</label>
			<input class="colour-picker" type="color" name="primary-colour" value="#ff0000">
		</div>
		<div class="control">
			<label for="secondary-colour">Change secondary bauble colour</label>
			<input class="colour-picker" type="color" name="secondary-colour" value="#DAA520">
		</div>
		<div class="control">
			<label for="tinsel-colour">Change tinsel colour</label>
			<input class="colour-picker" type="color" name="tinsel-colour" value="#C0C0C0">
		</div>
		<div class="control">
			<p>Add a new decoration! Select one here, then click on the tree</p>
      <p>For tinsel, click the tree and drag across</p>
			<select name="decoration-select" class="decoration-select">
				<option value=""> </option>
				<option value="light">light</option>
				<option value="⛄">⛄</option>
				<option value="🎅🏼">🎅🏼</option>
				<option value="🌟">🌟</option>
				<option value="🎀">🎀</option>
				<option value="🕯️">🕯️</option>
				<option value="🔔">🔔</option>
				<option value="🎄">🎄</option>
				<option value="❄️">❄️</option>
				<option value="🎁">🎁</option>
				<option value="🦌">🦌</option>
				<option value="🛷">🛷</option>
				<option value="tinsel">tinsel</option>
			</select>
		</div>
			<div class="control">
				<button id="snow-button">Let it snow! ❄️</button>
				<button id="stop-button" class="hidden-button">Stop, it's too snowy 🌨️</button>
				<audio id="sleigh-bells" src="http://soundbible.com/1256-Sleigh-Bells-Ringing.mp3"></audio>
			</div>
			<div class="control">
				<button id="cat-button">🐈</button>
				<p id="cat-warning"></p>
			</div>
	</div>
	<div class="ground"></div>
</body>
            
          
!
            
              
:root {
	--primary-colour: #ff0000;
	--secondary-colour: #DAA520;
	--tinsel-colour: #C0C0C0;
}

body {
	display: flex;
	justify-content: space-between;
	background-color: #DCDCDC;
}

.ground {
	position: absolute;
	background-color: #FFF;
	width: 100%;
	height: 1000px;
	left: 0px;
	top: 600px;
	z-index: -10;
}

.controls {
	min-width: 300px;
	display: flex;
	flex-direction: column;
	padding: 10px;
	margin-right: 50px;
	text-align: center;
	font-family: 'Helvetica Neue', sans-serif;
	border: 1px solid grey;
	border-radius: 5px;
	background-color: #FFF;
	box-shadow: 3px 3px grey;
}

.control {
	margin-bottom: 2em;
}

select, button {
	font-size: 1.2em;
}

.sound-effect-box {
	border: 1px solid grey;
	border-radius: 5px;
	margin: 0 20px 20px;
}

.tree-container {
	margin-top: 50px;
}

.main-tree {
	padding: 0 50px;
}

#Triangle {
	cursor: pointer;
}

.topper {
  width: 100%;
  height: 50px;
  margin-bottom: -24px;
  text-align: center;
  font-size: 2.4em;
}

.present-container {
	font-size: 3em;
	text-align: center;
	line-height: 0.6em;
	width: 452px;
	padding: 0 50px;
	margin-top: -20px;
}

.decoration {
	position: absolute;
	font-size: 30px;
	z-index: 100;
}

.tinsel {
	stroke: var(--tinsel-colour);
	stroke-width: 18;
	fill: none;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.snowflake {
	width: 7px;
	height: 7px;
	background-color: #fff;
	border-radius: 50%;
	border-bottom: 1px solid lightgrey;
	position: absolute;
	z-index: 200;
}

.hidden-button {
	display: none;
}
            
          
!
            
              const topSelector = document.querySelector('.toppers');
		const topper = document.querySelector('.topper');
		function changeTopper() {
			topper.textContent = topSelector.value;
		}
		topSelector.addEventListener('change', changeTopper);

		const addButton = document.getElementById('add-present');
		const presents = document.querySelector('.present-container');
		function addPresent() {
			if (presents.textContent.length < 34) {
				presents.textContent += "🎁";
			}
		}
		addButton.addEventListener('click', addPresent);

		const colourPickers = document.querySelectorAll('.colour-picker');
		function changeColour() {
			document.documentElement.style.setProperty(`--${this.name}`, this.value);
		}
		colourPickers.forEach(picker => picker.addEventListener('change', changeColour));

const decSelector = document.querySelector('.decoration-select');
		const tree = document.querySelector('.tree-container');
		const triangles = document.querySelectorAll('#Triangle');
		let lightsContainer = document.getElementById('lights-container');
		function placeDecoration(e) {
			if (decSelector.value !== "" && decSelector.value !== "tinsel") {
				if (decSelector.value === "light") {			
					const light = document.createElementNS("http://www.w3.org/2000/svg", 'circle');
					light.setAttribute("fill", "#FFFF00");
					light.setAttribute("cy", `${e.offsetY}`);
					light.setAttribute("cx", `${e.offsetX - 50}`);
					light.setAttribute("r", "1");
					lightsContainer.appendChild(light);
				} else {
					const decoration = document.createElement('div');
					decoration.textContent = decSelector.value;
					decoration.classList.add('decoration');
					decoration.style.top = `${e.offsetY + 70}px`;
					decoration.style.left = `${e.offsetX - 5}px`;
					tree.appendChild(decoration);
				}
			}
		}
		triangles.forEach(triangle => triangle.addEventListener('click', placeDecoration));

		let startX = 0;
		let startY = 0;
		const mainTree = document.querySelector(".main-tree");
		function startTinsel(e) {
			if (decSelector.value === "tinsel") {
				startX = e.offsetX - 50;
				startY = e.offsetY;
			}
		}
		function endTinsel(e) {
			if (decSelector.value === "tinsel") {
				const tinsel = document.createElementNS("http://www.w3.org/2000/svg", 'path');
				let endX = e.offsetX - 50;
				let endY = e.offsetY;
				tinsel.classList.add("tinsel");
				tinsel.setAttribute("d", `M ${startX},${startY} C ${startX},${startY+18} ${endX},${endY+18} ${endX},${endY} `);
				mainTree.appendChild(tinsel);
			}
		}
		triangles.forEach(triangle => triangle.addEventListener('mousedown', startTinsel));
		triangles.forEach(triangle => triangle.addEventListener('mouseup', endTinsel));

		function twinkle() {
			if (lightsContainer.hasChildNodes()) {
				lightsContainer.querySelectorAll('circle').forEach(light => {
					light.setAttribute('r', `${Math.random()+1}`);
				});
			}
		}
		setInterval(twinkle, 500);
		twinkle();

		const snowButton = document.getElementById('snow-button');
		const stopButton = document.getElementById('stop-button');
		const snowContainer = document.querySelector('.snow-container');
		const sleighBellsSound = document.getElementById('sleigh-bells');
		let snowing = null;

		function letItSnow() {
			stopButton.classList.remove("hidden-button");
			snowButton.classList.add("hidden-button");
			function createFlake() {
				let flake = document.createElement('div');
				flake.classList.add('snowflake');
				flake.style.top = '0px';
				flake.style.left = `${Math.random() * window.innerWidth}px`;
				snowContainer.appendChild(flake);
				function snowfall() {
					let topValue = parseInt(flake.style.top.slice(0, flake.style.top.length-2), 10);
					if (topValue < 650) {
						flake.style.top = `${topValue + 1}px`;
					} else {
						flake.remove();
					}
				}
				setInterval(snowfall, (Math.random() * 100) + 10);
				snowfall();
			}

			snowing = setInterval(createFlake, 2000);
		}

		function stopSnow() {
			snowButton.classList.remove("hidden-button");
			stopButton.classList.add("hidden-button");
			clearInterval(snowing);
		}
		snowButton.addEventListener('click', letItSnow);
		stopButton.addEventListener('click', stopSnow);

		const catButton = document.getElementById("cat-button");
		const catSound = document.getElementById("cat-meow");
		const catWarning = document.getElementById("cat-warning");
		function dropDecs() {
			if (!document.querySelectorAll(".decoration").length) {
				catWarning.textContent = "Add some decorations first!";
			} else {
				catWarning.textContent = "";
				Array.from(document.querySelectorAll(".decoration")).filter((dec, index) => index % 2 === 1).forEach(decoration => {
					decoration.style.top = `${(Math.random()*30)+610}px`;
					decoration.style.transform = `rotate(${(Math.random()*180)-90}deg)`;
				});
			}
		}
		catButton.addEventListener('click', dropDecs);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console