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.
<input type="checkbox" id="toggle" class="toggle sr-only" />
<div class="theme-container">
<label for="toggle">
<span>Switch light/dark mode</span>
</label>
<div class="container">
<h1>Switch from light to dark mode using the toggle(^_^)</h1>
<div class="node">
<p>Using the :checked pseudo-class selector, one can style descendants and subsequent siblings of a checkbox when it is in checked state.</p>
<p>Having both a checkbox for enabling dark mode and an element containing all other content on the page on the same level of the DOM tree allows us to offer a CSS-only dark mode of a web page.</p>
<p>macOS Mojave adds a Dark Mode for native apps that makes you look approximately 78 percent cooler when using the computer. In Safari Technology Preview 68, it’s now available on webpages too! Here’s how I added support to this website.</p>
<div class="action">
<button>More...</button>
</div>
</div>
</div>
</div>
@import url('//fonts.googleapis.com/css?family=Lato:400,400italic,700|Sansita+One');
@import url("https://fonts.googleapis.com/css?family=Merriweather:400,400i,700");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100vw;
min-height: 100vh;
}
body {
display: flex;
justify-content: center;
}
.theme-container {
flex: 1;
width: 100vw;
display: flex;
justify-content: center;
padding-top: 130px;
}
.container {
max-width: 80vw;
width: 60vw;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
font-family: "Sansita One", serif;
font-size: 2rem;
margin-bottom: 1vh;
}
.node {
&::before {
content: '';
float: left;
width: 546px;
height: 805px;
background: url('https://www.footyrenders.com/render/Neymar-45.png');
background-size: cover;
shape-outside: polygon(55px -1px, 9.57% 8.45%, 15.06% 17.15%, 0.41% 20.5%, -6.92% 29.07%, -22.67% 35.16%, -50.89% 41.37%, -75.8% 43.73%, -79.44% 49.93%, -58.94% 52.06%, -47.95% 47.33%, -3.26% 39.75%, -9.85% 47.7%, -39.52% 51.3%, -64.43% 58.76%, -73.59% 77.77%, -94.47% 84.85%, -93.73% 90.56%, -53.07% 84.1%, -40.26% 67.45%, 0.77% 67.58%, -8.42% 80.59%, -21.22% 90.42%, -20.84% 99.38%, -4.57% 97.33%, 13.13% 101.34%, 28.72% 94.26%, 43.75% 74.89%, 56.35% 62.5%, 76.74% 24.41%, 101.7% 17.48%, 101.87% 14.32%, 92.52% 11.73%, 74.31% 6.78%, 57.63% 1.97%);
shape-margin: 10px;
margin-left: -273px;
}
}
p {
font-family: Merriweather, serif;
font-size: 1.1rem;
line-height: 1.6rem;
margin: 1rem 0;
}
button {
-webkit-appearance: none;
background-color: transparent;
background-repeat: no-repeat;
background-image: linear-gradient(-60deg, #ff4cff 0%, #ff4cff 41.6%, #5bf390 41.6%, #5bf390 100%), linear-gradient(-60deg, #ff4cff 0%, #ff4cff calc(100% - 41.6%), #5bf390 calc(100% - 41.6%), #5bf390 100%);
background-position: 0 0, 0 100%, 0 0, 100% 0;
background-size: 100% 0.3em, 100% 0.3em, calc(100% + 0.6em) 100%, 100% calc(100% + 0.6em);
border: none;
border-left: 0.3em solid #5bf390;
border-right: 0.3em solid #ff4cff;
padding: 1.3em 2.8em;
line-height: 1;
overflow: hidden;
position: relative;
font-size: 1em;
font-weight: 400;
transition: all 0.4s;
outline: none !important;
font-family: "Sansita One", serif;
color: var(--c-text);
&::before,
&::after {
content: '';
display: block;
position: absolute;
z-index: -1;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-repeat: no-repeat;
transition: all 0.4s;
}
&::before {
background-image: linear-gradient(-66deg, transparent 0%, transparent 50%, #5bf390 50%, #5bf390 100%);
transform: translateX(calc(-100% + 41.6%));
}
&::after {
background-image: linear-gradient(114deg, transparent 0%, transparent 50%, #ff4cff 50%, #ff4cff 100%);
transform: translateX(calc(100% - 41.6%));
}
&:hover,
&:active{
// color: white;
&::before,
&::after {
transform: translateX(0);
}
}
}
.sr-only{
position: absolute;
height: 1px;
width: 1px;
clip: rect(1px 1px 1px 1px);
clip: rect(1px,1px,1px,1px);
clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
overflow: hidden !important;
}
label {
padding: 20px;
margin: 60px;
transition: background-color 200ms ease-in-out;
width: 120px;
height: 50px;
border-radius: 50px;
text-align: center;
background-color: slateGray;
box-shadow: -4px 4px 15px inset rgba(0, 0, 0, 0.4);
position: absolute;
top: 0;
right: 0;
font-family: "Sansita One", serif;
&::before,
&::after {
font-size: 2rem;
position: absolute;
transform: translate3d(0, -50%, 0);
top: 50%;
}
&::before {
content: '\263C';
right: 100%;
margin-right: 10px;
color: orange;
font-size: 2rem;
line-height: 1;
bottom: -7px;
}
&::after {
content: '\263E';
left: 100%;
margin-left: 10px;
color: lightSlateGray;
}
span {
position: absolute;
bottom: calc(100% + 10px);
left: 50%;
transform: translate(-50%, 0);
white-space: nowrap;
&::after {
position: absolute;
top: calc(100% + 15px);
left: 34px;
width: 40px;
height: 40px;
content: '';
border-radius: 50%;
background-color: lightBlue;
transition: transform 200ms, background-color 200ms;
box-shadow: -3px 3px 8px rgba(0, 0, 0, 0.4);
}
}
}
input[type="checkbox"]:checked ~ .theme-container label {
background-color: lightSlateGray;
&::before {
color: lightSlateGray;
}
&::after {
color: turquoise;
}
span::after {
transform: translate3d(68px, 0, 0);
}
}
// dark & light mode
:root {
/* Light theme */
--c-text: #333;
--c-background: #fff;
}
.theme-container {
color: var(--c-text);
background-color: var(--c-background);
}
input[type="checkbox"]:checked ~ .theme-container {
filter: invert(100) hue-rotate(180deg);
img {
filter: invert(100) hue-rotate(180deg);
}
.node::before {
filter: invert(100) hue-rotate(180deg);
}
}
document.addEventListener('DOMContentLoaded', function () {
const checkbox = document.querySelector('.toggle');
checkbox.checked = localStorage.getItem('darkMode') === 'true';
checkbox.addEventListener('change', function (event) {
localStorage.setItem('darkMode', event.currentTarget.checked);
});
});
Also see: Tab Triggers