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.
<ul class="descriptions">
<li class="description" id="getInitialState">
<h2 class="heading heading--2">getInitialState</h2>
<p>Invoked once before the component is mounted. The return value will be used as the initial value of <code>this.state</code></p>
</li>
<li class="description" id="getDefaultProps">
<h2 class="heading heading--2">getDefaultProps</h2>
<p>Invoked once and cached when the class is created. Values in the mapping will be set on <code>this.props</code> if that prop is not specified by the parent component (i.e. using an in check).</p>
<p>This method is invoked before any instances are created and thus cannot rely on <code>this.props</code>. In addition, be aware that any complex objects returned by <code>getDefaultProps()</code> will be shared across instances, not copied.</p>
</li>
<li class="description" id="componentWillMount">
<h2 class="heading heading--2">componentWillMount</h2>
<p>Invoked once, both on the client and server, immediately before the initial rendering occurs. If you call <code>setState</code> within this method, <code>render()</code> will see the updated state and will be executed only once despite the state change.</p>
</li>
<li class="description" id="render">
<h2 class="heading heading--2">render</h2>
<p>The render() method is required.</p>
<p>When called, it should examine this.props and this.state and return a single child element. This child element can be either a virtual representation of a native DOM component (such as <code><div /></code> or <code>React.DOM.div()</code>) or another composite component that you've defined yourself.</p>
<p>You can also return null or false to indicate that you don't want anything rendered. Behind the scenes, React renders a <code><noscript></code> tag to work with our current diffing algorithm. When returning null or false, <code>ReactDOM.findDOMNode(this)</code> will return <code>null</code>.</p>
<p>The <code>render()</code> function should be pure, meaning that it does not modify component state, it returns the same result each time it's invoked, and it does not read from or write to the DOM or otherwise interact with the browser (e.g., by using <code>setTimeout</code>). If you need to interact with the browser, perform your work in <code>componentDidMount()</code> or the other lifecycle methods instead. Keeping <code>render()</code> pure makes server rendering more practical and makes components easier to think about.</p>
</li>
<li class="description" id="componentDidMount">
<h2 class="heading heading--2">componentDidMount</h2>
<p>Invoked once, only on the client (not on the server), immediately after the initial rendering occurs. At this point in the lifecycle, you can access any refs to your children (e.g., to access the underlying DOM representation). The <code>componentDidMount()</code> method of child components is invoked before that of parent components.</p>
<p>If you want to integrate with other JavaScript frameworks, set timers using setTimeout or setInterval, or send AJAX requests, perform those operations in this method.</p>
</li>
<li class="description" id="componentWillReceiveProps">
<h2 class="heading heading--2">componentWillReceiveProps</h2>
<p>Invoked when a component is receiving new props. This method is not called for the initial render.</p>
<p>Use this as an opportunity to react to a prop transition before <code>render()</code> is called by updating the state using <code>this.setState()</code>. The old props can be accessed via this.props. Calling <code>this.setState()</code> within this function will not trigger an additional render.</p>
</li>
<li class="description" id="shouldComponentUpdate">
<h2 class="heading heading--2">shouldComponentUpdate</h2>
<p>Invoked before rendering when new props or state are being received. This method is not called for the initial render or when <code>forceUpdate</code> is used.</p>
<p>Use this as an opportunity to return <code>false</code> when you're certain that the transition to the new props and state will not require a component update.</p>
</li>
<li class="description" id="componentWillUpdate">
<h2 class="heading heading--2">componentWillUpdate</h2>
<p>Invoked immediately before rendering when new props or state are being received. This method is not called for the initial render.</p>
<p>Use this as an opportunity to perform preparation before an update occurs.</p>
</li>
<li class="description" id="componentDidUpdate">
<h2 class="heading heading--2">componentDidUpdate</h2>
<p>Invoked immediately after the component's updates are flushed to the DOM. This method is not called for the initial render.</p>
<p>Use this as an opportunity to operate on the DOM when the component has been updated.</p>
</li>
<li class="description" id="componentWillUnmount">
<h2 class="heading heading--2">componentWillUnmount</h2>
<p>Invoked immediately before a component is unmounted from the DOM.</p>
<p>Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM elements that were created in <code>componentDidMount</code>.</p>
</li>
<li class="description description--placeholder">
<h2 class="heading heading--2">React components lifecycle diagram</h2>
<p>Click on a method to see a description.</p>
<p>Taken from the <a href="https://facebook.github.io/react/docs/component-specs.html#lifecycle-methods">React documentation page</a>, compiled by <a href="https://eduardoboucas.com">Eduardo Bouças</a>.</p>
</li>
<li class="description__close"><a href="#">×</a></li>
</ul>
<div class="lanes">
<ul class="lane">
<li class="lane__title">Mounting</li>
<li class="lane__item"><a class="step" href="#getInitialState">getInitialState</a></li>
<li class="lane__item"><a class="step" href="#getDefaultProps">getDefaultProps</a></li>
<li class="lane__item"><a class="step" href="#componentWillMount">componentWillMount</a></li>
<li class="lane__item"><a class="step" href="#render">render</a></li>
<li class="lane__item"><a class="step" href="#componentDidMount">componentDidMount</a></li>
</ul>
<ul class="lane">
<li class="lane__title">Updating</li>
<li class="lane__item"><a class="step" href="#componentWillReceiveProps">componentWillReceiveProps</a></li>
<li class="lane__item"><a class="step" href="#shouldComponentUpdate">shouldComponentUpdate</a></li>
<li class="lane__item"><a class="step" href="#componentWillUpdate">componentWillUpdate</a></li>
<li class="lane__item"><a class="step" href="#render">render</a></li>
<li class="lane__item"><a class="step" href="#componentDidUpdate">componentDidUpdate</a></li>
</ul>
<ul class="lane">
<li class="lane__title">Unmounting</li>
<li class="lane__item"><a class="step" href="#componentWillUnmount">componentWillUnmount</a></li>
</ul>
</div>
$colour-accent: #61dafb;
$colour-background: #222;
$colour-background-shade-2: #2d2d2d;
p {
margin-top: 20px;
line-height: 1.6;
}
a {
color: $colour-accent;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
code {
background-color: $colour-background;
font-family: Monaco, monospace;
font-size: 0.9em;
padding: 5px;
}
.logo {
display: block;
margin: 30px auto 0 auto;
width: 100px;
height: 100px;
}
.heading {
margin-bottom: 0.5em;
}
.heading--2 {
font-size: 30px;
}
.lanes {
display: inline-block;
}
.lane {
padding: 50px 0;
text-align: left;
}
.lane + .lane {
border-top: 1px solid white;
}
.lane__title {
display: inline-block;
color: white;
margin-right: 10px;
font-size: 12px;
width: 80px;
text-align: right;
}
.lane__item {
display: inline-block;
margin-right: -4px;
& + & {
&:before {
content: '➞';
color: white;
font-size: 1em;
vertical-align: middle;
margin: 0 0.5em;
}
}
}
.step {
display: inline-block;
color: $colour-accent;
text-decoration: none;
font-size: 15px;
border: 3px solid $colour-accent;
border-radius: 10px;
padding: 15px;
transition: all 0.1s ease-out;
&:hover {
background-color: $colour-accent;
color: black;
text-decoration: none;
}
}
.descriptions {
position: relative;
background-color: $colour-background-shade-2;
color: white;
padding: 20px;
border-radius: 10px;
min-height: 100px;
max-width: 730px;
margin: 40px auto;
}
.description {
display: none;
&:target,
&--placeholder {
display: block;
}
&:target ~ &--placeholder {
display: none;
}
&:target ~ &__close {
display: block;
}
&:not(.description--placeholder) {
text-align: left;
}
}
.description__close {
position: absolute;
top: 15px;
right: 15px;
font-size: 25px;
transition: opacity 0.2s ease-out;
display: none;
}
body {
background-color: $colour-background;
font-family: 'Montserrat', sans-serif;
text-align: center;
}
Also see: Tab Triggers