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.
<!-- Done: Add underlines back for Windows High Contrast Mode -->
<!-- To-do: Dump first two experiments -->
<!-- To-do: Use <main> as content container, re-lay-out all -->
<!-- To-do: Adjust styles to not affect nav areas, using :has() and brute force -->
<!-- To-do: Print styles, including URL expansion -->
<!-- To-do: Better :target styles -->
<!-- To-do: Standard comments on colors for faster replace (no pre-processing) -->
<!-- To-do: <small> and small-caps -->
<!-- To-do: Evaluate other generated content hints -->
<!-- To-do: Decide between PDF icon or just text hint -->
<!-- To-do: Browser testing (particularly the line weight, may have to use px) -->
<main>
<section>
<div>
<h2>Default Link Styles</h2>
<p>
<a href="nerfherder"><img src="https://2.bp.blogspot.com/-7Cb-oJKZW1U/Tb7EWjVDRzI/AAAAAAAAAdw/Q4UBfWH4s_w/s320/HTML5_Logo_128.png" alt="HTML5 logo"></a>
Sometimes a link is an image, like this one (probably to the right). But <a name="foo">this is an anchor</a>. <a href="#Anchor">This is a link to an anchor</a>.
</p>
<p>
Sometimes a link appears with an acronym, <a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a>.
</p>
<p>
Maybe the link has descenders, like in the <a href="nerfherder">quirky words “thingamajiggery piddly</a> bits.”
</p>
<p>
Sub-script and super-script get links too, <a href="nerfherder">like H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a> or <a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a>.
</p>
<p>
<a href="http://cnn.com">This link takes you off this site</a>, so I'm trying an SVG generated content icon. This is a <a href="foo.pdf">test PDF link</a>.
</p>
</div>
<aside>
<h2>Block Links</h2>
<ul>
<li><a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a></li>
<li><a href="nerfherder">quirky thingamajiggery piddly bits</a></li>
<li><a href="nerfherder">H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a></li>
<li><a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a></li>
<li><a href="http://cnn.com">This link takes you away from this site</a></li>
</ul>
</aside>
</section>
<section>
<div>
<h2>Text Shadow Link Styles (First Pass)</h2>
<p>
<a href="nerfherder"><img src="https://2.bp.blogspot.com/-7Cb-oJKZW1U/Tb7EWjVDRzI/AAAAAAAAAdw/Q4UBfWH4s_w/s320/HTML5_Logo_128.png" alt="HTML5 logo"></a>
Sometimes a link is an image, like this one (probably to the right). But <a name="foo">this is an anchor</a>. <a href="#Anchor">This is a link to an anchor</a>.
</p>
<p>
Sometimes a link appears with an acronym, <a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a>.
</p>
<p>
Maybe the link has descenders, like in the <a href="nerfherder">quirky words “thingamajiggery piddly</a> bits.”
</p>
<p>
Sub-script and super-script get links too, <a href="nerfherder">like H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a> or <a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a>.
</p>
<p>
<a href="http://cnn.com">This link takes you off this site</a>, so I'm trying an SVG generated content icon. This is a <a href="foo.pdf">test PDF link</a>.
</p>
</div>
<aside>
<h2>Block Links</h2>
<ul>
<li><a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a></li>
<li><a href="nerfherder">quirky thingamajiggery piddly bits</a></li>
<li><a href="nerfherder">H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a></li>
<li><a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a></li>
<li><a href="http://cnn.com">This link takes you away from this site</a></li>
</ul>
</aside>
</section>
<section>
<div>
<h2> Simpler Text Shadow Link Styles</h2>
<p>
<a href="nerfherder"><img src="https://2.bp.blogspot.com/-7Cb-oJKZW1U/Tb7EWjVDRzI/AAAAAAAAAdw/Q4UBfWH4s_w/s320/HTML5_Logo_128.png" alt="HTML5 logo"></a>
Sometimes a link is an image, like this one (probably to the right). But <a name="foo">this is an anchor</a>. <a href="#Anchor">This is a link to an anchor</a>.
</p>
<p>
Sometimes a link appears with an acronym, <a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a>.
</p>
<p>
Maybe the link has descenders, like in the <a href="nerfherder">quirky words “thingamajiggery piddly</a> bits.”
</p>
<p>
Sub-script and super-script get links too, <a href="nerfherder">like H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a> or <a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a>.
</p>
<p>
<a href="http://cnn.com">This link takes you off this site</a>, so I'm trying an SVG generated content icon. This is a <a href="foo.pdf">test PDF link</a>.
</p>
</div>
<aside>
<h2>Block Links</h2>
<ul>
<li><a href="nerfherder">like <abbr title="Not Safe for Work">NSFW</abbr></a></li>
<li><a href="nerfherder">quirky thingamajiggery piddly bits</a></li>
<li><a href="nerfherder">H<sub>2</sub>SO<sub>4</sub> and then log<sub>n</sub></a></li>
<li><a href="nerfherder">9<sup>th</sup> and 6.022 × 10<sup>23</sup></a></li>
<li><a href="http://cnn.com">This link takes you away from this site</a></li>
</ul>
</aside>
</section>
<p id="Anchor">
Demo anchor to test <code>:target</code> styles.
</p>
</main>
/* To-Do: Remove text-shadow on select */
@import url(https://fonts.googleapis.com/css?family=Oswald);
@import url(https://fonts.googleapis.com/css?family=Merriweather:400,700,700italic,400italic);
body {
background-color: #6D695C;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACVBMVEUAAAAAAAAAAACDY+nAAAAAA3RSTlMmDQBzGIDBAAAAG0lEQVR42uXIIQEAAADCMHj/0NdkQMws0HEeAqvwAUGJthrXAAAAAElFTkSuQmCC);
font-size: 100%;
font-family: 'Merriweather', serif;
line-height: 1.4;
}
main, section, aside, div {
display: block;
box-sizing: border-box;
}
main > section {
background-color: #fff;
padding: .5em 1em;
background-image: linear-gradient(to right, #fff 0, #fff 69%, #ddd 69%, #ddd);
margin-bottom: 1em;
}
h1, h2, h3, h4, h5, h6 {
font-family: 'Oswald', sans-serif;
font-weight: 400;
}
section img {
float: right;
}
section::after {
content: "";
display: block;
clear: both;
}
section > div {
float: left;
width: 67%;
}
section > aside {
float: right;
width: 33%;
padding: 0 0 1em 1em;
font-family: 'Oswald', sans-serif;
}
aside h2 {
padding: 0 .6em;
}
aside ul {
margin: 0;
padding: 0;
list-style-type: none;
}
aside a[href] {
display: block;
margin: 1em 0;
padding: 0 1em;
}
sup, sub {
font-size: 75%;
line-height: 0;
}
abbr[title], acronym[title] {
border-bottom: 0.1em dotted rgba(0,0,0,.3);
cursor: help;
}
a[href] abbr[title], a[href] acronym[title] {
cursor: inherit;
}
a[href] {
color: #00c;
}
a[href]:hover, a[href]:focus {
color: #c00;
}
aside a[href] {
color: #c00;
}
aside a[href]:hover, aside a[href]:focus {
color: #00c;
}
/* Reverse-engineered from https://eager.io/blog/smarter-link-underlines/ */
main section:nth-child(2) a[href] {
text-decoration: none;
text-shadow: 0.03em 0 rgb(255,255,255), -0.03em 0 rgb(255,255,255), 0 0.03em rgb(255,255,255), 0 -0.03em rgb(255,255,255), 0.06em 0 rgb(255,255,255), -0.06em 0 rgb(255,255,255), 0.09em 0 rgb(255,255,255), -0.09em 0 rgb(255,255,255), 0.12em 0 rgb(255,255,255), -0.12em 0 rgb(255,255,255), 0.15em 0 rgb(255,255,255), -0.15em 0 rgb(255,255,255);
background-image: linear-gradient(rgb(255,255,255), rgb(255,255,255)), linear-gradient(rgb(255,255,255), rgb(255,255,255)), linear-gradient(rgb(24, 27, 67), rgb(24, 27, 67));
background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
background-repeat: no-repeat, no-repeat, repeat-x;
background-position: 0% 89%, 100% 89%, 0% 89%;*/
}
main section:nth-child(2) aside a[href] {
text-shadow: 0.03em 0 #ddd, -0.03em 0 #ddd, 0 0.03em #ddd, 0 -0.03em #ddd, 0.06em 0 #ddd, -0.06em 0 #ddd, 0.09em 0 #ddd, -0.09em 0 #ddd, 0.12em 0 #ddd, -0.12em 0 #ddd, 0.15em 0 #ddd, -0.15em 0 #ddd;
}
/* Fewer shadows, use currentColor */
main section:nth-child(3) a[href] {
text-decoration: none;
text-shadow: .07em 0 0 #fff, -.07em 0 0 #fff, 0 .05em 0 #fff;
background-image: linear-gradient(to right, currentColor 0%, currentColor 100%);
background-repeat: repeat-x;
background-position: 0 93%;
-webkit-background-size: 100% .07em;
background-size: 100% .07em;
}
main section:nth-child(3) aside a[href] {
text-shadow: .07em 0 0 #ddd, -.07em 0 0 #ddd, 0 .05em 0 #ddd;
}
main section:nth-child(3) a[href]::selection, main section:nth-child(3) aside a[href]::selection {
text-shadow: none;
/*background: transparent;*/
}
/* Support users of high contrast mode by restoring underlines */
@media screen and (-ms-high-contrast: active) {
main section:nth-child(2) a[href], main section:nth-child(3) a[href] {
text-decoration: underline;
}
}
/* Generated content via SVG icons */
main section:nth-child(3) a[href^="http://"]::after, main section:nth-child(3) a[href^="https://"]::after {
/*content: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMC42IiBoZWlnaHQ9Ijc4LjEiIHZpZXdCb3g9IjAgMCAxMDAuNiA3OC4xIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAxMDAuNjI1IDc4LjEyNSIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZmlsbD0iIzAxMDEwMSIgZD0iTTc1LjIgNjguMWgtNjV2LTQ1aDEzYzAgMCAzLjQtNC41IDEwLjktMTBINS4yYy0yLjggMC01IDIuMi01IDV2NTVjMCAyLjggMi4yIDUgNSA1aDc1YzIuOCAwIDUtMi4yIDUtNVY1NC40bC0xMCA4LjJWNjguMXpNNjcgMzMuM3YxNy44bDMzLjItMjZMNjcgMC4xdjE1LjdjLTQwLjMgMC00MC4zIDM5LjgtNDAuMyAzOS44QzM4LjEgMzYuOSA0NS4xIDMzLjMgNjcgMzMuM3oiLz48L3N2Zz4=);*/
/*content: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2729/href_new-win_ems.svg);*/
content: "";
display: inline-block;
height: .5em;
width: .75em;
margin-left: .2em;
/*border: 1px dotted #f00;*/
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2729/href_new-win.svg);
background-position: 0 100%;
background-repeat: no-repeat;
background-size: contain;
}
main section:nth-child(3) a[href^="http://"]::after, main section:nth-child(3) a[href^="https://"]::after, main section:nth-child(3) a[href^="http://"]::after path, main section:nth-child(3) a[href^="https://"]::after path {
fill: #f00;
}
.SVGnewwin {
height: .75em;
width: auto;
fill: #f00;
}
.SVGnewwin path {
fill: #f00;
}
main section:nth-child(3) a[href$=".pdf"]::after {
content: " (PDF)";
/*display: inline-block;
height: .75em;
width: 1em;
margin-left: .2em;
background-position: 0 100%;
background-repeat: no-repeat;
background-size: contain;
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/2729/pdf.svg); */
}
/* Style an anchor when it has been navigated to */
@keyframes Target {
from { background-color: rgba(255, 242, 0, 1); }
to { background-color: rgba(255, 242, 0, 0); }
}
@-webkit-keyframes Target {
from { background-color: rgba(255, 242, 0, 1); }
to { background-color: rgba(255, 242, 0, 0); }
}
:target {
/*background-color: rgba(255, 242, 0, 1);*/
-webkit-animation: Target 1s ease-out 1;
animation: Target 1s ease-out 1;
}
/* Just in case I need it, since it has slightly better support than the Subject of a selector with Child combinator (E! > F) rule (none) */
a[href]:has( > img)) {
background-image: none;
/*border: 3px dotted #f00;*/
}
Also see: Tab Triggers