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

              
                <h1>Number preview tool</h1>

<form id="translate">
  
  <div>
    <label for="number">number</label>
    <input type="number" id="number" value="12345.6789" required />
  </div>
  
  <div>
    <label for="notation">notation</label>
    <select id="notation">
      <option>standard</option>
      <option>scientific</option>
      <option>engineering</option>
      <option>compact</option>
    </select>
  </div>
  
  <div>
    <label for="maximumfractiondigits">significant digits</label>
    <input type="number" id="maximumfractiondigits" value="2" min="0" max="9" step="1" required />
  </div>
  
  <div>
    <label for="style">style</label>
    <select id="style">
      <option>decimal</option>
      <option>currency</option>
      <option>percent</option>
      <option>unit</option>
    </select>
  </div>
  
  <div class="currencyfield">
    <label for="currency">currency</label>
    <select id="currency">
      <option>USD</option>
      <option>EUR</option>
      <option>GBP</option>
      <option>CAD</option>
      <option>AUD</option>
      <option>ZAR</option>
      <option>INR</option>
      <option>CNY</option>
      <option>JPY</option>
    </select>
  </div>
  
  <div class="currencyfield">
    <label for="currencydisplay">currency display</label>
    <select id="currencydisplay">
      <option>symbol</option>
      <option>narrowSymbol</option>
      <option>code</option>
      <option>name</option>
    </select>
  </div>
  
  <div class="unitfield">
    <label for="unit">unit</label>
    <select id="unit">
      <option>bit</option>
      <option>byte</option>
      <option>celsius</option>
      <option>centimeter</option>
      <option>day</option>
      <option>degree</option>
      <option>fahrenheit</option>
      <option>foot</option>
      <option>hour</option>
      <option>kilobyte</option>
      <option>liter</option>
      <option>meter</option>
      <option>mile</option>
      <option>month</option>
      <option>percent</option>
      <option>week</option>
      <option>year</option>
    </select>
  </div>
  
  <div class="unitfield">
    <label for="unitdisplay">unit display</label>
    <select id="unitdisplay">
      <option>long</option>
      <option>short</option>
      <option>narrow</option>
    </select>
  </div>
  
</form>

<table summary="translation">
  <thead>
    <tr><th>locale</th><th class="value">date / time</th>
  </thead>
  <tbody id="result">
    <tr><th title="US English">en-US</th><td></td></tr>
    <tr><th title="UK English">en-GB</th><td></td></tr>
    <tr><th title="Canadian English">en-CA</th><td></td></tr>
    <tr><th title="Australian English">en-AU</th><td></td></tr>
    <tr><th title="Spanish">es-ES</th><td></td></tr>
    <tr><th title="Mexican Spanish">es-MX</th><td></td></tr>
    <tr><th title="French">fr-FR</th><td></td></tr>
    <tr><th title="German">de-DE</th><td></td></tr>
    <tr><th title="Italian">it-IT</th><td></td></tr>
    <tr><th title="Portuguese">pt-PT</th><td></td></tr>
    <tr><th title="Polish">pl-PL</th><td></td></tr>
    <tr><th title="Welsh">cy-GB</th><td></td></tr>
    <tr><th title="Icelandic">is-IS</th><td></td></tr>
    <tr><th title="Kazakh">kk-KZ</th><td></td></tr>
    <tr><th title="Afrikaans">af-AF</th><td></td></tr>
    <tr><th title="Zulu">zu-ZU</th><td></td></tr>
    <tr><th title="Russian">ru-RU</th><td></td></tr>
    <tr><th title="Arabic (Saudi Arabia)">ar-SA</th><td></td></tr>
    <tr><th title="Hebrew">he-HE</th><td></td></tr>
    <tr><th title="Bengali">bn-BN</th><td></td></tr>
    <tr><th title="Vietnamese">vi-VI</th><td></td></tr>
    <tr><th title="Chinese">zh-CN</th><td></td></tr>
    <tr><th title="Japanese">ja-JP</th><td></td></tr>
  </tbody>
</table>

<output id="code" />
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

form {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
}

body {
  font-family: sans-serif;
  font-size: 1em;
  margin: 1em;
  color: #333;
  background-color: #fff;
}

h1 {
  font-size: 1.5em;
  font-weight: normal;
  margin-bottom: 0.5em;
}

input, select {
  display: block;
  width: 8em;
  font-family: inherit;
  font-size: 1em;
  padding: 0.2em;
}

label {
  display: block;
  font-size: 0.9em;
  padding: 0 0 0.2em;
  color: #666;
}

table {
  width: 100%;
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
	border-spacing: 0;
	border-collapse: collapse;
	empty-cells: show;
  margin: 1em 0;
  border: 2px solid #999;
}

thead {
  border-bottom: 1px solid #999;
}

tr th:first-child {
  width: 6em;
  border-right: 1px solid #999;
}

th, td {
  vertical-align: top;
  text-align: right;
  padding: 0.2em 0.4em;
}

th {
  background-color: rgba(0,0,0,0.2);
}

td, th.value {
  text-align: left;
}

tbody tr:nth-child(2n) {
  background-color: rgba(0,0,0,0.05);
}

output {
  display: block;
  font-family: monospace;
  white-space: nowrap;
  padding: 0.5em;
  font-size: 1em;
  color: #0d0;
  background-color: #111;
  user-select: all;
  overflow: auto;
  border-radius: 5px;
}

.currencyfield {
  display: none;
}

form.currency .currencyfield {
  display: block;
}

.unitfield {
  display: none;
}

form.unit .unitfield {
  display: block;
}
              
            
!

JS

              
                // DOM nodes
const
  translate = document.getElementById('translate'),
  code = document.getElementById('code'),
  result = [];

Array.from(document.getElementById('result')
  .getElementsByTagName('th'))
  .forEach(r => result.push(
      { input: r.textContent, output: r.nextElementSibling }
    )
  );

// form event handlers
translate.addEventListener('submit', e => e.preventDefault());
translate.addEventListener('change', update);
update();

// update results
function update() {
  
  // get field values
  const
    field = getFields(translate),
    value = parseFloat(field.number),
    opt = {
      notation: field.notation,
      maximumFractionDigits: parseFloat(field.maximumfractiondigits),
      style: field.style
    };
  
  translate.className = field.style;
  
  switch (field.style) {
      
    case 'currency':
      opt.currency = field.currency;
      opt.currencyDisplay = field.currencydisplay;
      break;
      
    case 'unit':
      opt.unit = field.unit;
      opt.unitDisplay = field.unitdisplay;
      break;
      
  }
  
  // update code snippet
  code.textContent = `new Intl.NumberFormat("[locale]", ${ JSON.stringify(opt) }).format( ${ value } );`;
  
  // update results
  result.forEach(r => {
    
    r.output.textContent = new Intl.NumberFormat(r.input, opt).format(value);
    
  });
  
}


// return an object with all form fields
function getFields(form) {
  
  const field = {};
  
  Array.from(form.elements).forEach(e => {
    if (e.id) field[e.id] = (e.value || '').trim();
  });
  
  return field;
  
}
              
            
!
999px

Console