HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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">
/* 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;
}
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;
}
}());
}
Also see: Tab Triggers