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.
<main>
<img src="https://assets.codepen.io/3174/t-rex.png?width=448&height=448&format=webp&quality=50" alt="T-rex, drawn in pixel art" />
<div>I'm enough just as I am.</div>
</main>
<footer>
<button>Generate affirmation</button>
<p><small>Crafted with <span>♥</span> by <a href="https://chrisnager.com">Chris Nager</a> <br>on October 14, 2023</small></p>
</footer>
body {
background-color: pink;
background-color: color(display-p3 1 0.875 0.925);
box-sizing: border-box;
display: grid;
font-family: ui-system, sans-serif;
grid-template-rows: 1fr auto;
height: 100dvh;
margin: 0;
padding: 12vh 1rem 2rem;
text-align: center;
}
main {
max-width: 42rem;
margin-inline: auto;
}
img {
aspect-ratio: 1;
display: block;
margin-inline: auto;
max-width: 14rem;
user-select: none;
}
div {
font-family: Georgia, serif;
font-size: 1.75rem;
font-size: clamp(1.75rem, 4vw, 2.25rem);
text-wrap: balance;
}
main:has(+ footer > button:active) > :is(div, img) {
mix-blend-mode: color-burn;
filter: brightness(90%);
}
button {
background-color: white;
border: 0.125rem solid;
border-radius: 0.5rem;
color: blue;
color: color(display-p3 0.25 0.25 1);
font-size: inherit;
font-weight: 600;
padding: 0.5rem;
user-select: none;
}
button:active {
color: navy;
}
footer {
margin-block-start: 3rem;
}
p {
margin-block-start: 3rem;
margin-block-end: 0;
}
span {
color: red;
color: color(display-p3 1 0 0);
}
a {
color: inherit;
text-underline-offset: 0.125rem;
}
const affirmations = {
1: "I'm deserving of love and respect.",
2: "I'm growing and evolving every day.",
3: "I'm in control of my happiness.",
4: "I'm capable of achieving my goals.",
5: "I'm worthy of all the good things that happen in my life.",
6: "I'm resilient and can get through tough times.",
7: "I'm free to create the life I desire.",
8: "I'm loved and supported by those around me.",
9: "I'm strong and independent.",
10: "I'm constantly improving and bettering myself.",
11: "I'm surrounded by abundance.",
12: "I'm full of potential and endless possibilities.",
13: "I'm in charge of my life and no one else's.",
14: "I'm worthy of my dreams and aspirations.",
15: "I'm a positive thinker and only attract positivity.",
16: "I'm open to new adventures in my life.",
17: "I'm deserving of financial stability.",
18: "I'm not defined by my mistakes.",
19: "I'm filled with endless creativity.",
20: "I'm a kind and loving person.",
21: "I'm proud of all I have achieved.",
22: "I'm not my past or my imperfections.",
23: "I'm deserving of everything good that comes my way.",
24: "I'm constantly learning and growing.",
25: "I'm enough just as I am.",
26: "I'm a magnet for success and prosperity.",
27: "I'm focused and persistent.",
28: "I'm deserving of love, just as everyone else.",
29: "I'm not alone in my struggles.",
30: "I'm braver than I believe.",
31: "I'm a beacon of love and compassion.",
32: "I'm deserving of the time and space to heal.",
33: "I'm able to achieve greatness.",
34: "I'm always headed in the right direction.",
35: "I'm worthy of love, compassion, and empathy.",
36: "I'm not defined by the opinions of others.",
37: "I'm deserving of all the beauty life offers.",
38: "I'm able to overcome any challenges that come my way.",
39: "I'm always doing my best and that's enough.",
40: "I'm deserving of respect and kindness.",
41: "I'm in charge of my destiny.",
42: "I'm powerful and capable of great things.",
43: "I'm surrounded by people who believe in me.",
44: "I'm a unique and special individual.",
45: "I'm deserving of all the happiness in the world.",
46: "I'm stronger than any obstacle in front of me.",
47: "I'm constantly growing and developing.",
48: "I'm worthy of respect and admiration.",
49: "I'm deserving of my place in the world.",
50: "I'm living my best life every single day.",
51: "I'm worthy of success and prosperity.",
52: "I'm open to love and kindness.",
53: "I'm a beacon of light and hope.",
54: "I'm loved by those around me.",
55: "I'm creating the life I deserve.",
56: "I'm deserving of peace and tranquility.",
57: "I'm a powerful creator.",
58: "I'm loved and supported by the universe.",
59: "I'm deserving of happiness and joy.",
60: "I'm in charge of how I feel.",
61: "I'm proud of who I am.",
62: "I'm loved and cherished.",
63: "I'm a magnet for love and positivity.",
64: "I'm stronger than I think.",
65: "I'm living my best life right now."
};
const affirmationDiv = document.getElementsByTagName("div")[0];
const affirmationButton = document.getElementsByTagName("button")[0];
function displayRandomAffirmation() {
const randomIndex =
Math.floor(Math.random() * Object.keys(affirmations).length) + 1;
affirmationDiv.innerText = affirmations[randomIndex];
}
affirmationButton.addEventListener("click", displayRandomAffirmation);
Also see: Tab Triggers