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.
<main>
<h1>Escaping HTML symbols/entities</h1>
<p>To allow the embedding of code examples into web pages.</p>
<p>Replaces < > and & with &lt; &gt; and &amp; then copies the result to the clipboard.</p>
<form id=converter class=frm>
<label class=frm_lbl for=textarea data-lbl-text="Escaped HTML result, copied to clipboard">Input HTML, CSS, JavaScript, or markup:</label>
<textarea class=frm_txtr id=textarea placeholder="Paste HTML here, then click 'Convert & Copy'" spellcheck=false></textarea>
<div class=frm_buttons>
<button class=btn-convert data-clipboard-target=#textarea data-btn-text="Copied to clipboard">Convert<span class=-visually-hidden> HTML into escaped HTML</span> & Copy<span class=-visually-hidden> the result to the clipboard</span></button>
<button disabled class=btn-reset data-reset-target=#textarea>Reset<span class=-visually-hidden> the form</span></button>
</div>
</form>
<p>Permanent online tool: <a href="https://websemantics.uk/tools/escaping-html/" target=_blank title="[new window]">Escape HTML</a></p>
</main>
<!-- Codepen footer include -->
[[[https://codepen.io/2kool2/pen/mKeeGM]]]
*, *::after, *::before {box-sizing: inherit;}
body {
--color: hsl(269, 19%, 30%);
--bgColor: hsla(32,100%,85%,.35);
--linkColor: hsla(214, 71%, 47%, 1);
--linkColorUnderline: hsla(214, 71%, 47%, .5);
--linkColorHover: hsla(214, 100%, 35%, 1);
--linkBgHover: hsla(214, 100%, 85%, 1);
--linkFocus: hsla(214, 71%, 80%, 0.3);
--focusOutline: hsla(214, 71%, 85%, 1);
--textShadow: #fff;
--boxShadow: hsla(0,0%,0%,.3);
--bgColorForm: hsla(120,50%,50%,.075);
font-family: sans-serif;
text-rendering: optimizeLegibility;
margin: 1rem;
line-height: 1.5;
padding-bottom: 2rem;
background-attachment: fixed;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.4'/%3E%3C/filter%3E%3C/defs%3E%3Crect filter='url(%23a)' opacity='.3' width='100%25' height='100%25'/%3E%3C/svg%3E");
min-height: 100%;
color: var(--color);
background-color: var(--bgColor);
}
main {
max-width: 36rem;
margin: 0 auto;
}
h1 {
font-weight: 100;
margin-top: 2rem;
margin-bottom: 1rem;
text-align: center;
}
h1 + p {
font-size: 1.35rem;
font-weight: 100;
text-align: center;
}
h2 {
font-weight: 400;
margin-top: 3rem;
margin-bottom: 1rem;
text-align: center;
}
p {
text-align: center;
font-size: 1.125rem;
}
ul, p {
max-width: 40rem;
margin: 1em auto;
}
li {
margin:.25rem 0;
}
figure {
margin: 2rem auto;
max-width: 40rem;
}
figure + figure {
margin-top: 3rem;
}
figcaption {
font-size: 1.25rem;
font-weight: 100;
}
a:link,
a:visited {
color: var(--linkColor);
text-decoration-color: var(--linkColorUnderline);
outline: hsla(214, 71%, 80%, 0); solid .25rem;
transition:
color .3s ease-out,
background-color .3s ease-out,
outline-color .3s ease-out;
}
a:hover,
a:focus {
color: var(--linkColorHover);
outline: var(--linkBgHover) solid .25rem;
background-color: var(--linkBgHover);
}
/* Specifics */
.-visually-hidden {
position: absolute !important;
clip: rect(1px,1px,1px,1px);
padding: 0 !important;
border: 0 !important;
height: 1px !important;
width: 1px !important;
overflow: hidden;
}
.frm {
background-color: var(--bgColorForm);
border: 2px dashed #f90;
padding: .6rem 1rem 1rem;
max-width: 40rem;
margin: 0 auto;
}
.frm_lbl {
display: block;
margin: 0 0 .25rem;
}
.frm_txtr {
position: relative;
display: block;
margin: 0;
padding: 0.75rem 0.5rem 0 2.5rem;
border: 1px solid #ddd;
font-size: inherit;
font-family: monospace, monospace;
text-shadow: 0 1px var(--textShadow);
letter-spacing: 0.01em;
text-align: left;
white-space: pre;
text-overflow: ellipsis;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 2;
tab-size: 2;
hyphens: none;
overflow: auto;
min-height: 15rem;
resize: both;
min-width: calc(100% - 3rem);
background-color: transparent;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' viewBox='0 0 1920 64'%3E%3Cpath fill='%23fcfcfa' d='M1920 64H0V0h1920v64zM20 36a11 11 0 110 22 11 11 0 010-22z'/%3E%3Cpath stroke='%23edf3ed' stroke-width='2.6' d='M0 1h1920M0 5h1920M0 9h1920M0 13h1920M0 17h1920M0 21h1920M0 25h1920M0 29h1920'/%3E%3Cpath stroke='%23e4ede4' stroke-dasharray='2 6 2 6' stroke-width='2' d='M40 2v60'/%3E%3Cpath fill-opacity='.2' d='M20 36c6 0 11 5 11 11s-5 11-11 11S9 53 9 47s5-11 11-11zm8 6a10 10 0 00-16 0c-2 2-2 4-2 6 0 6 4 10 10 10s10-4 10-10c0-2 0-4-2-6z'/%3E%3C/svg%3E");
background-attachment: local;
background-size: 120rem 4rem;
background-position: top -1.2rem left 0;
}
.frm_txtr:focus {
outline-offset: calc(-0.25rem - 1px);
outline: var(--focusOutline) solid 0.25rem;
z-index: 5;
}
.frm_txtr:hover, .frm_txtr:focusn {
box-shadow: 0 .25rem .25rem var(--boxShadow);
}
/* Buttons */
button::-moz-focus-inner {
border: 0;
}
.frm_buttons {
display: flex;
justify-content: space-around;
}
.btn-convert,
.btn-reset {
font-size: inherit;
margin: 1rem 0 0;
cursor: pointer;
position: relative;
display: inline-block;
padding: .618rem 1.618rem;
letter-spacing: 1px;
text-shadow: rgba(0,0,0,.9) 0 1px 2px;
color: #fff;
background-color: #434343;
border: 1px solid #242424;
border-radius: 4px;
box-shadow:
rgba(255,255,255,.25) 0 1px 0,
inset rgba(255,255,255,.25) 0 1px 0,
inset rgba(0,0,0,.5) 0 0 0,
inset rgba(255,255,255,.08) 0 1.25rem 0,
inset rgba(0,0,0,.3) 0 -1.25rem 1.25rem,
inset rgba(255,255,255,.1) 0 1.25rem 1.25rem;
transition: all .2s linear;
}
.btn-convert {
background-color: #c75000;
}
.btn-copied {
background-color: #477343;
border: 1px solid #242424;
}
.btn-reset {}
[disabled] {
opacity: 0.25;
pointer-events: none;
}
var supportsES6=(function(){try{new Function('(a=0)=>a');return true}catch(e){console.log('No ES6');return false}}());
var Convert_Html_Entities = (function (window, document, supportsES6) {
'use strict';
if (!supportsES6) return;
const form = document.querySelector('.frm');
const label = document.querySelector('.frm_lbl');
const textArea = document.getElementById('textarea');
const btnConvert = document.querySelector('.btn-convert');
const btnReset = document.querySelector('.btn-reset');
if (!form || !label || !textArea || !btnConvert || !btnReset) return;
const submit = e => e.preventDefault();
const initialLabelText = label.innerHTML;
const replaceHtmlEntities = str => str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
const copy = _ => {
new ClipboardJS('.btn-convert');
const btnText = btnConvert.innerHTML;
btnConvert.innerHTML = btnConvert.getAttribute('data-btn-text');
btnConvert.classList.add('btn-copied');
setTimeout(_ => {
btnConvert.setAttribute('disabled', 'true');
btnConvert.classList.remove('btn-copied');
btnConvert.innerHTML = btnText;
btnReset.removeAttribute('disabled');
}, 2000);
};
const convert = _ => {
if (textArea.value.length < 1) return;
textArea.value = replaceHtmlEntities(textArea.value);
label.textContent = label.getAttribute('data-lbl-text');
copy();
};
const reset = _ => {
textArea.value = '';
label.textContent = initialLabelText;
btnConvert.removeAttribute('disabled');
btnReset.setAttribute('disabled', 'true');
};
form.addEventListener('submit', submit);
btnConvert.addEventListener('click', convert);
btnReset.addEventListener('click', reset);
}(window, document, supportsES6));
// Included - Copy to clipboard.js
// https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js
Also see: Tab Triggers