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.
<label for="path">Path to favicons</label>
<input id="path" placeholder="enter the path to your favicons & browserconfig.xml"><br>
<label for="path">Windows Tile background color</label>
<input class="jscolor" value="2b5797"><br>
<label>PNG Image (228 x 228 or larger)</label>
<input type="file" id="select">
<img id="preview">
<br>
<p>Images must be square :)</p>
<h1>HTML</h1>
<p>Place the Following in the <head></head> of your HTML</p>
<code id="html">
<!-- generics --><br />
<link rel="icon" href="<span>/path/to</span>/favicon-32.png" sizes="32x32"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-57.png" sizes="57x57"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-76.png" sizes="76x76"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-96.png" sizes="96x96"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-128.png" sizes="128x128"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-192.png" sizes="192x192"><br />
<link rel="icon" href="<span>/path/to</span>/favicon-228.png" sizes="228x228"><br />
<br />
<!-- Android --><br />
<link rel="shortcut icon" sizes="196x196" href=“<span>/path/to</span>/favicon-196.png"><br />
<br />
<!-- iOS --><br />
<link rel="apple-touch-icon" href="<span>/path/to</span>/favicon-120.png" sizes="120x120"><br />
<link rel="apple-touch-icon" href="path/to/favicon-152.png" sizes="152x152"><br />
<link rel="apple-touch-icon" href="path/to/favicon-180.png" sizes="180x180"><br />
<br />
<!-- Windows 8 IE 10--><br />
<meta name="msapplication-TileColor" content="#<output>FFFFFF</output>"><br />
<meta name="msapplication-TileImage" content="<span>/path/to</span>/favicon-144.png"><br />
<br />
<!— Windows 8.1 + IE11 and above —><br />
<meta name="msapplication-config" content="<span>/path/to</span>/browserconfig.xml" /><br />
</code>
<br>
<button id="saveFileHTML">Save File</button>
<h1>browserconfig.xml</h1>
<code id="xml">
<?xml version="1.0" encoding="utf-8"?><br />
<browserconfig><br />
<msapplication><br />
<tile><br />
<square70x70logo src=“favicon-76.png”/><br />
<square150x150logo src="favicon-228.png"/><br />
<TileColor>#<span>2b5797</span></TileColor><br />
</tile><br />
</msapplication><br />
</browserconfig>
</code>
<br>
<button id="saveFileBROWSER">Save File</button>
<br>
<h1>Favicons</h1>
<img id="favicon-228.png" class="preview" data-size="228"><br>
<img id="favicon-196.png" class="preview" data-size="196"><br>
<img id="favicon-180.png" class="preview" data-size="180"><br>
<img id="favicon-144.png" class="preview" data-size="144"><br>
<img id="favicon-128.png" class="preview" data-size="128"><br>
<img id="favicon-96.png" class="preview" data-size="96"><br>
<img id="favicon-76.png" class="preview" data-size="76"><br>
<img id="favicon-57.png" class="preview" data-size="57"><br>
<img id="favicon-32.png" class="preview" data-size="32"><br>
<button id="saveFavIcons">Save File</button>
<h3>Windows tile preview</h3>
<div id="smalltile"><img class="preview" data-size="70"></div>
<div id="mediumtile"><img class="preview" data-size="150"></div>
body {
padding: 10px;
}
#path {
min-width: 400px;
}
label {
display:inline-block;
min-width: 250px;
}
#smalltile, #mediumtile {
background: #2B5797;
display: flex;
justify-content: center;
align-items: center;
}
#smalltile {
width: 70px;
height: 70px;
margin-bottom: 30px;
img {
width: 40px;
}
}
#mediumtile {
width: 150px;
height: 150px;
img {
width: 70px;
}
}
// Simple JQuery for inputs
$( "#path" ).change(function() {
var inputval = $( this ).val();
$("#html span").html(inputval); //update code
});
$( ".jscolor" ).change(function() {
var inputval2 = $( this ).val();
$("#xml span").html(inputval2) //update code
$("#html output").html(inputval2) //update code
});
// Click Handlers
$( "#saveFileHTML" ).click(function() {
saveToDiskText("#html", "head.html");
});
$( "#saveFileBROWSER" ).click(function() {
saveToDiskText("#xml","browserconfig.xml");
});
$( "#saveFavIcons" ).click(function() {
$( ".preview" ).each(function() {
var dataSize = $(this).attr("data-size");
var filename = "favicon-" + dataSize + ".png";
saveToDiskImage(this, filename);
});
});
// save file FileSaver.js
function saveToDiskText (target, filename){
var filebody = $(target).text();
var file = new File([filebody], filename, {type: "text/plain;charset=utf-8"});
saveAs(file);
}
//save file image js
function saveToDiskImage (target, filename){
var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
// draw to canvas...
canvas.toBlob(function(blob) {
saveAs(blob, filename);
});
}
function resize(size, target) {
var file = $("#select")[0].files[0];
console.log("this is my file " + file);
console.log("this is my target " + target);
ImageTools.resize( file, {
width: size, // maximum width
height: size // maximum height
}, function(blob, didItResize) {
// didItResize will be true if it managed to resize it, otherwise false (and will return the original file as 'blob')
var src = window.URL.createObjectURL(blob);
$(target).attr("src", src)
// you can also now upload this blob using an XHR.
});
}
$("#select").change(function() {
//resize(320,);
$( ".preview" ).each(function() {
//var size = $(this).data(size);
var size = $(this).attr("data-size")
console.log(size);
resize(size, this);
});
})
// http://stackoverflow.com/questions/2434458/image-resizing-client-side-with-javascript-before-upload-to-the-server
// https://github.com/eligrey/FileSaver.js
'use strict';
if (typeof exports === "undefined") {
var exports = {};
}
if (typeof module === "undefined") {
var module = {};
}
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var hasBlobConstructor = typeof Blob !== 'undefined' && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
})();
var hasArrayBufferViewSupport = hasBlobConstructor && typeof Uint8Array !== 'undefined' && (function () {
try {
return new Blob([new Uint8Array(100)]).size === 100;
} catch (e) {
return false;
}
})();
var hasToBlobSupport = typeof HTMLCanvasElement !== "undefined" ? HTMLCanvasElement.prototype.toBlob : false;
var hasBlobSupport = hasToBlobSupport || typeof Uint8Array !== 'undefined' && typeof ArrayBuffer !== 'undefined' && typeof atob !== 'undefined';
var hasReaderSupport = typeof FileReader !== 'undefined' || typeof URL !== 'undefined';
var ImageTools = (function () {
function ImageTools() {
_classCallCheck(this, ImageTools);
}
_createClass(ImageTools, null, [{
key: 'resize',
value: function resize(file, maxDimensions, callback) {
if (typeof maxDimensions === 'function') {
callback = maxDimensions;
maxDimensions = {
width: 640,
height: 480
};
}
var maxWidth = maxDimensions.width;
var maxHeight = maxDimensions.height;
if (!ImageTools.isSupported() || !file.type.match(/image.*/)) {
callback(file, false);
return false;
}
if (file.type.match(/image\/gif/)) {
// Not attempting, could be an animated gif
callback(file, false);
// TODO: use https://github.com/antimatter15/whammy to convert gif to webm
return false;
}
var image = document.createElement('img');
image.onload = function (imgEvt) {
var width = image.width;
var height = image.height;
var isTooLarge = false;
if (width > height && width > maxDimensions.width) {
// width is the largest dimension, and it's too big.
height *= maxDimensions.width / width;
width = maxDimensions.width;
isTooLarge = true;
} else if (height > maxDimensions.height) {
// either width wasn't over-size or height is the largest dimension
// and the height is over-size
width *= maxDimensions.height / height;
height = maxDimensions.height;
isTooLarge = true;
}
if (!isTooLarge) {
// early exit; no need to resize
callback(file, false);
return;
}
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, width, height);
if (hasToBlobSupport) {
canvas.toBlob(function (blob) {
callback(blob, true);
}, file.type);
} else {
var blob = ImageTools._toBlob(canvas, file.type);
callback(blob, true);
}
};
ImageTools._loadImage(image, file);
return true;
}
}, {
key: '_toBlob',
value: function _toBlob(canvas, type) {
var dataURI = canvas.toDataURL(type);
var dataURIParts = dataURI.split(',');
var byteString = undefined;
if (dataURIParts[0].indexOf('base64') >= 0) {
// Convert base64 to raw binary data held in a string:
byteString = atob(dataURIParts[1]);
} else {
// Convert base64/URLEncoded data component to raw binary data:
byteString = decodeURIComponent(dataURIParts[1]);
}
var arrayBuffer = new ArrayBuffer(byteString.length);
var intArray = new Uint8Array(arrayBuffer);
for (var i = 0; i < byteString.length; i += 1) {
intArray[i] = byteString.charCodeAt(i);
}
var mimeString = dataURIParts[0].split(':')[1].split(';')[0];
var blob = null;
if (hasBlobConstructor) {
blob = new Blob([hasArrayBufferViewSupport ? intArray : arrayBuffer], { type: mimeString });
} else {
var bb = new BlobBuilder();
bb.append(arrayBuffer);
blob = bb.getBlob(mimeString);
}
return blob;
}
}, {
key: '_loadImage',
value: function _loadImage(image, file, callback) {
if (typeof URL === 'undefined') {
var reader = new FileReader();
reader.onload = function (evt) {
image.src = evt.target.result;
if (callback) {
callback();
}
};
reader.readAsDataURL(file);
} else {
image.src = URL.createObjectURL(file);
if (callback) {
callback();
}
}
}
}, {
key: 'isSupported',
value: function isSupported() {
return typeof HTMLCanvasElement !== 'undefined' && hasBlobSupport && hasReaderSupport;
}
}]);
return ImageTools;
})();
exports['default'] = ImageTools;
module.exports = exports['default'];
Also see: Tab Triggers