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.
<header>
<!-- This headline is a single phrase! Using generic span elements provides a way to maintain semantic integrity, but introduce "extra" elements for design flexibility -->
<h1 class="box">
<span class="flush-right bg-nudge">The</span>
<span class="sm-nudge">web’s</span>
<span class="flush-right">deepest</span>
<span>mystery</span>
</h1>
<h2>How one teenage whiz kid set out to solve the puzzle of cicada, and found himself in a world of international intrigue</h2>
<h3><strong>By David Kushner</strong><em>Illustration by Sean M<span class="lc">c</span>Cabe</em></h3>
</header>
<p class="box"><em>Marcus Wanner needed</em> a little adventure in his life. A skinny 15-year-old brainiac with wire-frame glasses and wavy brown hair, he was the eldest of five, home-schooled by their mother, a devout Catholic, near Roanoke, Virginia. Shuttling Marcus between home, church and the Boy Scouts seemed like the best way to keep him away from trouble (and girls). <q>I missed out on a lot,</q> he recalls with a sigh. <q>I didn’t get out much.</q> ¶ Though Marcus was gifted with computers, his mom and dad, an electrical engineer, also locked him down online. He couldn’t send an e-mail or register on a website without their permission. To make sure he was abiding, he was restricted to the living-room computer, which they could see. <q>It was the Big-Brother-eye-over-the-shoulder thing,</q> he says. But his parents only had so much power. <q>There was no way we could check what he was up to if he covered his tracks,</q> his mother admits. <q>He’s light-years ahead of us.</q> Marcus was a good kid, dependable, hardworking, the leader of his Boy Scout troop, just a project away from Eagle Scout. But he could only take so much. <q>Until a point, I tried to go with the flow,</q> he says. <q>And then I was like, <q>Aw, fuck it.</q></q>
</p>
<!-- NOTE: Many true typographic symbols: quotations, apostrophes, the paragraph mark should be input as coded HTML "entities" SEE: https://css-tricks.com/snippets/html/glyphs/ -->
@import url(https://fonts.googleapis.com/css?family=Oswald:700,300);
/*RESET! */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
/*
First just get the basic type styling done. Just the essentials.
*/
h1,
h2,
h3 {
text-transform: uppercase;
font-family: 'Oswald';
font-weight: 300;
}
.lc {
text-transform: none;
}
h1,
strong {
font-weight: 700;
}
/*
Now address font sizing, overall width, and typographic heirarchy
*/
h1 {
font-size: 200px;
letter-spacing: -10px;
line-height:.9;
}
h2 {
width: 300px;
font-size: 28px;
}
h3 {
font-size: 20px;
width: 200px;
line-height: 1.3;
}
h3 strong {
display: block;
font-size: 32px;
}
h3 em{
display:inline-block;
width: 80%;
}
/*
Now, we can begin to think about polishing the layout NOTE: I like to use the "outline" trick to visualize the CSS boxes
*/
.box{
outline: 1px solid red;
}
/*
The headline is pretty easy if we use <span>'s as block level elements to isolate each word then simply use text-align and a few custom classes (and an advanced selector) to really tweak everything.
*/
h1 span {
display: block;
}
h1 span:last-child {
color: indigo;
}
.flush-right {
text-align: right;
}
.bg-nudge {
margin-right: 183px;
}
.sm-nudge {
margin-left: 60px;
}
/*
With a "grouping" parent container in place to define the width of our layout we can use positioning to carefully craft a precise layout.
*/
header {
width: 800px;
margin: auto;
}
/*NOTE! The "Trick" is to explicitly set postitoning on the parent element <header> so all of it's children <h2,h3> come along for the ride. (SEE https://css-tricks.com/absolute-positioning-inside-relative-positioning/) */
header {
position: relative;
}
h2,
h3 {
position: absolute;
}
/*Forget "margin and padding" and just remember "TRouBLe" (top: left: bottom: and right:) to place the "position absolute" children where they belong realtive to their parent's origin'
*/
h2 {
top: 190px;
left: 520px;
/* it's okay to keep tweaking when needed'*/
line-height: 34px;
}
h3 {
top: 390px;
left: -20px;
/* don't forget text-align as a layout tool!*/
text-align: right;
}
h3 strong {
padding-bottom: 20px;
line-height: 1;
}
/*
A bottom-border is what you want, but it will be full width of the h3, so instead we use an "empty" psuedo element to "draw" a line with another CSSbox allowing us the freedomw to size, color, and position it exactly where we want.
*/
h3 strong::before {
content: "";
height: 3px;
width: 50px;
background-color: black;
position: absolute;
right: 0;
top: 72px;
}
p {
font-family: Georgia;
font-size: 18px;
line-height: 28px;
}
p em {
text-transform: uppercase;
font-style: normal;
}
/* quotes */
q {
quotes: '“' '”' '‘' '’';
}
q:before {
content: open-quote;
}
q:after {
content: close-quote;
}
/*drop cap with clever selector*/
p:first-letter {
font-size: 300px;
line-height: 260px;
font-family: 'Oswald';
font-weight: 700;
float: left;
margin-right: 20px;
text-shadow: 16px 8px 0 white, 20px 10px 0 black;
;
}
/*COLOPHON: (creating the stripes)
For what it's worth, I'd add a similar border-top+psuedo element trick to top the first paragraph since it's narrow width is the determining factor in the look of this layout*/
p {
/*explicity set positioning as a the parent*/
position: relative;
width: 500px;
margin: auto;
border-top: 8px double black;
margin-top: 50px;
padding-top: 50px;
}
p:before,
p:after {
/*absolutely position these "children"*/
position: absolute;
content: "";
width: 100%;
border-top: 8px double black;
}
p:before {
top: -18px;
left: 0;
}
p:after {
top: -28px;
left: 0;
}
/*Adding the final touch form the print layout sans-page number*/
p {
padding-bottom: 20px;
border-bottom: 3em solid black;
}
/*A small "reset" touch to help visualize the lesson by getting it away from the edges of the browser window*/
body {
padding: 50px 0;
}
Also see: Tab Triggers