Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <div class="controls">
	<h2>Controls</h2>
	<div class="bp1"><input type="range" min="0" max="2000" step="1" /><input type="number" /></div>
	<div class="bp2"><input type="range" min="0" max="2000" step="1" /><input type="number" /></div>
	<div class="bp3"><input type="range" min="0" max="2000" step="1" /><input type="number" /></div>
	<div class="bp4"><input type="range" min="0" max="2000" step="1" /><input type="number" /></div>
</div>
<div class="visual">
<h2>Visualization <span class="currentWidth"></span></h2>
<svg width="90%" height="10em" viewbox="0 0 2200 100">
	<rect class="vbp1" x="0" y="0" width="100" height="100"></rect>
	<rect class="vbp2" x="0" y="0" width="100" height="100"></rect>
	<rect class="vbp3" x="0" y="0" width="100" height="100"></rect>
	<rect class="vbp4" x="0" y="0" width="100" height="100"></rect>
	
	<g class="texts">
<text x="2" y="-10" class="vbpt1"></text>
<text x="2" y="140" class="vbpt2"></text>
<text x="2" y="-10" class="vbpt3"></text>
<text x="2" y="140" class="vbpt4"></text>
	</g>
	
</svg>
</div>
<div class="mq">
	<h2>Media queries</h2>
<textarea cols="30" rows="10" class="result"></textarea>
	</div>

<style class="live"></style>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700|Open+Sans:400,800);
body,
html {
	font-family: 'Open Sans', sans-serif;
	width: 100vw;
	height: 100vh;
}

body {
	
}

textarea {
	font-family: 'Inconsolata', monospace;
	width: 80%;
	height: 20em;
	
	border-width: 0;
	font-size: 12pt;
}

input {
	display: block;
	width: 80%;
	min-width: 400px;
}

input[type="number"] {
	width: 10%;
	min-width: 50px;
	border-width: 0;
}

rect {
	fill: rgba(0,0,0,.1);
	stroke: none;
}

text {
	font-family: 'Inconsolata', monospace;
	font-size: 20px;
}

.controls > div {
	display: flex;
}

@media all and (min-width:320px) and (max-width:750px) {
	text {
		font-size: 80px;
	}
}

@media all and (min-width:751px) and (max-width:1024px) {
	text {
		font-size: 52px;
	}
}

@media all and (min-width:1025px) and (max-width:1600px) {
	text {
		font-size: 52px;
	}
}

@media all and (min-width:1601px) {
	text {
		font-size: 24px;
	}
}

* {
	user-select: none;
	box-sizing: border-box;
}

textarea {
	user-select: inherit;
}

svg{
	min-width: 400px;
}
              
            
!

JS

              
                var breakpoints = [320, 750, 1024, 1600];

var result = document.querySelector(".result"),
	ranges = document.querySelectorAll('input[type="range"]'),
	values = document.querySelectorAll('input[type="range"]+input'),
	live = document.querySelector(".live"),
	currentWidth = document.querySelector(".currentWidth");

function update(evt) {
	var bp = [];
	currentWidth.innerText = "(current width: " + document.body.clientWidth + ")";
	var isChangeSourceRange = true;
	if (evt) {
		isChangeSourceRange = evt.target.type.toString().toLowerCase() === "range";
		evt.preventDefault();
	}
	var last = 0;
	Array.prototype.forEach.call(ranges, function (r, i) {
		var val = parseInt(isChangeSourceRange ? r.value : values[i].value);
		val = val < last ? last + 1 : val;
		r.value = val;
		values[i].value = val;
		bp.push(val);
		var id = i + 1;
		var rect = document.querySelector(".vbp" + id);
		rect.setAttribute("width", val);
		// rect.setAttribute('x', last);
		var txt = document.querySelector(".vbpt" + id);
		txt.setAttribute("x", val + 2);
		txt.textContent = val;
		last = val;
	});
	generateMediaQueries(bp);
}

function init() {
	Array.prototype.forEach.call(ranges, function (r, i) {
		r.value = breakpoints[i];
		values[i].value = breakpoints[i];
	});
	Array.prototype.forEach.call(ranges, function (r, i) {
		r.addEventListener("input", update);
		values[i].addEventListener("change", update);
	});
	window.addEventListener("resize", update);
}

function generateMediaQueries(breakpoints) {
	var mq = [];
	var last = -1;

	breakpoints.forEach(function (bp) {
		if (last !== -1) {
			mq.push(bp);
		}
		mq.push(mq.length > 1 ? parseInt(bp) + 1 : bp);
		last = parseInt(bp);
	});

	var rules = "";
	(livecss = ""), (bp = 2);
	for (var i = 0; i < mq.length; i += 2) {
		var rule = "@media all and (min-width:" + mq[i] + "px)";
		if (mq[i + 1]) {
			rule += " and (max-width:" + mq[i + 1] + "px)";
		}
		var liveRule = rule;
		rule += " {\n   /* CSS rules here */\n}";
		liveRule +=
			" {\nrect:nth-child(" +
			bp +
			") {stroke: rgba(0,0,0,1);stroke-width: 5px;}\n}";
		bp++;
		// livecss+=liveRule;
		rules += rule + "\n\n";
	}
	result.value = rules;
	live.innerHTML = livecss;
}

init();
update();

              
            
!
999px

Console