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>
<figure>
<figcaption>myday.class.php</figcaption>
<pre><code contenteditable="false" tabindex="0" spellcheck="false">/**
* myDay.class.php
*
* @author daemon.devin
* @version 1.0 beta 1
* @uses drugs
* @todo hustle
* @return laughter
*/
class myDay {
public function &live(self $objective, $mindState) {
return $objective->$mindState;
}
protected function invoke($objective, $mindState, $how) {
return call_user_func_array(array($objective, $mindState), $how);
}
}
class Morning extends myDay {
private $name;
protected $tasks;
public function __construct($mindState) {
$this->name = $mindState;
$this->tasks = array();
}
public function initialize(Evening $high, $get) {
$this->tasks[$get] = $high;
// instead, we get a reference from the dispatcher:
$current = &$this->live($high, "sober");
// ... and change that:
$current = $this;
}
public function loaded($get) {
$this->invoke($this->tasks[$get], "loaded", array());
}
}
class Evening extends myDay {
private $drug;
private $function;
private $mindState;
protected $owner;
public function __construct($dope, $relax, $high) {
$this->drug = $dope;
$this->function = $relax;
$this->mindState = $high;
}
protected function loaded() {
echo ("Smoking ".$this->drug." to get ".$this->mindState." and ".$this->function."\n");
}
}
$now = new Morning("sober");
$soon = new Evening('weed', 'unwind', 'loaded');
$now->initialize($soon, "smoke");
$now->loaded("smoke");</code></pre>
</figure>
</main>
body {
margin: 0;
padding: 0;
background: #000;
color: #444;
font: normal normal normal 100%/1.4 georgia, serif;
}
main {
display: block;
width: 95%;
min-width: 18em;
margin: 2em auto;
}
figure {
display: block;
margin: 1em 0;
width: 100%;
color: #9e9e9e;
border: 1px solid #111;
border-radius: 3px;
background: rgb(22, 22, 22);
}
figure figcaption {
display: block;
font-family: sans-serif;
padding: 5px 10px 4px 10px;
border-bottom: 1px solid #111;
border-radius: 3px 3px 0 0;
font-weight: bold;
font-variant: small-caps;
background: #111;
color: #9e9e9e;
}
.numbers {
cursor: context-menu;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
box-shadow: inset 0 0 4px 0 rgba(0, 0, 0, 0.5);
}
pre,
pre * {
font: normal normal normal 1em/1.4 monaco, courier, monospace;
}
pre {
font-size: 0.8em;
}
pre,
pre code,
pre samp {
display: block;
margin: 0;
cursor: text;
}
pre code,
pre samp {
/* enforce white-space for IE7 */
white-space: pre;
/* enforce word-wrap for mobile safari */
word-wrap: normal;
padding: 10px;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
overflow-x: auto;
box-shadow: inset 0 1px 0 1px rgba(0, 0, 0, 0.5);
}
/* additional focus rules to provide a visual cue */
pre [contenteditable]:focus {
border-radius: 0 0 3px 0;
background: #fff;
outline: none;
background: rgb(22, 22, 22);
box-shadow: inset 0 1px 4px 1px rgba(0, 0, 0, 0.5);
}
pre.line-numbers {
position: relative;
}
pre.line-numbers code,
pre.line-numbers samp {
margin-left: 3em;
border-left: 1px solid #000;
}
pre.line-numbers > div {
display: block;
position: absolute;
top: 0;
left: 0;
height: 100%;
border-radius: 0 0 0 3px;
overflow: hidden;
counter-reset: line;
}
pre.line-numbers > div > span {
display: block;
width: 2.5em;
padding: 0 0.5em 0 0;
text-align: right;
color: #777;
overflow: hidden;
counter-increment: line;
}
pre.line-numbers > div > span::before {
content: counter(line);
}
pre.line-numbers > div > span:first-child {
margin-top: 10px;
}
pre.line-numbers > div > span:nth-child(odd) {
background: #111;
}
@media print {
pre code {
overflow-x: visible;
white-space: pre-wrap;
}
pre.line-numbers div {
display: none;
}
pre.line-numbers > code,
pre.line-numbers > samp {
margin-left: 0;
}
}
code.hljs {
padding-top: 10px;
}
/* double-up the syntax elements for cross-browser RTF-keystroke support */
pre b,
pre strong {
font-weight: normal;
color: #039;
}
pre u,
pre u b,
pre u strong {
text-decoration: none;
color: #083;
}
pre i,
pre em,
pre i *,
pre em *,
pre i * *,
pre em * * {
letter-spacing: -0.1em;
text-decoration: none;
font-style: normal;
color: #c55;
}
.hljs {
color: #a9b7c6;
background: rgb(22, 22, 22);
display: block;
overflow-x: auto;
padding: 0.5em;
}
.hljs-number,
.hljs-literal,
.hljs-symbol,
.hljs-bullet {
color: #FF8040;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-deletion {
color: #569CD6;
}
.hljs-variable,
.hljs-template-variable,
.hljs-link {
color: #FF8040;
}
.hljs-comment,
.hljs-quote {
color: #57A64A;
}
.hljs-meta {
color: #D2A8A1;
}
.hljs-string,
.hljs-attribute,
.hljs-addition {
color: #FF0000;
}
.hljs-section,
.hljs-title,
.hljs-type {
color: #ffc66d;
}
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
color: #e8bf6a;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
(function() {
for (var tags = ['div', 'figure', 'figcaption'], i = 0; i < tags.length; i++) {
document.createElement(tags[i]);
}
})();
(function() {
//filter IE8 and earlier which don't support the generated content
if (typeof(window.getComputedStyle) == 'undefined') {
return;
}
//get the collection of PRE elements
var pre = document.getElementsByTagName('pre');
//now iterate through the collection
for (var len = pre.length, i = 0; i < len; i++) {
//get the CODE or SAMP element inside it,
//or just in case there isn't one, continue to the next PRE
var code = pre[i].getElementsByTagName('code').item(0);
if (!code) {
code = pre[i].getElementsByTagName('samp').item(0);
if (!code) {
continue;
}
}
//create a containing DIV column (but don't append it yet)
//including aria-hidden so that ATs don't read the numbers
var column = document.createElement('div');
column.setAttribute('aria-hidden', 'true');
column.setAttribute('class', 'numbers');
//split the code by line-breaks to count the number of lines
//then for each line, add an empty span inside the column
for (var n = 0; n < code.innerHTML.split(/[\n\r]/g).length; n++) {
column.appendChild(document.createElement('span'));
}
//now append the populated column before the code element
pre[i].insertBefore(column, code);
//finally add an identifying class to the PRE to trigger the extra CSS
pre[i].className = 'line-numbers';
}
})();
Also see: Tab Triggers