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.
<div id="wrapper"><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" viewBox="0 0 650 590" width="635" height="550" id="vday" role="img">
<title>Large red heart with text that says Bee my valentine?</title>
<g id="heart">
<path d="M 297.29747,550.86823 C 283.52243,535.43191 249.1268,505.33855 220.86277,483.99412 C 137.11867,420.75228 125.72108,411.5999 91.719238,380.29088 C 29.03471,322.57071 2.413622,264.58086 2.5048478,185.95124 C 2.5493594,147.56739 5.1656152,132.77929 15.914734,110.15398 C 34.151433,71.768267 61.014996,43.244667 95.360052,25.799457 C 119.68545,13.443675 131.6827,7.9542046 172.30448,7.7296236 C 214.79777,7.4947896 223.74311,12.449347 248.73919,26.181459 C 279.1637,42.895777 310.47909,78.617167 316.95242,103.99205 L 320.95052,119.66445 L 330.81015,98.079942 C 386.52632,-23.892986 564.40851,-22.06811 626.31244,101.11153 C 645.95011,140.18758 648.10608,223.6247 630.69256,270.6244 C 607.97729,331.93377 565.31255,378.67493 466.68622,450.30098 C 402.0054,497.27462 328.80148,568.34684 323.70555,578.32901 C 317.79007,589.91654 323.42339,580.14491 297.29747,550.86823 z" />
</g>
<g id="message" aria-hidden="true"><text x="150" y="200" id="beemy">Bee My</text><text x="110" y="300" id="val">Valentine?</text>
</g>
</svg><img id="bee" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Abeille-bee.svg" alt="">
<br><br>
<h2>
<a target="_blank" href="https://codepen.io/cariefisher/pen/abVyvOd">Go to step 4</a>
</h2>
</div>
/* Let's take out the inline styles from the original SVG and add them to a CSS file. Doing this will give us more control over the look and feel of the SVG, plus it allows us to create a reverse design using prefers-color-scheme media query. To simplify things for later on, let's rename the IDs to easily know what we are modifying.
There are a lot of styling options for SVGs...too many to list at least in this CodePen! Check out this article on "SVG Properties and CSS" by Katherine Kato for more details about currently supported options, plus some future SVG 2 options : https://css-tricks.com/svg-properties-and-css/
Note: you can create either a dark theme or a light theme - it just depends on what theme you start with as to what the alternate experience is. Keep in mind - both experiences need to meet WCAG color contrast ratio guidelines. One theme cannot just be your "accessible" theme and the other your "regular" theme. All experiences need to be inclusive.
Can I Use: https://caniuse.com/?search=prefers-color-scheme */
@import url("https://fonts.googleapis.com/css2?family=Open+Sans&family=Parisienne&display=swap");
body {
font-family: "Parisienne", cursive;
margin: 2rem;
}
a {
color: #000000;
text-decoration: underline;
margin-left: 2rem;
font-family: "Open Sans", sans-serif;
}
#wrapper {
position: relative;
width: 650px;
height: 590px;
}
/* heart */
#heart {
fill: #ff0000;
stroke: #000000;
stroke-width: 15;
stroke-dasharray: 1, 30;
stroke-linecap: round;
}
/* text */
#message {
fill: #000000;
font-size: 6rem;
font-weight: bold;
}
/* bee */
#bee {
width: 200px;
position: absolute;
bottom: 23%;
left: 33%;
}
/* CSS + animation for default / light mode theme */
@media (prefers-color-scheme: dark) {
body {
background: #000000;
}
a {
color: #ffffff;
text-decoration: underline;
}
#heart {
stroke: #ffffff;
}
#message {
fill: #ffffff;
}
}
Also see: Tab Triggers