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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<dl id="moons">
<dt><a href="#titan">Titan</a>
<dd id="titan"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/titan.jpg" alt="Titan"><p>Saturn's largest moon is unique in several respects: it is the only known satellite in the solar system to have a dense atmosphere (one primarily composed of nitrogen), and the only known to have lakes on its surface (as it is far too cold to support liquid water, these bodies are liquid methane).<p>Titan was discovered in 1655 by the Dutch astronomer Christiaan Huygens. Today, the moon is considered by many scientists to be a possible habitat for non-terrestrial life. Its atmosphere is similar to that of the early Earth, and the potential of an "underground sea" of liquid water, along with tantalizing chemical imbalances in the atmosphere and crust, suggest that simple life may be present, operating in a methane, rather than water-based, environment.
<dt>
<a href="#iapetus">Iapetus</a>
<dd id="iapetus">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/iapetus.jpg" alt="Iapetus">
<p>Iapetus, the third largest moon of Saturn, is fascinating both tonally and morphologically: its stretched shape and equatorial ridge cause it to resemble nothing so much as a walnut, while the extreme difference in albedo between one hemisphere and the other bring to mind an Oreo cookie. It also has a significant crater, Turgis, that is nearly 40% of the moon's diameter, with a rim scarp that towers 15 kilometres high.
<dt>
<a href="#mimas">Mimas</a>
<dd id="mimas">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/mimas.jpg" alt="Mimas">
<p>Mimas was discovered by William Hershel, the same year as <a href="#enceladus">Enceladus</a>. The most remarkable feature of Mimas is its massive primary impact crater, which from certain angles causes the moon to look very much like the Death Star. The crater, named after its discoverer, is over 130 kilometres across: if a crater of equivalent scale was formed on Earth, it would be wider than Canada.<p>Mimas is also remarkable for the fact that it is the smallest object in the solar system to have formed into a sphere under the influence of its own self-gravitation.
<dt>
<a href="#enceladus">Enceladus</a><dd id="enceladus">
<img alt="Enceladus" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/enceladus.jpg">
<p>Discovered by Fredrick William Herschel in 1789, tiny Enceladus is one of only four known bodies in the outer solar system with active volcanoes, the other three being the moons of <a href="http://en.wikipedia.org/wiki/Io_moon">Io</a>, <a href="http://en.wikipedia.org/wiki/Triton_moon">Triton</a> and possibly <a href="https://en.wikipedia.org/wiki/Titan_(moon)">Titan</a>. In the case of Enceladus, these are cryovolcanoes: eruptions of water, nitrogen and ammonia, rather than molten rock.<p>Just 500 kilometres in diameter, Enceladus is far too small to generate its own heat. Instead, its geological activity is mostly likely caused by its orbit around Saturn, with the gas giant constantly pulling and squeezing on the small satellite, warming the interior of the moon.<p>As a source of water, Enceladus is conjectured to harbour life, while also being the wellspring for the ice crystal content of Saturn's <a href="http://en.wikipedia.org/wiki/Rings_of_Saturn#E_Ring">E ring</a>.
</dl>
$bgcolor: #222;
* {
box-sizing: border-box;
}
body {
margin: 3rem;
background: $bgcolor;
@media all and (max-width: 850px) {
margin: 0;
}
}
dl#moons {
line-height: 1.5;
font-family: Avenir, sans-serif;
position: relative;
width: 50rem;
@media all and (max-width: 850px) {
width: 100%;
}
dt {
display: inline-block;
margin-right: .5rem;
@media all and (max-width: 550px) {
margin-right: 0;
width: 25%;
}
position: relative;
z-index: 5;
a {
text-decoration: none;
color: #fff;
padding: 1rem;
@media all and (max-width: 550px) {
padding: .5rem;
}
border: 1px solid black;
background: #555;
display: block;
min-width: 8rem;
font-weight: 600;
border-radius: 10px 10px 0 0;
&:hover, &:focus {
background: #222;
}
&:visited {
background: #aaa;
}
.active {
background: #222;
}
}
}
dd {
position: absolute;
left: 0;
margin-left: 0;
top: 0;
padding: 2rem 1rem 1rem 1rem;
border-top: 3.6rem solid $bgcolor;
@media all and (max-width: 550px) {
border-top-width: 2rem;
}
width: 100%;
background: #000;
color: white;
opacity: 0;
transition: .3s opacity;
a {
color: white;
}
img {
max-width: 100%;
float: right;
margin: 1rem;
shape-outside: circle();
}
}
}
dd#titan:target, dd#iapetus:target, dd#enceladus:target,dd#mimas:target {
z-index: 4;
opacity: 1;
}
document.querySelector('a[href="#titan"]').click();
Also see: Tab Triggers