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 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

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

              
                <h2>Stylesheet Unit Converter</h2>

<label for="fromunit">Convert from: </label>
<select id="fromunit">
	<optgroup label="Pixel units">
	    <option value="px" selected>px</option>
	</optgroup>
	<optgroup label="Font units">
	    <option value="em">em</option>
	    <option value="rem">rem</option>
	    <option value="ex">ex</option>
	    <option value="ch">ch</option>
	</optgroup>
	<optgroup label="Viewport units">
	    <option value="vw">vw</option>
	    <option value="vh">vh</option>
	    <option value="vmin">vmin</option>
	    <option value="vmax">vmax</option>
	</optgroup>
</select>
<span class="labeldivider"> to: </span>
<select id="tounit">
	<optgroup label="Pixel units">
	    <option value="px">px</option>
	</optgroup>
	<optgroup label="Font units">
	    <option value="em" selected>em</option>
	    <option value="rem">rem</option>
	    <option value="ex">ex</option>
	    <option value="ch">ch</option>
	</optgroup>
	<optgroup label="Viewport units">
	    <option value="vw">vw</option>
	    <option value="vh">vh</option>
	    <option value="vmin">vmin</option>
	    <option value="vmax">vmax</option>
	</optgroup>
</select>
<span id="factor"></span>
<br>

<label for="base">Base size: </label>
<input type="number" id="base" value="16" max="50" min="1">
<span class="labeldivider"> &nbsp; Inverse base size:</span><input type="checkbox" id="inverse" />
<br>

<label for="precision">Decimal precision: </label>
<input type="number" id="precision" value="3" max="3" min="0">
<br>

<textarea id="in" placeholder="Paste in your stylesheet here"></textarea>
<textarea id="out" placeholder="Converted stylesheet will be displayed here"></textarea>

<button>Convert</button>

<dl id="help">
	<dt>Unit</dt>
	<dd>Description</dd>
	<dt>px</dt>
	<dd>pixels (1px = 1/96th of 1in)</dd>
	<dt>em</dt>
	<dd>Relative to the font-size of the element (2em means 2 times the size of the current font)</dd>
	<dt>ex</dt>
	<dd>Relative to the x-height of the current font (rarely used)</dd>
	<dt>ch</dt>
	<dd>Relative to width of the "0" (zero)</dd>
	<dt>rem</dt>
	<dd>Relative to font-size of the root element</dd>
	<dt>vw</dt>
	<dd>Relative to 1% of the width of the viewport</dd>
	<dt>vh</dt>
	<dd>Relative to 1% of the height of the viewport</dd>
	<dt>vmin</dt>
	<dd>Relative to 1% of viewport's smaller dimension</dd>
	<dt>vmax</dt>
	<dd>Relative to 1% of viewport's larger dimension</dd>
</dl>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto);

body {
 font: normal 1em 'Roboto', sans-serif;
	background: radial-gradient(ellipse at center, hsla(195,97%,76%,1) 0%,hsla(194,85%,64%,1) 40%,hsla(195,96%,45%,1) 100%);
	padding: 1em;
	margin: 0;
	background: hsla(194,55%,34%,1);
}
::-webkit-input-placeholder { /* WebKit browsers */
  color: rgb(84, 85, 117);
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
  color: rgb(84, 85, 117);
  opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
  color: rgb(84, 85, 117);
  opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
  color: rgb(84, 85, 117);
}


label {
	display: inline-block;
	font-weight: bold;
	width: 9em;
	text-align: right;
}
.labeldivider {
	font-weight: bold;
}
select {
	font-size: 1em;
	max-width: 5em;
	margin-bottom: .2em;
}
textarea {
  width: 100%;
  min-height: 6em;
	margin-bottom: .2em;
}
input[type="number"] {
	max-width: 3em;
	margin-bottom: .2em;
	font-size: 1em;
}

#factor {
	font-size: 90%;
	font-style: italic;
	white-space: nowrap;
	.highlight {
		color: rgb(241, 198, 96);
	}

}
dl#help {
	font-size: 90%;
	background: rgba(255,255,255,.5);
	padding: 1em;
	dt {
	  display: inline-block;
	  min-width: 4em;
		&:first-of-type {
			font-weight: bold;
		}
	}
	dd {
	  display: inline;
	  margin: 0;
		&:first-of-type {
			font-weight: bold;
		}
	}
	dd:after {
	  display: block;
	  content: '';
	}
}

              
            
!

JS

              
                jQuery( document ).ready(function( $ ) {

	$('input#base, input#inverse, input#precision, select#fromunit, select#tounit').on('change',function() {
	    var inverse = $('input#inverse').is(':checked'),
					baseSize = $('input#base').val(),
					decimalPlaces = $('input#precision').val(),
	    		fromUnitName = $('select#fromunit').val(),
	    		toUnitName = $('select#tounit').val(),
	        fromUnit = 1,
					toUnit = Number(Math.round((inverse ? fromUnit * baseSize : fromUnit / baseSize) + 'e' + decimalPlaces) + 'e-' + decimalPlaces);
					$('#factor').html('( Conversion factor: <span class="highlight">' + fromUnit + fromUnitName + ' = ' + toUnit + toUnitName + '</span> )');
	}).trigger('change');

	$('button').on('click', function () {
	    var inverse = $('input#inverse').is(':checked'),
					baseSize = $('input#base').val(),
					decimalPlaces = $('input#precision').val(),
	    		fromUnitName = $('select#fromunit').val(),
	    		toUnitName = $('select#tounit').val(),
					css = $('textarea#in').val(),
					result,
					findPX = new RegExp('(\\d*\\.?\\d*)'+ fromUnitName,'g');

	    while ((result = findPX.exec(css)) !== null) {
	        var fromUnit = Number('0' + result[1]),
							toUnit = Number(Math.round((inverse ? fromUnit * baseSize : fromUnit / baseSize) + 'e' + decimalPlaces) + 'e-' + decimalPlaces)
	        css = css.replace(result[1] + fromUnitName, toUnit + toUnitName);
	    }
	    $('textarea#out').val(css);
	});

});

              
            
!
999px

Console