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>
<article id="Toggle-Switches-Container">
<section id="Toggle-Dark-Mode" class="panel-element">
<h3>Toggle Dark Mode</h3>
<div class="toggle-contents-wrapper">
<p>Off</p>
<div id="Dark-Mode-Switch" class="toggle-wrapper">
<div class="toggle-dot"></div>
</div>
<p>On</p>
</div>
</section>
<section id="Toggle-Language" class="panel-element">
<h3>Toggle Language</h3>
<div class="toggle-contents-wrapper">
<p>English</p>
<div id="Language-Switch" class="toggle-wrapper">
<div class="toggle-dot"></div>
</div>
<p>Español</p>
</div>
</section>
</article>
<article class="container panel-element">
<section class="selector">
<div id="Tab-1" class="tab tab-active">
Option One
</div>
<div id="Tab-2" class="tab">
Option Two
</div>
<div id="Tab-3" class="tab">
Option Three
</div>
</section>
<section id="English-Display" class="content">
<div id="Option One" class="content-body option-one show-active">
<h4>Option One</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tortor condimentum lacinia quis vel eros donec ac odio tempor. Iaculis eu non diam phasellus vestibulum lorem sed. Eros donec ac odio tempor orci dapibus ultrices. Quis imperdiet massa tincidunt.</p>
</div>
<div id="Option Two" class="content-body option-two">
<h4>Option Two</h4>
<p>Sit amet volutpat consequat mauris nunc congue nisi vitae suscipit. Faucibus pulvinar elementum integer enim neque. Amet mattis vulputate enim nulla aliquet. Habitant morbi tristique senectus et netus. Sem et tortor consequat id porta nibh venenatis. Vel risus commodo viverra maecenas accumsan lacus. Tincidunt dui ut ornare lectus sit.</p>
</div>
<div id="Option Three" class="content-body option-three">
<h4>Option Three</h4>
<p>At volutpat diam ut venenatis. Aliquet risus feugiat in ante metus dictum at. Lobortis elementum nibh tellus molestie nunc non blandit massa. Vel pretium lectus quam id leo in. Aliquam vestibulum morbi blandit cursus risus at. Elit sed vulputate mi sit amet mauris. Porttitor rhoncus dolor purus non enim praesent.</p>
</div>
</section>
<section id="Spanish-Display" class="content">
<div id="Opción Uno" class="content-body option-one show-active">
<h4>Opción Uno</h4>
<p>Netus et malesuada fames ac turpis egestas maecenas pharetra. Nunc sed augue lacus viverra vitae congue eu consequat ac. Et molestie ac feugiat sed lectus. Dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim. Fringilla est ullamcorper eget nulla facilisi etiam dignissim.</p>
</div>
<div id="Opción Dos" class="content-body option-two">
<h4>Opción Dos</h4>
<p>Fames ac turpis egestas maecenas pharetra convallis posuere morbi. Nulla porttitor massa id neque. Cum sociis natoque penatibus et magnis dis parturient. Id diam maecenas ultricies mi. Amet dictum sit amet justo donec enim diam. Diam ut venenatis tellus in metus. Gravida arcu ac tortor dignissim convallis aenean.</p>
</div>
<div id="Opción Tres" class="content-body option-three">
<h4>Opción Tres</h4>
<p>Viverra justo nec ultrices dui. Odio ut enim blandit volutpat. Donec ultrices tincidunt arcu non sodales neque. Mauris nunc congue nisi vitae suscipit tellus mauris a diam. Diam sollicitudin tempor id eu nisl nunc mi ipsum. Aenean et tortor at risus. Faucibus et molestie ac feugiat sed lectus vestibulum mattis.</p>
</div>
</section>
</article>
</main>
*, *::before, *::after {
box-sizing: border-box;
border-style: none;
list-style: none;
margin: 0;
padding: 0;
text-decoration: none;
}
:root {
/* LIGHT THEME COLORS */
--light-theme-base: #bdbdbd;
--light-theme-background: #FFFFFF;
--light-theme-shadow: rgba(18, 18, 18, .3);
--light-theme-primary: #6200EE;
--light-theme-primary-dark: #3700B3;
--light-theme-secondary: #03DAC6;
--light-theme-secondary-dark: #018786;
--light-theme-error-color: #B00020;
/* DARK THEME COLORS */
--dark-theme-base: #1d1d1d;
--dark-theme-background: #121212;
--dark-theme-shadow: rgba(255, 255, 255, .3);
--dark-theme-primary: #BB86FC;
--dark-theme-primary-dark: #3700B3;
--dark-theme-secondary: #03DAC6;
--dark-theme-error-color: #CF6679;
}
/* ---------- MAIN BODY DECLERATIONS ---------- */
html, body {
background-color: var(--theme-color-white);
font-family: "Montserrat";
font-size: 18px;
height: 100%;
min-height: 100vh;
min-width: 100%;
width: 100%;
}
body {
align-items: center;
background-color: var(--light-theme-base);
display: flex;
flex-direction: column;
font-family: 'Montserrat', sans-serif;
}
main {
align-items: center;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
max-width: 37em;
min-height: 700px;
min-width: 480px;
width: 100%;
}
article {
max-width: 40rem;
margin: 1.5rem auto;
}
body, article, section, section > *, .toggle-dot, .selector {
transition: background-color 1s;
}
#Toggle-Switches-Container {
align-items: center;
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
}
#Toggle-Switches-Container section {
border-radius: 10px;
text-align: center;
padding: 2em;
width: 48%;
}
#English-Display {
display: block;
}
#Spanish-Display {
display: none;
}
.panel-element {
background-color: var(--light-theme-background);
box-shadow: 2px 2px 5px var(--light-theme-shadow);
min-width: 12rem;
}
.toggle-contents-wrapper {
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
}
.toggle-wrapper {
background-color: var(--light-theme-primary-dark);
border: 2px solid var(--light-theme-primary-dark);
border-radius: 35px;
box-shadow: 1px 1px 5px var(--light-theme-shadow);
display: flex;
justify-content: flex-start;
margin: .5em 1.25em;
width: 3.5em;
min-width: 3.5em;
}
.toggle-dot {
background-color: var(--light-theme-secondary-dark);
box-shadow: 1px 1px 3px var(--light-theme-shadow);
margin: 2px;
border-radius: 35px;
height: 1.5em;
width: 1.5em;
}
.toggle-is-active {
justify-content: flex-end;
}
.container {
border-radius: 15px;
height: 50%;
margin: 0 auto;
width: 100%;
}
.selector {
align-items: center;
background-color: var(--light-theme-primary-dark);
border-radius: 15px 15px 0 0;
display: flex;
height: 5em;
justify-content: space-around;
text-align: center;
transition: background-color 1s;
}
.tab {
align-items: center;
background-color: var(--light-theme-primary);
border-radius: 8px;
box-shadow: 2px 2px 3px var(--light-theme-shadow);
color: var(--light-theme-background);
display: flex;
height: 3em;
justify-content: center;
padding: 10px;
transition: color 1s;
width: 27%;
transition: background-color .5s;
}
.tab:hover {
background-color: var(--light-theme-secondary-dark);
cursor: pointer;
transition: background-color .3s;
}
.content {
padding: 1.5em;
}
.content-body {
display: none;
}
.content-body h4 {
margin: .5em 0 1rem 0;
}
.show-active {
animation: fade-in 1s;
display: block;
}
.tab-active {
background-color: var(--light-theme-secondary-dark);
transition: color 1s;
}
@keyframes fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
body {
font-size: 12px;
}
main {
min-width: 20em;
}
#Toggle-Switches-Container {
flex-direction: column;
min-height: 19em;
}
}
/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
body {
font-size: 14px;
}
}
/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
body {
font-size: 16px;
};
}
// LIGHT THEME COLOR VARIABLES
var lightBase = '#bdbdbd';
var lightBackground = '#FFFFFF';
var lightShadow = 'rgba(18, 18, 18, .3)';
var lightPrimary = '#6200EE';
var lightPrimaryDark = '#3700B3';
var lightSecondary = '#03DAC6';
var lightSecondaryDark = '#018786';
var lightErrorColor = '#B00020';
// DARK THEME COLOR VARIABLES
var darkBase = '#1d1d1d';
var darkBackground = '#121212';
var darkShadow = 'rgba(255, 255, 255, .1)'
var darkPrimary = '#BB86FC';
var darkPrimaryDark = '#3700B3';
var darkSecondary = '#03DAC6';
var darkErrorColor = '#CF6679';
// GLOBAL VARIABLES
var darkModeSwitch = document.querySelector('#Dark-Mode-Switch');
var darkModetoggleIsOn = false;
var languageSwitch = document.querySelector('#Language-Switch');
var languagetoggleIsOn = false;
var tabs = document.getElementsByClassName('tab');
// CHANGES LIGHT THEME COLORS TO DARK THEME COLROS
function turnOnDarkModeColors() {
if (darkModetoggleIsOn === true) {
document.body.style.transition = 'color 1s, background-color 1s';
document.documentElement.style.setProperty('--light-theme-base', darkBase);
document.documentElement.style.setProperty('--light-theme-background', darkBackground);
document.documentElement.style.setProperty('--light-theme-primary', darkPrimary);
document.documentElement.style.setProperty('--light-theme-primary-dark', darkPrimaryDark);
document.documentElement.style.setProperty('--light-theme-secondary', darkSecondary);
document.documentElement.style.setProperty('--light-theme-secondary-dark', darkSecondary);
document.body.style.color = lightBackground;
} else {
document.body.style.transition = 'color 1s, background-color 1s';
document.documentElement.style.setProperty('--light-theme-base', lightBase);
document.documentElement.style.setProperty('--light-theme-background', lightBackground);
document.documentElement.style.setProperty('--light-theme-primary', lightPrimary);
document.documentElement.style.setProperty('--light-theme-primary-dark', lightPrimaryDark);
document.documentElement.style.setProperty('--light-theme-secondary', lightSecondary);
document.documentElement.style.setProperty('--light-theme-secondary-dark', lightSecondaryDark);
document.body.style.color = 'black';
}
}
// DARK MODE TOGGLE FUNCTIONALITY
darkModeSwitch.addEventListener('click', function() {
if (darkModetoggleIsOn === false) {
darkModeSwitch.style.justifyContent = 'flex-end';
darkModetoggleIsOn = true;
} else {
darkModeSwitch.style.justifyContent = 'flex-start';
darkModetoggleIsOn = false;
}
turnOnDarkModeColors();
return darkModetoggleIsOn;
});
// CHANGES ENGLISH TEXT TO SPANISH TEXT
function activateLanguageToggle() {
if (languagetoggleIsOn === true) {
// Dark Mode Toggle Components
document.querySelector('#Toggle-Dark-Mode h3').innerHTML = 'Alternar modo oscuro';
document.querySelector('#Toggle-Dark-Mode p:first-child').innerHTML = 'Apagado';
document.querySelector('#Toggle-Dark-Mode p:last-child').innerHTML = 'En';
// Toggle Language Components
document.querySelector('#Toggle-Language h3').innerHTML = 'Alternar idioma';
// Tab Selectors
document.querySelector('#Tab-1').innerHTML = 'Opción Uno';
document.querySelector('#Tab-2').innerHTML = 'Opción Dos';
document.querySelector('#Tab-3').innerHTML = 'Opción Tres';
// Tab Content
document.querySelector('#English-Display').style.display = 'none';
document.querySelector('#Spanish-Display').style.display = 'block';
} else {
// Dark Mode Toggle Components
document.querySelector('#Toggle-Dark-Mode h3').innerHTML = 'Toggle Dark Mode';
document.querySelector('#Toggle-Dark-Mode p:first-child').innerHTML = 'Off';
document.querySelector('#Toggle-Dark-Mode p:last-child').innerHTML = 'On';
// Toggle Language Components
document.querySelector('#Toggle-Language h3').innerHTML = 'Toggle Language';
// Tab Selectors
document.querySelector('#Tab-1').innerHTML = 'Option One';
document.querySelector('#Tab-2').innerHTML = 'Option Two';
document.querySelector('#Tab-3').innerHTML = 'Option Three';
// Tab Content
document.querySelector('#Spanish-Display').style.display = 'none';
document.querySelector('#English-Display').style.display = 'block';
}
document.getElementsByClassName('tab-active')[0].click();
console.log(document.getElementsByClassName('show-active'));
}
// LANGUAGE TOGGLE FUNCTIONALITY
languageSwitch.addEventListener('click', function() {
if (languagetoggleIsOn === false) {
languageSwitch.classList.add('toggle-is-active');
languagetoggleIsOn = true;
} else {
languageSwitch.classList.remove('toggle-is-active');
languagetoggleIsOn = false;
}
activateLanguageToggle();
return languagetoggleIsOn;
});
// function to remove .show-active class & add to clicked
function setNewActive(el) {
var contentBodies = document.getElementsByClassName('content-body');
for (var contentBody of contentBodies) {
contentBody.classList.remove('show-active');
}
document.getElementById(el.textContent.trim()).classList.add('show-active');
for (var tab of tabs) {
tab.classList.remove('tab-active');
}
el.classList.add('tab-active');
}
// select .tab class, and loop through
for (var tab of tabs) {
// add click listener to each tab
tab.addEventListener('click', function(e) {
setNewActive(e.currentTarget);
console.log(e.currentTarget);
});
}
Also see: Tab Triggers