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

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 id="container">
  <h1>Simple PX to EMS Converter <sup>version 1.1</sup></h1>
  <p>Just enter a base size and a pixel size to get the value in ems. The default base value for text size in most browsers is 16px.</p>
  
  <hr/>
  
  <form action="#">
  <div>
    <label for="baseSize">Base Pixel Size</label>
    <input type="text" size="4" name="baseSize" value="16"/>
  </div>
  <div>
    <label for="targetSize">Size in Pixels</label>
    <input type="text" size="4" name="targetSize" value="20"/>
  </div>
  <!--
  <div>
    <input name="submit" type="submit" value="Submit" />
  </div>
  -->
  </form>
  <hr/>  
  <div id="result">
    <label for="submit">Result</label>
    <input type="text" name="reultEm" disabled />
  </div>  
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Fugaz+One);
@import url(https://fonts.googleapis.com/css?family=Muli);

h1, h2, p, label, input {
  font-family: 'Fugaz One', cursive;
}

h1 {
  color:white;
  text-shadow: 0.125em 0.125em 0.375em rgba(0,0,0,0.2);
  filter: dropshadow(color=#444, offx=3, offy=3);
}
  h1 sup {
   font-size:0.5em; 
  }

p {
  font-family: 'Muli', sans-serif;
  line-height:1.4em;
}

hr {
  margin:1em 0;
  border:0.0625em solid white;
}
  form div {
    margin-bottom:1em;
  }

    label {
  
    }

    input {
      padding:0 0.25em;
      border-radius:0.25em;
      border:1px solid #999;
    }

input[type=submit] {
  background-color:gold;
  border:none;
  padding:0.625em 1.875em;
}
#container {
  width:23.75em;
  background:rgba(124,200,32,0.9);
  padding:3.125em 3.125em 4.375em;
  margin:2em auto;
  border-bottom-right-radius:3.25em;
  
}

  div#result {
    font-size:1.6em;
  }

/*
  Credit for Awesome Linear Gradient Background
  goes to https://cdpn.io/wButa
*/ 
body {
	background-color: #f7f7f7;
	background-image: linear-gradient(#eee 25%, transparent 25%),
					  linear-gradient(90deg, #eee 25%, transparent 25%); 
	background-size: 8px 8px;
}
              
            
!

JS

              
                $(function() {

  var ems = function(targetPx, basePx) {  
    if(targetPx === 0) {return 0};
    return targetPx/basePx; 
  }
  
    var base = $("input[name=baseSize]");
    var target = $("input[name=targetSize]");
    var emResult = $("input[name=reultEm]");
    var calculate_ems = function() {
      if($.isNumeric($(target).val())) {
        $(emResult).val(ems($(target).val(), $(base).val()) + "em");
      } else {
        $(emResult).val('Integer, please!');
      }
    }
    
    calculate_ems();
  
    $(target).on('keyup', function() {
      calculate_ems();
    });
    

  /*
  Version 1.1 - Removed Submit button, added keyup listener
  
  $("form").submit(function() {
    
    $(emResult).val(ems($(target).val(), $(base).val()) + "em");
    
  });
  */  
});
              
            
!
999px

Console