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.
<button class="toggle-scheme">
<span class="toggle-scheme__icon toggle-scheme__icon--main"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill="none" d="M0 0h24v24H0z"></path>
<path d="M12 21.9966C6.47715 21.9966 2 17.5194 2 11.9966C2 6.47373 6.47715 1.99658 12 1.99658C17.5228 1.99658 22 6.47373 22 11.9966C22 17.5194 17.5228 21.9966 12 21.9966ZM12 19.9966C16.4183 19.9966 20 16.4149 20 11.9966C20 7.5783 16.4183 3.99658 12 3.99658C7.58172 3.99658 4 7.5783 4 11.9966C4 16.4149 7.58172 19.9966 12 19.9966ZM7.00035 15.3158C9.07995 15.1645 11.117 14.2938 12.7071 12.7037C14.2972 11.1136 15.1679 9.07654 15.3193 6.99694C15.6454 7.21396 15.955 7.46629 16.2426 7.75394C18.5858 10.0971 18.5858 13.8961 16.2426 16.2392C13.8995 18.5824 10.1005 18.5824 7.75736 16.2392C7.46971 15.9516 7.21738 15.642 7.00035 15.3158Z" fill="rgba(0,0,0,1)"></path>
</svg></span>
<span class="toggle-scheme__icon toggle-scheme__icon--alt"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path fill="none" d="M0 0h24v24H0z"></path>
<path d="M12 21.9966C6.47715 21.9966 2 17.5194 2 11.9966C2 6.47373 6.47715 1.99658 12 1.99658C17.5228 1.99658 22 6.47373 22 11.9966C22 17.5194 17.5228 21.9966 12 21.9966ZM5.32889 16.4219C6.76378 18.5674 9.20868 19.9801 11.9836 19.9801C16.4018 19.9801 19.9836 16.3984 19.9836 11.9801C19.9836 9.20518 18.5707 6.76021 16.4251 5.32535C17.2705 8.35312 16.5025 11.7367 14.1213 14.118C11.7401 16.4992 8.3566 17.2671 5.32889 16.4219Z" fill="var(--black)"></path>
</svg></span>
</button>
/* Code For Switch */
.toggle-scheme {
background: none;
border: none;
cursor: pointer;
font-size: 24px;
display: flex;
}
.toggle-scheme__icon {
width: 24px;
height: 24px;
}
.toggle-scheme__icon--alt {
width: 24px;
height: 24px;
display: none;
}
/* End Code For Switch */
.content {
padding: 20px;
}
:root {
--black: #000;
--white: #fff;
}
body {
background-color: var(--white);
}
.color-scheme--alt {
--black: #fff;
--white: #000;
}
document.addEventListener("DOMContentLoaded", function () {
const toggleButton = document.querySelector(".toggle-scheme");
const mainIcons = document.querySelectorAll(".toggle-scheme__icon--main");
const altIcons = document.querySelectorAll(".toggle-scheme__icon--alt");
// Get user preference from local storage
const userPreference = localStorage.getItem("prefers-color-scheme");
// Set the initial color scheme based on user preference
if (userPreference === "alt") {
document.documentElement.classList.add("color-scheme--alt");
toggleIcons(mainIcons, "none");
toggleIcons(altIcons, "inline");
} else {
document.documentElement.classList.remove("color-scheme--alt");
toggleIcons(mainIcons, "inline");
toggleIcons(altIcons, "none");
}
// Toggle color scheme when button is clicked
toggleButton.addEventListener("click", function () {
const currentScheme = document.documentElement.classList.contains(
"color-scheme--alt"
)
? "alt"
: "main";
if (currentScheme === "main") {
document.documentElement.classList.add("color-scheme--alt");
localStorage.setItem("prefers-color-scheme", "alt");
toggleIcons(mainIcons, "none");
toggleIcons(altIcons, "inline");
} else {
document.documentElement.classList.remove("color-scheme--alt");
localStorage.setItem("prefers-color-scheme", "main");
toggleIcons(mainIcons, "inline");
toggleIcons(altIcons, "none");
}
});
// Helper function to toggle the display of elements with a given class
function toggleIcons(elements, displayValue) {
elements.forEach(function (element) {
element.style.display = displayValue;
});
}
});
Also see: Tab Triggers