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.
<body>
<div class="container bubbles">
<div id="sec1" class="section">
<h1>Part 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in porttitor felis. Vestibulum eget ex varius, lobortis nulla eget, accumsan magna. Fusce sed molestie enim. Sed tincidunt aliquam laoreet. Ut sit amet nulla in sem luctus consectetur. Phasellus ut nibh vitae sem bibendum lobortis.</p><p>Integer lectus neque, tempor in arcu in, dignissim ullamcorper nisl. Quisque ullamcorper ullamcorper felis ut semper. Aenean imperdiet semper tincidunt. </p>
</div>
<div id="sec2" class="section">
<h1>Part 2</h1>
<p>Sed dictum purus sed lorem euismod, in consectetur est finibus. Duis a lectus vel velit venenatis tristique id nec orci. Duis suscipit dui augue, ut rhoncus velit malesuada id. Vestibulum in hendrerit urna.</p><p>Sed ac urna tincidunt, elementum magna et, pellentesque urna. Vivamus imperdiet a sapien varius euismod. Vivamus ullamcorper malesuada nisi et congue. Vestibulum iaculis, sapien nec blandit accumsan, purus urna imperdiet enim, sed lobortis ex neque eget justo. Vestibulum nec nunc non tellus fermentum consectetur non ac nisi.</p><p>Pellentesque auctor hendrerit rhoncus. Nam faucibus bibendum erat at ornare. Nulla venenatis risus vitae libero tempor, vitae aliquam lacus viverra. </p>
</div>
<div id="sec3" class="section">
<h1>Part 3</h1>
<p>Donec a justo sit amet nulla volutpat malesuada a vitae nibh. Etiam venenatis velit et turpis aliquet rhoncus. Ut vitae accumsan dolor, ac consequat elit. Nulla cursus ut odio nec eleifend. Aliquam vitae tincidunt dui. Phasellus sed dolor nulla. Cras id tincidunt nulla.</p><p>Nulla ut metus accumsan, convallis dolor sollicitudin, viverra mauris. Vivamus viverra eros a turpis pellentesque mollis. Quisque scelerisque mattis purus, lobortis maximus augue. Nullam eget nulla ac lorem ultrices tincidunt vel id felis. Praesent nulla quam, mattis nec eros et, suscipit lacinia leo.</p>
</div>
</div>
<div id="show-settings" onclick="showSettings()">
<table class="show-settings-elements"><tr>
<td class="show-settings-text">Settings</td>
<td class="show-settings-icon">⚙</td>
</tr></table>
</div>
<div class="settings">
<div class="settings-head">
<span onclick="hideSettings()">✕</span>
</div>
<div class="settings-body">
<div class="settings-pane left">
<div class="control-area">
<p class="switch-title">Text colour</p>
<div class="toggle-switch">
White
<label class="switch">
<input type="checkbox" name="textcolour">
<span class="toggle toggle-shape round"></span>
</label>
Black
</div>
</div> <!-- .checkbox-area -->
<div class="control-area">
<p class="switch-title">Background</p>
<div class="radio-buttons">
<input id="bg-bubbles" type="radio" name="bg" value="bubbles" checked> <label for="bg-bubbles">Bubbles</label><br>
<input id="bg-curves" type="radio" name="bg" value="curves"> <label for="bg-curves">Curves</label><br>
<input id="bg-geometric" type="radio" name="bg" value="geometric"> <label for="bg-geometric">Geometric</label><br>
<input id="bg-moorish" type="radio" name="bg" value="moorish"> <label for="bg-moorish">Moorish</label>
</div>
</div> <!-- .control-area -->
</div> <!-- .settings-left -->
<div class="settings-pane right">
<div class="slider-area">
<p class="slider-title">Hue <span id="hue-value" class="value">220</span></p>
<p id="slider-hue" class="slider"></p>
</div>
<div class="slider-area">
<p class="slider-title">Variance <span id="variance-value" class="value">40</span></p>
<p id="slider-variance" class="slider"></p>
</div>
<div class="slider-area">
<p class="slider-title">Saturation <span id="saturation-value" class="value">50</span></p>
<p id="slider-saturation" class="slider"></p>
</div>
<div class="slider-area">
<p class="slider-title">Lightness <span id="lightness-value" class="value">50</span></p>
<p id="slider-lightness" class="slider"></p>
</div>
<div class="slider-area">
<p class="slider-title">Opacity <span id="opacity-value" class="value">80</span></p>
<p id="slider-opacity" class="slider"></p>
</div>
</div> <!-- .settings-pane .right -->
</div > <!-- .settings-body -->
</div> <!-- .settings -->
</body>
@import url("https://fonts.googleapis.com/css?family=Montserrat:200,300,400");
@import url("https://fonts.googleapis.com/css?family=Rajdhani:300,400,500" rel="stylesheet");
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: hsl(0,0%,10%);
font-family: Montserrat, sans-serif;
}
.container {
display: flex;
background-color: hsl(0,0%,100%);
}
/* see: https://www.heropatterns.com */
.bubbles {
background-color: #ffffff;
background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23727272' fill-opacity='1' fill-rule='evenodd'/%3E%3C/svg%3E");
}
.curves {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='30' viewBox='0 0 1000 120'%3E%3Cg fill='none' stroke='%237a7a7a' stroke-width='8' stroke-opacity='0.9'%3E%3Cpath d='M-500 75c0 0 125-30 250-30S0 75 0 75s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3Cpath d='M-500 45c0 0 125-30 250-30S0 45 0 45s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3Cpath d='M-500 105c0 0 125-30 250-30S0 105 0 105s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3Cpath d='M-500 15c0 0 125-30 250-30S0 15 0 15s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3Cpath d='M-500-15c0 0 125-30 250-30S0-15 0-15s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3Cpath d='M-500 135c0 0 125-30 250-30S0 135 0 135s125 30 250 30s250-30 250-30s125-30 250-30s250 30 250 30s125 30 250 30s250-30 250-30'/%3E%3C/g%3E%3C/svg%3E");
}
.geometric {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='152' height='152' viewBox='0 0 152 152'%3E%3Cg fill-rule='evenodd'%3E%3Cg id='temple' fill='%23acacac' fill-opacity='1'%3E%3Cpath d='M152 150v2H0v-2h28v-8H8v-20H0v-2h8V80h42v20h20v42H30v8h90v-8H80v-42h20V80h42v40h8V30h-8v40h-42V50H80V8h40V0h2v8h20v20h8V0h2v150zm-2 0v-28h-8v20h-20v8h28zM82 30v18h18V30H82zm20 18h20v20h18V30h-20V10H82v18h20v20zm0 2v18h18V50h-18zm20-22h18V10h-18v18zm-54 92v-18H50v18h18zm-20-18H28V82H10v38h20v20h38v-18H48v-20zm0-2V82H30v18h18zm-20 22H10v18h18v-18zm54 0v18h38v-20h20V82h-18v20h-20v20H82zm18-20H82v18h18v-18zm2-2h18V82h-18v18zm20 40v-18h18v18h-18zM30 0h-2v8H8v20H0v2h8v40h42V50h20V8H30V0zm20 48h18V30H50v18zm18-20H48v20H28v20H10V30h20V10h38v18zM30 50h18v18H30V50zm-2-40H10v18h18V10z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.moorish {
background-image: url("data:image/svg+xml,%3Csvg width='84' height='84' viewBox='0 0 84 84' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23a3a3a3' fill-opacity='1'%3E%3Cpath d='M84 23c-4.417 0-8-3.584-8-7.998V8h-7.002C64.58 8 61 4.42 61 0H23c0 4.417-3.584 8-7.998 8H8v7.002C8 19.42 4.42 23 0 23v38c4.417 0 8 3.584 8 7.998V76h7.002C19.42 76 23 79.58 23 84h38c0-4.417 3.584-8 7.998-8H76v-7.002C76 64.58 79.58 61 84 61V23zM59.05 83H43V66.95c5.054-.5 9-4.764 9-9.948V52h5.002c5.18 0 9.446-3.947 9.95-9H83v16.05c-5.054.5-9 4.764-9 9.948V74h-5.002c-5.18 0-9.446 3.947-9.95 9zm-34.1 0H41V66.95c-5.053-.502-9-4.768-9-9.948V52h-5.002c-5.184 0-9.447-3.946-9.95-9H1v16.05c5.053.502 9 4.768 9 9.948V74h5.002c5.184 0 9.447 3.946 9.95 9zm0-82H41v16.05c-5.054.5-9 4.764-9 9.948V32h-5.002c-5.18 0-9.446 3.947-9.95 9H1V24.95c5.054-.5 9-4.764 9-9.948V10h5.002c5.18 0 9.446-3.947 9.95-9zm34.1 0H43v16.05c5.053.502 9 4.768 9 9.948V32h5.002c5.184 0 9.447 3.946 9.95 9H83V24.95c-5.053-.502-9-4.768-9-9.948V10h-5.002c-5.184 0-9.447-3.946-9.95-9zM50 50v7.002C50 61.42 46.42 65 42 65c-4.417 0-8-3.584-8-7.998V50h-7.002C22.58 50 19 46.42 19 42c0-4.417 3.584-8 7.998-8H34v-7.002C34 22.58 37.58 19 42 19c4.417 0 8 3.584 8 7.998V34h7.002C61.42 34 65 37.58 65 42c0 4.417-3.584 8-7.998 8H50z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.section {
padding: 2.5em;
width: 33.3333vw;
color: white;
}
.section h1 {
font-weight: 300;
font-size: 2em;
letter-spacing: 0.15em;
margin: 0 0 0.5em;
font-family: 'Rajdhani', sans-serif;
text-transform: uppercase;
color: hsl(0,0%,90%);
}
.section p {
font-weight: 300;
margin-bottom: 1em;
line-height: 1.4em;
}
.section p:last-child {
margin-bottom: 0;
}
#sec1 {
background: hsl(180,30%,45%,90%);
}
#sec2 {
background: hsl(220,30%,45%,90%);
}
#sec3 {
background: hsl(260,30%,45%,90%);
}
#show-settings {
position: absolute;
right: 0.75em;
bottom: 0.75em;
padding: 0.1em 0.5em;
border-radius: 1em;
color: hsl(0,0%,60%);
background: hsl(220, 16%, 18%);
width: 7em;
height: 2.35em;
z-index: 1;
box-shadow: -0.2em 0.2em 0.7em -0.4em hsl(0, 0%, 0%);
}
#show-settings:hover {
background: hsl(220, 16%, 22%);
color: hsl(220,0%,64%);
cursor: pointer;
}
.show-settings-elements {
opacity: 1;
transition: opacity 0.5s;
}
.show-settings-icon {
padding-top: 0.2em;
}
.show-settings-text{
font-size: 0.9em;
padding: 0.5em 0.4em 0 0.2em;
vertical-align: top;
}
.settings {
background: hsl(220, 16%, 26%);
color: hsl(0, 0%, 60%);
position: absolute;
bottom: 0.75em;
right: 0.75em;
width: 6.9em;
height: 2.3em;
overflow: hidden;
border-radius: 1em;
transition: width 0.5s, height 0.5s;
z-index: 0;
}
.settings p {
font-size: 0.9em;
}
.settings-head {
text-align: right;
background: hsl(220, 16%, 18%);
padding: 0.4em 1em 0.2em;
border-radius: 1em 1em 0 0;
}
.settings-head span {
font-size: 1.5em;
color: hsl(220, 16%, 18%);
transition: color 0.5s;
}
.settings-head span:hover {
cursor: pointer;
}
.settings-body {
padding: 0.5em 1.5em;
/* min-width: 20em; */
display: flex;
}
.settings-pane.left {
min-width: 12em;
}
.settings-pane.right {
min-width: 20em;
}
.noUi-target {
border: 1px solid hsl(0, 0%, 75%);
border-radius: 2px;
}
.noUi-handle {
position: absolute;
top: -8px;
right: -8px;
width: 16px;
height: 16px;
background: hsl(180,60%,45%);
border-radius: 100%;
}
.noUi-handle:focus {
outline: none;
}
.slider-area {
margin-top: 16px;
}
p.slider-title, p.switch-title {
font-size: 0.85em;
}
.slider {
margin-top: 10px;
}
.value {
/* font-size: 0.8em; */
background: hsl(0, 0%, 45%);
font-family: monospace;
color: hsl(0, 0%, 95%);
padding: 0.1em 0.3em;
display: inline-block;
width: 28px;
border-radius: 8px;
text-align: right;
}
.control-area {
margin-top: 16px;
}
.toggle-switch {
padding: 0.333em 0;
font-size: 0.75em;
}
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 20px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: .2s;
}
.toggle-shape {
background-color: hsl(0,0%,60%);
}
.toggle:before {
position: absolute;
content: "";
height: 13px;
width: 14px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .2s;
}
input:checked + .toggle:before {
transform: translateX(18px);
}
/* Rounded sliders */
.toggle.round {
border-radius: 10px;
}
.toggle.round:before {
border-radius: 50%;
}
.switch-title {
padding-bottom: 0.5em;
}
.radio-buttons {
font-size: 0.75em;
}
input[name="bg"] {
margin-bottom: 0.75em;
}
var hue = 180
var variance = 40
var saturation = 50
var lightness = 50
var opacity = 80
// var textcolour = 'white'
var currentbg = 'bubbles'
function showSettings() {
document.querySelector('.show-settings-elements').style.opacity = '0'
setTimeout( function(){
var settings = document.querySelector('.settings')
settings.style.zIndex = '2'
document.querySelector('#show-settings').style.boxShadow = 'none'
settings.style.boxShadow = '-0.2em 0.2em 0.7em -0.4em hsl(0, 0%, 0%)'
settings.style.height = '19.5em'
settings.style.width = '35em'
document.querySelector('.settings-head span').style.color = 'hsl(0,90%,42%)'}, 125)
}
function hideSettings() {
var settings = document.querySelector('.settings')
document.querySelector('.settings-head span').style.color = 'hsl(220, 16%, 18%)'
settings.style.height = '2.3em'
settings.style.width = '6.9em'
setTimeout( function(){
settings.style.zIndex = '0'
document.querySelector('.show-settings-elements').style.opacity = '1'
document.querySelector('#show-settings').style.boxShadow = '-0.2em 0.2em 0.7em -0.4em hsl(0, 0%, 0%)'
settings.style.boxShadow = 'none'
}, 500)
}
var hueSlider = document.querySelector('#slider-hue')
var varianceSlider = document.querySelector('#slider-variance')
var saturationSlider = document.querySelector('#slider-saturation')
var lightnessSlider = document.querySelector('#slider-lightness')
var opacitySlider = document.querySelector('#slider-opacity')
var textcolourControl = document.querySelector('input[name="textcolour"]')
var backgroundControl = document.querySelectorAll('input[name="bg"]')
noUiSlider.create(hueSlider, {
start: 220,
range: {
'min': 0,
'max': 360
},
step: 1
});
noUiSlider.create(varianceSlider, {
start: 40,
range: {
'min': 5,
'max': 120
},
step: 1
});
noUiSlider.create(saturationSlider, {
start: 50,
range: {
'min': 10,
'max': 100
},
step: 1
});
noUiSlider.create(lightnessSlider, {
start: 50,
range: {
'min': 5,
'max': 90
},
step: 1
});
noUiSlider.create(opacitySlider, {
start: 80,
range: {
'min': 20,
'max': 100
},
step: 1
});
hueSlider.noUiSlider.on('update', function( values, handle ) {
var val = Math.round(values[handle]);
hue = val
document.querySelector('#hue-value').innerHTML = hue
changeColours()
})
varianceSlider.noUiSlider.on('update', function( values, handle ) {
var val = Math.round(values[handle]);
variance = val
document.querySelector('#variance-value').innerHTML = variance
changeColours()
})
saturationSlider.noUiSlider.on('update', function( values, handle ) {
var val = Math.round(values[handle]);
saturation = val
document.querySelector('#saturation-value').innerHTML = saturation
changeColours()
})
lightnessSlider.noUiSlider.on('update', function( values, handle ) {
var val = Math.round(values[handle]);
lightness = val
document.querySelector('#lightness-value').innerHTML = lightness
changeColours()
})
opacitySlider.noUiSlider.on('update', function( values, handle ) {
var val = Math.round(values[handle]);
opacity = val
document.querySelector('#opacity-value').innerHTML = opacity
changeColours()
})
textcolourControl.addEventListener('change', function(){
headings = document.querySelectorAll('.section h1')
paragraphs = document.querySelectorAll('.section p')
headings.forEach( function(heading){
if(textcolourControl.checked) {
heading.style.color = 'hsl(0,0%,15%)'
} else {
heading.style.color = 'hsl(0,0%,90%)'
}
})
paragraphs.forEach( function(paragraph){
if(textcolourControl.checked) {
paragraph.style.color = 'black'
} else {
paragraph.style.color = 'white'
}
})
})
backgroundControl.forEach( function(bg) {
bg.addEventListener('change', function() {
var container = document.querySelector('.container')
container.classList.remove(currentbg)
currentbg = bg.value
container.classList.add(currentbg)
})
})
function changeColours() {
document.querySelector('#sec1').style.background = 'hsl(' + (hue) + ',' + saturation + '%, ' + lightness + '%, ' + opacity + '%)'
document.querySelector('#sec2').style.background = 'hsl(' + (hue+variance) + ',' + saturation + '%, ' + lightness + '%, ' + opacity + '%)'
document.querySelector('#sec3').style.background = 'hsl(' + (hue+variance*2) + ',' + saturation + '%, ' + lightness + '%, ' + opacity + '%)'
}
Also see: Tab Triggers