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.
<div class="wrap">
<h1>Update CSS Variables With <em>JS</em></h1>
<div class="option">
<strong>Option</strong>
<div class="block">
<label for="textSize" class="opt-title">Font size</label>
<input type="range" name="textSize" min="11" max="18" value="14" data-sizing="px" />
</div>
<div class="block">
<label for="mainColor" class="opt-title">Main Color</label>
<input type="color" name="mainColor" value="#ffc600">
</div>
<div class="block">
<label for="blur" class="opt-title">Background Blur</label>
<input type="range" name="blur" min="0" max="10" value="0" data-sizing="px" />
</div>
</div>
<div class="content">
<article class="article-1">
<img src="http://unsplash.it/960?image=183" alt="image" class="img">
<div class="txt">
<p><em>Lorem ipsum </em>dolor sit amet, consectetur adipiscing elit. Ut auctor porttitor ipsum. Proin euismod elit risus, vel semper ligula convallis eget. Nullam efficitur condimentum nisi, vel mollis nibh mattis vitae. Nullam porta, mi in sollicitudin imperdiet, magna mi accumsan tortor, quis convallis tortor lorem ac metus. Fusce tincidunt, massa vel porta pellentesque, nibh ex ornare arcu, ac accumsan ipsum ligula in turpis. Proin vel neque in lacus volutpat tempor sit amet pretium massa. Donec tempor <em>mauris ut eros dictum</em>, id cursus nunc venenatis. Aliquam vulputate, orci in laoreet mollis, est orci blandit urna, eu dictum lacus diam ac turpis.</p>
<p>Vestibulum lacinia vel ante vel vehicula. Praesent dignissim tristique luctus. Vivamus odio tellus, aliquam vitae interdum vitae, congue vitae elit. Phasellus ornare feugiat turpis non elementum. In hac habitasse platea dictumst. Phasellus sollicitudin dui ut feugiat convallis. Etiam aliquet gravida metus vel congue.</p>
<p>Quisque non purus at justo interdum finibus. Donec libero nisi, ultrices non blandit eu, convallis et magna. Suspendisse potenti. Quisque vestibulum, diam non facilisis iaculis, dui odio lacinia ligula, sed porttitor felis ex sed nisl. <em>Curabitur tempor vel tellus ac rhoncus</em>. Sed dictum erat pharetra lorem mattis, non euismod risus venenatis. Maecenas vel ligula quis eros laoreet elementum a eget magna.</p>
</div>
</article>
<article class="article-2">
<img src="http://unsplash.it/960?image=179" alt="image" class="img">
<div class="txt">
<p><em>Integer ac euismod mi, ut commodo risus. Suspendisse metus ante, iaculis ac convallis non, lobortis non nulla. Cras venenatis feugiat dolor, eu aliquet massa venenatis nec.</em> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc viverra dictum sapien, quis dictum nibh. Mauris suscipit, diam congue luctus condimentum, risus massa convallis orci, id ultricies augue risus non ligula. Phasellus viverra risus vel rhoncus aliquam. Aliquam vel vestibulum justo. Ut ornare vel nibh vitae cursus. Mauris vitae mauris at nulla hendrerit dictum ac vel ante. Sed nec dui molestie, pulvinar est nec, molestie mauris. Praesent dignissim velit nec eros tempor, imperdiet maximus magna convallis. Etiam laoreet dolor at elit dapibus, quis molestie enim volutpat. <em>Donec ultricies, eros at aliquam dapibus</em>, mauris turpis vulputate orci, sed vehicula nisi felis eget lorem. Mauris id sollicitudin sem. Proin a pulvinar ipsum, et fringilla nunc. Phasellus rutrum vel sem scelerisque gravida. Nunc maximus enim elit, ut elementum urna vehicula aliquam. Nunc id sapien quis justo mattis volutpat et non quam. Integer hendrerit et elit ut tincidunt. Fusce convallis lectus quis enim semper, vel pretium turpis scelerisque. Maecenas dui elit, semper eu finibus nec, euismod a mauris. Nulla efficitur lorem vitae rutrum tincidunt. Sed in neque maximus, rhoncus libero id, auctor felis. Fusce efficitur ultricies purus. Etiam in augue quis massa facilisis accumsan a id leo. Nunc luctus tellus non odio imperdiet, nec mollis metus euismod. Mauris ut fringilla tortor. Praesent ac dictum leo.</p>
</div>
</article>
<article class="article-3">
<img src="http://unsplash.it/960?image=228" alt="image" class="img">
<div class="txt">
<p>Vivamus vehicula lacus at fermentum facilisis. Etiam tempus pellentesque tristique. Nullam vitae malesuada eros. Cras facilisis scelerisque felis, in luctus ante dictum ac.</p>
<p>Ut dolor orci, sodales in lectus vel, egestas blandit dui. Nam feugiat, lacus id laoreet dignissim, ligula dolor congue ex, pretium convallis ex elit eget erat. Mauris malesuada faucibus fermentum. Vivamus luctus dapibus metus sed egestas.<em> Cras tempus sodales tincidunt</em>. Mauris sit amet sagittis nisi. Nam nec lectus leo. Praesent ac dolor sit amet quam congue eleifend. Donec interdum a libero at ornare. Pellentesque quis lacinia nisl. Nunc sit amet massa ante. Phasellus in felis est. Vivamus facilisis metus ut mi molestie dictum. <br/>Duis tristique, velit vitae bibendum placerat, elit nisl fermentum nunc, id commodo mi nisi vel risus. In eleifend lorem vitae accumsan pharetra. Nunc ultrices rhoncus pellentesque. Proin tincidunt, nunc eget dapibus pharetra, velit lacus vehicula magna, non auctor libero purus eu lacus. Curabitur nec aliquam leo. Sed blandit vulputate justo in egestas. Donec in viverra eros. Quisque volutpat neque eu mauris euismod convallis nec non metus. Maecenas nibh lorem, lacinia a velit aliquam, <em>ullamcorper condimentum felis</em>. Aenean diam urna, imperdiet id porta quis, cursus in sem. Etiam tempor bibendum maximus. Nulla ut dictum diam. Mauris consequat dolor nec libero pharetra pretium. Phasellus pharetra ultrices efficitur.</p>
<p class="accent"><em>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</em></p>
</div>
</article>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro');
:root {
--textSize: 14px;
--mainColor: #ffc600;
--blur: 0px;
}
* {
margin: 0;
padding: 0;
font-family: 'Source Sans Pro', sans-serif;
}
h1 {
font-size: 43px;
text-align: center;
color: #f6f6f6;
margin-top: 40px;
margin-bottom: 60px;
}
h2 {
font-size: 32px;
margin-bottom: 20px;
}
body {
background-color: #242424;
h2 {
color: #f6f6f6;
border-left: 5px solid #f6f6f6;
padding-left: 12px;
}
}
em {
color: var(--mainColor);
font-style: normal;
}
.wrap {
padding: 20px;
width: 960px;
margin: 0 auto;
}
.option {
position: fixed;
padding: 25px;
z-index: 10;
bottom: 30px;
right: 30px;
background-color: #fff;
font-size: 16px;
box-shadow: 0px 4px 10px rgba(1,1,1,0.15);
strong {
display: block;
margin-bottom: 30px;
font-size: 30px;
}
.block {
margin: 6px 0;
}
.opt-title {
font-weight: bold;
margin-right: 4px;
}
label+input {
margin-left: 4px;
}
}
article {
overflow: hidden;
position: relative;
margin: 30px 0;
&:after {
opacity: 0.5;
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
background-color: #000;
content: '';
pointer-events: none;
user-select: none;
}
.img {
display: block;
width: 100%;
filter: blur(var(--blur));
}
.txt {
z-index: 1;
display: flex;
position: absolute;
bottom: 20px;
color: #fafafa;
padding: 20px;
p {
margin: 0 14px;
font-size: var(--textSize);
line-height: 140%;
}
}
}
.article-2 {
.txt {
width: 60%;
}
}
.article-3 {
.txt {
display: block;
text-align: center;
top: 50%;
transform: translateY(-50%);
p {
width: 50%;
margin: 0 auto;
}
p:nth-child(2) {
width: 75%;
margin-top: 30px;
margin-bottom: 60px;
}
}
}
article .txt p.accent {
font-size: 120%;
width: 90%;
}
const inputs = document.querySelectorAll(".option input");
const handleUpdate = function() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}
inputs.forEach(input => {
input.addEventListener("change", handleUpdate);
input.addEventListener("mousemove", handleUpdate);
});
Also see: Tab Triggers