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 id="tablehere"></div>

<p><label><input type="checkbox" id="autocopy" checked> Auto-copy flag upon clicking</label></p>
<!-- Does not work due to cross-origin blocking.
<p><label><input type="checkbox" id="babelfont"> Use BabelStone flags font</label></p>
-->

<p>Shows all (valid and invalid) <a href="https://en.wikipedia.org/wiki/Regional_Indicator_Symbol">Unicode Regional Indicator Symbols</a>. Layout inspired by <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"><em>ISO 3166-1 alpha-2</em> from Wikipedia</a>.</p>

<p>Older browser versions do not support <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint"><code>String.fromCodePoint</code></a>. I've added <a href="https://github.com/mathiasbynens/String.fromCodePoint">mathiasbynens/String.fromCodePoint</a> polyfill.</p>

<p>Results (as of 2016-03-19):</p>

<ul>
  <li>No support:
    <ul>
      <li>Any Linux browser (Chrome, Firefox).</li>
      <li>Any Windows browser (IE/Edge, Chrome, Firefox) on any Windows version (tested up to 10).</li>
      <li>Android up to 4.4.</li>
      <li>Android 5.0 on Samsung.</li>
    </ul>
  </li>
  <li>Small selection of flags:
    <ul>
      <li>iOS up to 8.1 (with Safari up to 8).</li>
      <li>Mac OS X up to 10.10 (Yosemite), with Safari up to 8.</li>
    </ul>
  </li>
  <li>Full support:
    <ul>
      <li>iOS 9.0 (with Safari 9).</li>
      <li>Mac OS X 10.11 (El Capitan), with any browser (Safari 9).</li>
      <li>Android 5.0 or newer.</li>
    </ul>
  </li>
</ul>

<p>Easy cross-browser testing through <a href="https://www.crossbrowsertesting.com/">CrossBrowserTesting.com</a>, <a href="https://blog.codepen.io/2014/12/15/test-pens-browser-live-free-crossbrowsertesting-com/">for free for CodePens</a>.</p>

<p>Related links:</p>

<ul>
  <li><a href="https://babelstone.co.uk/Fonts/FlagsTest.html">https://babelstone.co.uk/Fonts/FlagsTest.html</a>, <a href="https://twitter.com/babelstone/status/510177642071732225">@BabelStone tweet</a>, <a href="http://forum.high-logic.com/viewtopic.php?t=5180">forum topic</a></li>
</ul>

<input type="text" id="inputforcopy">
              
            
!

CSS

              
                /* Does not work due to cross-origin blocking.
@font-face
{
	  font-family: "BabelStone Flags";
	  src: local("BabelStone Flags"), local("BabelStoneFlags"), url("https://babelstone.co.uk/Fonts/BabelStoneFlags.woff") format("woff");
}
*/

html, body {
  background: white;
  color: black;
  font-family: sans-serif;
}
table {
  border-collapse: collapse;
}
table td,
table th {
  white-space: nowrap;
  padding: 0.1em;
  text-align: center;
  vertical-align: middle;
}
.babelfont td {
  font-family: "BabelStone Flags";
}

table tr.highlight,
table col.highlight {
  background-color: #CCC;
}

#inputforcopy {
  width: 1px;
  height: 1px;
  border: 0;
  padding: 0;
  margin: 0;
}
              
            
!

JS

              
                function highlight_cell(cell) {
  // Converting the live HTMLCollection into a simple and static JavaScript Array.
  var elements = Array.prototype.map.call(
    document.getElementsByClassName('highlight'),
    function(el) {
      return el;
    }
  );
  elements.map(function(el) {
    el.classList.remove('highlight');
  });

  if (!cell || cell.tagName.toLowerCase() != 'td') {
    return;
  }
  var tr = cell.parentElement;
  if (!tr || tr.tagName.toLowerCase() != 'tr') {
    return;
  }
  tr.classList.add('highlight');
  var col_index = cell.cellIndex;
  // cellIndex is zero-based, but nth-child is 1-based, thus "+1".
  // But colgroup.data starts at the second column, thus "-1".
  var col = document.querySelector('table > colgroup.data > col:nth-child(' + (col_index - 1 + 1) + ')');
  if (col) {
    col.classList.add('highlight');
  }
}

function copy_single_line_of_text(text) {
  var input = document.getElementById('inputforcopy');
  input.value = text;
  input.select();
  try {
    document.execCommand('copy');
  } catch (err) {
    // Do nothing.
  }
  input.blur();
}

function handle_click(ev) {
  highlight_cell(ev.target);
  var autocopy = document.getElementById('autocopy');
  if (autocopy.checked) {
    if (ev.target.tagName.toLowerCase() == 'td') {
      copy_single_line_of_text(ev.target.textContent.trim());
    }
  }
}

function create_table() {
  var letterA = 65;
  var flagA = 0x1F1E6;
  var wildcard = 0x2423;  // OPEN BOX

  var table = document.createElement('table');

  var colgroup1 = document.createElement('colgroup');
  var colgroup2 = document.createElement('colgroup');
  var colgroup3 = document.createElement('colgroup');

  colgroup1.appendChild(document.createElement('col'));
  for (var i = 0; i < 26; i++) {
    colgroup2.appendChild(document.createElement('col'));
  }
  colgroup3.appendChild(document.createElement('col'));

  colgroup1.setAttribute('class', 'header');
  colgroup2.setAttribute('class', 'data');
  colgroup3.setAttribute('class', 'header');

  table.appendChild(colgroup1);
  table.appendChild(colgroup2);
  table.appendChild(colgroup3);

  function create(tag, content) {
    var elem = document.createElement(tag);
    elem.textContent = content;
    return elem;
  }

  function add_spacer(tr) {
    var th = document.createElement('th');
    th.setAttribute('class', 'spacer');
    tr.appendChild(th);
  }

  function header_row() {
    var tr = document.createElement('tr');
    add_spacer(tr);
    for (var i = 0; i < 26; i++) {
      tr.appendChild(create('th', String.fromCodePoint(wildcard, letterA + i)));
    }
    add_spacer(tr);
    return tr;
  }

  var tbody = document.createElement('tbody');
  table.appendChild(tbody);

  tbody.appendChild(header_row());

  for (var j = 0; j < 26; j++) {
    var tr = document.createElement('tr');
    tbody.appendChild(tr);
    tr.appendChild(create('th', String.fromCodePoint(letterA + j, wildcard)));
    for (var i = 0; i < 26; i++) {
      tr.appendChild(create('td', String.fromCodePoint(flagA + j, flagA + i)));
    }
    tr.appendChild(create('th', String.fromCodePoint(letterA + j, wildcard)));
  }

  tbody.appendChild(header_row());

  table.addEventListener('click', handle_click);

  return table;
}

function font_choice_changed(ev) {
  if (ev.target.checked) {
    document.querySelector('table').classList.add('babelfont');
  } else {
    document.querySelector('table').classList.remove('babelfont');
  }
}

function init() {
  document.getElementById('tablehere').appendChild(create_table());

  // Does not work due to cross-origin blocking.
  //document.getElementById('babelfont').addEventListener('change', font_choice_changed);
}
window.addEventListener('load', init);


// Polyfill for older browsers:

/*! https://mths.be/fromcodepoint v0.2.1 by @mathias */
if (!String.fromCodePoint) {
	(function() {
		var defineProperty = (function() {
			// IE 8 only supports `Object.defineProperty` on DOM elements
			try {
				var object = {};
				var $defineProperty = Object.defineProperty;
				var result = $defineProperty(object, object, object) && $defineProperty;
			} catch(error) {}
			return result;
		}());
		var stringFromCharCode = String.fromCharCode;
		var floor = Math.floor;
		var fromCodePoint = function(_) {
			var MAX_SIZE = 0x4000;
			var codeUnits = [];
			var highSurrogate;
			var lowSurrogate;
			var index = -1;
			var length = arguments.length;
			if (!length) {
				return '';
			}
			var result = '';
			while (++index < length) {
				var codePoint = Number(arguments[index]);
				if (
					!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
					codePoint < 0 || // not a valid Unicode code point
					codePoint > 0x10FFFF || // not a valid Unicode code point
					floor(codePoint) != codePoint // not an integer
				) {
					throw RangeError('Invalid code point: ' + codePoint);
				}
				if (codePoint <= 0xFFFF) { // BMP code point
					codeUnits.push(codePoint);
				} else { // Astral code point; split in surrogate halves
					// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
					codePoint -= 0x10000;
					highSurrogate = (codePoint >> 10) + 0xD800;
					lowSurrogate = (codePoint % 0x400) + 0xDC00;
					codeUnits.push(highSurrogate, lowSurrogate);
				}
				if (index + 1 == length || codeUnits.length > MAX_SIZE) {
					result += stringFromCharCode.apply(null, codeUnits);
					codeUnits.length = 0;
				}
			}
			return result;
		};
		if (defineProperty) {
			defineProperty(String, 'fromCodePoint', {
				'value': fromCodePoint,
				'configurable': true,
				'writable': true
			});
		} else {
			String.fromCodePoint = fromCodePoint;
		}
	}());
}
              
            
!
999px

Console