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.
//- The inline SVG graph is generated dynamically in Jade, based on JSON-formatted data. This makes it possible to generate a static illustration (as opposed to using a JS library that modifies the DOM on the client), while preserving the original data in the source.
// originally developed for: https://explosion.ai/blog/spacy-user-survey
// inspired by: https://css-tricks.com/how-to-make-charts-with-svg/
//- Graph data as JSON
- var graph = { title: "Do you use spaCy at work?", data: [ { label: "Yes, we use it in production.", value: 0.20, segment: 0.18 }, { label: "Yes, we use it in development.", value: 0.13, segment: 0.12 }, { label: "Yes, we use it for research.", value: 0.31, segment: 0.18 }, { label: "No, but we're planning to.", value: 0.17, segment: 0.14 }, { label: "No, and we're currently not planning to.", value: 0.14, segment: 0.14 } ], segments: { value: "everyone", segment: "non-researchers" } }
//- Settings
- bar_height = 30
- label_height = 40
- legend_height = 20
- spacing = 10
- bars = graph.data.length
- width = 800
- height = bars * (bar_height + label_height + spacing) + (legend_height + 4 * spacing) * (graph.segments ? 2 : 0)
- fill_value = "#1e1935"
- fill_segment = "url(#pattern)"
//- Markup
figure.c-graph
figcaption.c-graph__title=graph.title
svg(version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="chart" width=width height=height role="img" viewBox="0 0 #{width} #{height}" preserveAspectRatio="xMinYMin meet")
defs
pattern#pattern(patternUnits="userSpaceOnUse" width="10" height="10")
image(xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMCIgaGVpZ2h0PSIxMCI+ICA8cmVjdCB3aWR0aD0iMTAiIGhlaWdodD0iMTAiIGZpbGw9IiMxRTE5MzUiLz4gIDxwYXRoIGQ9Ik0tMSwxIGwyLC0yICAgICAgICAgICBNMCwxMCBsMTAsLTEwICAgICAgICAgICBNOSwxMSBsMiwtMiIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjEuNSIvPjwvc3ZnPg==" x="0" y="0" width="10" height="10")
each bar, i in graph.data
- y = (bar_height + spacing) * i + label_height * (i + 1) + spacing
text.c-graph__label(x="0" y=(y - spacing))=bar.label
g.c-graph__value
- value = Math.round(bar.value * 100)
- dy = bar_height / 1.35
rect.c-graph__bar(width=(width / 100 * value) height=bar_height y=y fill=fill_value)
text.c-graph__number.c-graph__number--value(x=(width * value / 100 + spacing) y=y dy=dy)
if bar.value_label
| #{bar.value_label}
else
| #{value}%
if bar.segment && graph.segments
- segment = Math.round(bar.segment * 100)
g.c-graph__segment
rect.c-graph__bar(width=(width / 100 * segment) height=bar_height y=y fill=fill_segment)
text.c-graph__number(x=spacing y=y dy=dy)
if bar.segment_label
| #{bar.segment_label}
else
| #{segment}%
if graph.segments
g.c-graph__footer(x="0" y=(height - legend_height) height=legend_height dy=spacing)
- y_value = height - 2 * (legend_height + spacing)
- y_segment = height - legend_height - spacing
rect.c-graph__legend-value(y=y_value width=legend_height height=legend_height fill=fill_value)
text(x=(legend_height + spacing) y=y_value dy="1em")=graph.segments.value
rect.c-graph__legend-segment(y=y_segment width=legend_height height=legend_height fill=fill_segment)
text(x=(legend_height + spacing) y=y_segment dy="1em")=graph.segments.segment
$color-front: #1e1935
$color-back: #fff
$color-highlight: desaturate(lighten($color-front, 15), 5)
$font: "Poppins", Arial, sans-serif
.c-graph
max-width: 100%
padding: 25px
.c-graph__bar
cursor: pointer
transition: fill 0.15s ease
.c-graph__value:hover &,
.c-graph__segment:hover &
fill: $color-highlight
.c-graph__value:hover
.c-graph__number,
& + .c-graph__segment .c-graph__bar
fill: $color-highlight
.c-graph__number
cursor: pointer
font-weight: bold
transition: opacity 0.25s ease
.c-graph__value &
fill: $color-front
.c-graph__segment &
fill: $color-back
opacity: 0
.c-graph__segment:hover &
opacity: 1
.c-graph__value .c-graph__bar,
.c-graph__legend-value
fill: $color-front
.c-graph__title
font: bold 22px/#{1.375} $font
.c-graph__label
font: 16px $font
.c-graph__footer
font: 14px $font
.c-graph__number
font: bold 18px $font
// Demo container and reset
body
width: 100%
height: 100%
max-width: 100%
display: flex
justify-content: center
align-items: center
*
box-sizing: border-box
-webkit-font-smoothing: antialiased
border: 0
margin: 0
padding: 0
Also see: Tab Triggers