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 class="grid">
<div class="grid__row">
<div class="grid__col grid__col--4">
<textarea class="js-input"># An exhibit of Markdown
This note demonstrates some of what [Markdown][1] is capable of doing.
*Note: Feel free to play with this page. Unlike regular notes, this doesn't automatically save itself.*
## Basic formatting
Paragraphs can be written like so. A paragraph is the basic block of Markdown. A paragraph is what text will turn into when there is no reason it should become anything else.
Paragraphs must be separated by a blank line. Basic formatting of *italics* and **bold** is supported. This *can be **nested** like* so.
## Lists
### Ordered list
1. Item 1
2. A second item
3. Number 3
4. Ⅳ
*Note: the fourth item uses the Unicode character for [Roman numeral four][2].*
### Unordered list
* An item
* Another item
* Yet another item
* And there's more...
## Paragraph modifiers
### Code block
Code blocks are very useful for developers and other people who look at code or other things that are written in plain text. As you can see, it uses a fixed-width font.
You can also make `inline code` to add code into other things.
### Quote
> Here is a quote. What this is should be self explanatory. Quotes are automatically indented when they are used.
## Headings
There are six levels of headings. They correspond with the six levels of HTML headings. You've probably noticed them already in the page. Each level down uses one more hash character.
### Headings *can* also contain **formatting**
### They can even contain `inline code`
Of course, demonstrating what headings look like messes up the structure of the page.
I don't recommend using more than three or four levels of headings here, because, when you're smallest heading isn't too small, and you're largest heading isn't too big, and you want each size up to look noticeably larger and more important, there there are only so many sizes that you can use.
## URLs
URLs can be made in a handful of ways:
* A named link to [MarkItDown][3]. The easiest way to do these is to select what you want to make a link and hit `Ctrl+L`.
* Another named link to [MarkItDown](http://www.markitdown.net/)
* Sometimes you just want a URL like http://www.markitdown.net/.
## Horizontal rule
A horizontal rule is a line that goes across the middle of the page.
---
It's sometimes handy for breaking things up.
## Images
Markdown can also contain images. I'll need to add something here sometime.
## Finally
There's actually a lot more to Markdown than this. See the official [introduction][4] and [syntax][5] for more information. However, be aware that this is not using the official implementation, and this might work subtly differently in some of the little things.
[1]: http://daringfireball.net/projects/markdown/
[2]: http://www.fileformat.info/info/unicode/char/2163/index.htm
[3]: http://www.markitdown.net/
[4]: http://daringfireball.net/projects/markdown/basics
[5]: http://daringfireball.net/projects/markdown/syntax
</textarea>
</div>
<div class="grid__col grid__col--4">
<textarea class="js-output"></textarea>
</div>
<div class="grid__col grid__col--4">
<iframe class="js-preview"></iframe>
</div>
</div>
</div>
@use postcss-preset-env {
stage: 0;
}
/* helpers/grid.css */
.grid {
width: 100%;
}
.grid__row {
display: flex;
}
.grid__col {
flex-grow: 1;
}
.grid__col--4 {
width: calc(100% / 3);
}
/* layout/base.css */
* {
box-sizing: inherit;
}
html {
box-sizing: border-box;
height: 100%;
}
body {
font-family: sans-serif;
line-height: 1.5;
margin: 0;
min-height: 100%;
}
/* modules/code.css */
.pre {
height: 100vh;
}
/* modules/embed.css */
iframe {
border: 0;
height: 100%;
width: 100%;
}
/* modules/form.css */
textarea {
background: none;
border: 0;
height: 100vh;
margin: 0;
padding: 0.5em;
width: 100%;
}
/* vendor/codemirror.css */
.CodeMirror {
height: 100vh;
}
.CodeMirror-readonly .CodeMirror-cursor {
display: none;
}
// import 'CodeMirror/mode/xml/xml';
// import 'CodeMirror/addon/edit/matchbrackets';
// import CodeMirror from 'CodeMirror';
// import marked from 'marked';
class App {
constructor(options) {
this.init();
this.addEventListeners();
}
init() {
const input = (this.input = CodeMirror.fromTextArea(
document.querySelector(".js-input"),
{
lineNumbers: true,
matchBrackets: true,
mode: "text/x-markdown",
theme: "material"
}
));
const output = (this.output = CodeMirror.fromTextArea(
document.querySelector(".js-output"),
{
lineNumbers: true,
matchBrackets: true,
mode: "text/html",
theme: "material",
readOnly: true
}
));
this.preview = document.querySelector(".js-preview");
output.getWrapperElement().classList.add("CodeMirror-readonly");
this.compile(input.getValue());
}
compile(source) {
const previewDocument = this.preview.contentDocument;
const output = marked(source);
previewDocument.open();
previewDocument.write(output);
previewDocument.close();
this.output.setValue(output);
}
addEventListeners() {
const { input } = this;
let delay;
input.on("change", () => {
clearTimeout(delay);
delay = setTimeout(() => this.compile(input.getValue()), 300);
});
}
}
new App();
Also see: Tab Triggers