Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                <div class="wrap">
	<h1>Update CSS Variables With <em>JS</em></h1>
	<div class="option">
		<strong>Option</strong>
		<div class="block">
			<label for="textSize" class="opt-title">Font size</label>
			<input type="range" name="textSize" min="11" max="18" value="14" data-sizing="px" />
		</div>
		<div class="block">
			<label for="mainColor" class="opt-title">Main Color</label>
			<input type="color" name="mainColor" value="#ffc600">
		</div>
		<div class="block">
			<label for="blur" class="opt-title">Background Blur</label>
			<input type="range" name="blur" min="0" max="10" value="0" data-sizing="px" />
		</div>
	</div>
	
	<div class="content">
		<article class="article-1">
			<img src="http://unsplash.it/960?image=183" alt="image" class="img">
			<div class="txt">
				<p><em>Lorem ipsum </em>dolor sit amet, consectetur adipiscing elit. Ut auctor porttitor ipsum. Proin euismod elit risus, vel semper ligula convallis eget. Nullam efficitur condimentum nisi, vel mollis nibh mattis vitae. Nullam porta, mi in sollicitudin imperdiet, magna mi accumsan tortor, quis convallis tortor lorem ac metus. Fusce tincidunt, massa vel porta pellentesque, nibh ex ornare arcu, ac accumsan ipsum ligula in turpis. Proin vel neque in lacus volutpat tempor sit amet pretium massa. Donec tempor <em>mauris ut eros dictum</em>, id cursus nunc venenatis. Aliquam vulputate, orci in laoreet mollis, est orci blandit urna, eu dictum lacus diam ac turpis.</p>
				<p>Vestibulum lacinia vel ante vel vehicula. Praesent dignissim tristique luctus. Vivamus odio tellus, aliquam vitae interdum vitae, congue vitae elit. Phasellus ornare feugiat turpis non elementum. In hac habitasse platea dictumst. Phasellus sollicitudin dui ut feugiat convallis. Etiam aliquet gravida metus vel congue.</p>
				<p>Quisque non purus at justo interdum finibus. Donec libero nisi, ultrices non blandit eu, convallis et magna. Suspendisse potenti. Quisque vestibulum, diam non facilisis iaculis, dui odio lacinia ligula, sed porttitor felis ex sed nisl. <em>Curabitur tempor vel tellus ac rhoncus</em>. Sed dictum erat pharetra lorem mattis, non euismod risus venenatis. Maecenas vel ligula quis eros laoreet elementum a eget magna.</p>
			</div>
		</article>
		<article class="article-2">
			<img src="http://unsplash.it/960?image=179" alt="image" class="img">
			<div class="txt">
				<p><em>Integer ac euismod mi, ut commodo risus. Suspendisse metus ante, iaculis ac convallis non, lobortis non nulla. Cras venenatis feugiat dolor, eu aliquet massa venenatis nec.</em> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc viverra dictum sapien, quis dictum nibh. Mauris suscipit, diam congue luctus condimentum, risus massa convallis orci, id ultricies augue risus non ligula. Phasellus viverra risus vel rhoncus aliquam. Aliquam vel vestibulum justo. Ut ornare vel nibh vitae cursus. Mauris vitae mauris at nulla hendrerit dictum ac vel ante. Sed nec dui molestie, pulvinar est nec, molestie mauris. Praesent dignissim velit nec eros tempor, imperdiet maximus magna convallis. Etiam laoreet dolor at elit dapibus, quis molestie enim volutpat. <em>Donec ultricies, eros at aliquam dapibus</em>, mauris turpis vulputate orci, sed vehicula nisi felis eget lorem. Mauris id sollicitudin sem. Proin a pulvinar ipsum, et fringilla nunc. Phasellus rutrum vel sem scelerisque gravida. Nunc maximus enim elit, ut elementum urna vehicula aliquam. Nunc id sapien quis justo mattis volutpat et non quam. Integer hendrerit et elit ut tincidunt. Fusce convallis lectus quis enim semper, vel pretium turpis scelerisque. Maecenas dui elit, semper eu finibus nec, euismod a mauris. Nulla efficitur lorem vitae rutrum tincidunt. Sed in neque maximus, rhoncus libero id, auctor felis. Fusce efficitur ultricies purus. Etiam in augue quis massa facilisis accumsan a id leo. Nunc luctus tellus non odio imperdiet, nec mollis metus euismod. Mauris ut fringilla tortor. Praesent ac dictum leo.</p>
			</div>
		</article>
		<article class="article-3">
			<img src="http://unsplash.it/960?image=228" alt="image" class="img">
			<div class="txt">
				<p>Vivamus vehicula lacus at fermentum facilisis. Etiam tempus pellentesque tristique. Nullam vitae malesuada eros. Cras facilisis scelerisque felis, in luctus ante dictum ac.</p>
				<p>Ut dolor orci, sodales in lectus vel, egestas blandit dui. Nam feugiat, lacus id laoreet dignissim, ligula dolor congue ex, pretium convallis ex elit eget erat. Mauris malesuada faucibus fermentum. Vivamus luctus dapibus metus sed egestas.<em> Cras tempus sodales tincidunt</em>. Mauris sit amet sagittis nisi. Nam nec lectus leo. Praesent ac dolor sit amet quam congue eleifend. Donec interdum a libero at ornare. Pellentesque quis lacinia nisl. Nunc sit amet massa ante. Phasellus in felis est. Vivamus facilisis metus ut mi molestie dictum. <br/>Duis tristique, velit vitae bibendum placerat, elit nisl fermentum nunc, id commodo mi nisi vel risus. In eleifend lorem vitae accumsan pharetra. Nunc ultrices rhoncus pellentesque. Proin tincidunt, nunc eget dapibus pharetra, velit lacus vehicula magna, non auctor libero purus eu lacus. Curabitur nec aliquam leo. Sed blandit vulputate justo in egestas. Donec in viverra eros. Quisque volutpat neque eu mauris euismod convallis nec non metus. Maecenas nibh lorem, lacinia a velit aliquam, <em>ullamcorper condimentum felis</em>. Aenean diam urna, imperdiet id porta quis, cursus in sem. Etiam tempor bibendum maximus. Nulla ut dictum diam. Mauris consequat dolor nec libero pharetra pretium. Phasellus pharetra ultrices efficitur.</p>
				<p class="accent"><em>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</em></p>
			</div>
		</article>
	</div>
	
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro');

:root {
	--textSize: 14px;
	--mainColor: #ffc600;
	--blur: 0px;
}

* {
	margin: 0;
	padding: 0;
	font-family: 'Source Sans Pro', sans-serif;
}

h1 {
	font-size: 43px;
	text-align: center;
	color: #f6f6f6;
	margin-top: 40px;
	margin-bottom: 60px;
}

h2 {
	font-size: 32px;
	margin-bottom: 20px;
}

body {
	background-color: #242424;
	
	h2 {
		color: #f6f6f6;
		border-left: 5px solid #f6f6f6;
		padding-left: 12px;
	}
}

em {
	color: var(--mainColor);
	font-style: normal;
}

.wrap {
	padding: 20px;
	width: 960px;
	margin: 0 auto;
}

.option {
	position: fixed;
	padding: 25px;
	z-index: 10;
	bottom: 30px;
	right: 30px;
	background-color: #fff;
	font-size: 16px;
	box-shadow: 0px 4px 10px rgba(1,1,1,0.15);
	
	strong {
		display: block;
		margin-bottom: 30px;
		font-size: 30px;
	}
	
	.block {
		margin: 6px 0;
	}
	
	.opt-title {
		font-weight: bold;
		margin-right: 4px;
	}
	
	label+input {
		margin-left: 4px;
	}
}


article {
	overflow: hidden;
	position: relative;
	margin: 30px 0;
		
		&:after {
			opacity: 0.5;
			position: absolute;
			top: 0;
			left: 0;
			display: block;
			width: 100%;
			height: 100%;
			background-color: #000;
			content: '';
			pointer-events: none;
			user-select: none;
		}
	
	.img {
		display: block;
		width: 100%;
		filter: blur(var(--blur));
	}
	
	.txt {
		z-index: 1;
		display: flex;
		position: absolute;
		bottom: 20px;
		color: #fafafa;
		padding: 20px;
		
		p {
			margin: 0 14px;
			font-size: var(--textSize);
			line-height: 140%;
		}
	}
}

.article-2 {
	.txt {
		width: 60%;
	}
}

.article-3 {
	.txt {
		display: block;
	  text-align: center;
		top: 50%;
		transform: translateY(-50%);
		p {
			width: 50%;
			margin: 0 auto;
		}
		p:nth-child(2) {
			width: 75%;
			margin-top: 30px;
			margin-bottom: 60px;
		}
	}
}

article .txt p.accent {
	font-size: 120%;
	width: 90%;
}
              
            
!

JS

              
                const inputs = document.querySelectorAll(".option input");

const handleUpdate = function() {
	const suffix = this.dataset.sizing || '';
	document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}

inputs.forEach(input => {
	input.addEventListener("change", handleUpdate);
	input.addEventListener("mousemove", handleUpdate);
});
              
            
!
999px

Console