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.
.typo#typo-wrapper
h1(
contenteditable='true'
spellcheck='false'
).typo__heading.has-anim Stretch
button(
type='button'
title='Click me! or click your right/left arrows'
)#btn.btn.btn--blend-mode CSS - mix-blend-mode:
span overlay
| ;
p
small.credit by ilithya
:root {
--shadow_x: 10px;
--shadow_y: 10px;
}
$c_bg: hotpink;
$c_pen: #fffffd; // white
$c_dark: #191919; // black
$c_purple: #7c4de1;
$c_hue: 259; // Edit shadow color here
@mixin size($w, $h: $w) {
width: $w;
height: $h;
}
html,
body {
height: 100%;
}
body {
background-color: $c_bg;
margin: 0;
padding: 0;
overflow: hidden;
}
::selection {
background-color: $c_pen;
color: $c_bg;
}
.typo {
@include size(100%);
cursor: default;
display: flex;
align-items: center;
justify-content: center;
// Galaxy photo by Marc Schulte
// https://www.pexels.com/@marc-schulte-656598
background-image: url('https://images.pexels.com/photos/2779948/pexels-photo-2779948.jpeg?auto=compress&cs=tinysrgb&h=1150&w=1660'); // More img compression - h=750&w=1260
// Just another galaxy image to play with:
// background-image: url('https://images.pexels.com/photos/957010/milky-way-starry-sky-night-sky-star-957010.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
position: fixed;
top: 0;
left: 0;
// Colored effect in galaxy bg photo toggled via JS
&::after {
@include size(100%);
background-color: $c_bg;
mix-blend-mode: overlay;
content: '';
position: absolute;
top: 0;
left: 0;
}
&__heading {
color: $c_dark;
font-family: 'Roboto Condensed', sans-serif;
font-size: 35vmin;
line-height: 30vmin;
margin: 0;
mix-blend-mode: lighten;
outline: none;
position: relative;
z-index: 10; // To place it on top of color background
// Color background - to cover galaxy bg, except inside typo
&::after {
@include size(500vw, 500vh);
background-color: $c_bg;
content: '';
position: absolute;
top: -250vh;
left: -250vw;
z-index: -1;
}
}
}
.has-shadow {
text-shadow:
calc(var(--shadow_x) * -1) calc(var(--shadow_y) * 1) 0 hsl($c_hue, 11%, 71%),
calc(var(--shadow_x) * -2) calc(var(--shadow_y) * 2) 0 hsl($c_hue, 21%, 69%),
calc(var(--shadow_x) * -3) calc(var(--shadow_y) * 3) 0 hsl($c_hue, 31%, 67%),
calc(var(--shadow_x) * -4) calc(var(--shadow_y) * 4) 0 hsl($c_hue, 41%, 65%),
calc(var(--shadow_x) * -5) calc(var(--shadow_y) * 5) 0 hsl($c_hue, 51%, 63%),
calc(var(--shadow_x) * -6) calc(var(--shadow_y) * 6) 0 hsl($c_hue, 61%, 61%),
calc(var(--shadow_x) * -7) calc(var(--shadow_y) * 7) 0 hsl($c_hue, 71%, 59%),
calc(var(--shadow_x) * -8) calc(var(--shadow_y) * 8) 0 hsl($c_hue, 81%, 57%);
}
.has-anim {
animation: anim_text 0.8s 0.4s cubic-bezier(.17,.67,.66,1.03) infinite alternate;
@at-root {
@keyframes anim_text {
100% {
transform: translate(80px, -80px);
// FYI: I do not recommend attempting animating the text-shadow property in production or a real project, as performance-wise it's not the best because of the paint and layout time. Reference - https://csstriggers.com/
text-shadow:
calc(var(--shadow_x) * -1) calc(var(--shadow_y) * 1) 0 hsl($c_hue, 11%, 71%),
calc(var(--shadow_x) * -2) calc(var(--shadow_y) * 2) 0 hsl($c_hue, 21%, 69%),
calc(var(--shadow_x) * -3) calc(var(--shadow_y) * 3) 0 hsl($c_hue, 31%, 67%),
calc(var(--shadow_x) * -4) calc(var(--shadow_y) * 4) 0 hsl($c_hue, 41%, 65%),
calc(var(--shadow_x) * -5) calc(var(--shadow_y) * 5) 0 hsl($c_hue, 51%, 63%),
calc(var(--shadow_x) * -6) calc(var(--shadow_y) * 6) 0 hsl($c_hue, 61%, 61%),
calc(var(--shadow_x) * -7) calc(var(--shadow_y) * 7) 0 hsl($c_hue, 71%, 59%),
calc(var(--shadow_x) * -8) calc(var(--shadow_y) * 8) 0 hsl($c_hue, 81%, 57%);
}
}
}
}
.btn {
$font-size: 0.7rem;
border: 0;
color: $c_pen;
cursor: pointer;
font-family: Georgia, Times, "Times New Roman", serif;
font-size: $font-size;
letter-spacing: 1px;
line-height: $font-size;
outline: 1px solid transparent; // Fixes iOs jagged edges
padding: 7px 10px 9px;
position: absolute;
right: -5px;
text-decoration: none; // In case it's a link tag
user-select: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
&--blend-mode {
background-color: $c_dark;
bottom: 25px;
transform: rotateZ(-2deg);
}
}
.credit {
color: rgba($c_pen, 0.3);
font-size: 0.6em;
letter-spacing: 1px;
position: absolute;
bottom: 5px;
right: 5px;
user-select: none;
}
// Mix Blend Mode Options
// For a full view of current browser options and support - https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
// FYI - You could totally do this via CSS Variables instead, but in this case I wanted to play with old school classes.
.is-overlay {
// This is also the default mix-blend mode in container
&::after {
mix-blend-mode: overlay;
}
}
.is-color {
&::after {
mix-blend-mode: color;
}
}
.is-exclusion {
&::after {
mix-blend-mode: exclusion;
}
}
.is-hard-light {
&::after {
mix-blend-mode: hard-light;
}
}
.is-color-burn {
&::after {
mix-blend-mode: color-burn;
}
}
.is-darken {
&::after {
mix-blend-mode: darken;
}
}
.is-difference {
&::after {
mix-blend-mode: difference;
}
}
.is-saturation {
&::after {
mix-blend-mode: saturation;
}
}
.is-color-dodge {
&::after {
mix-blend-mode: color-dodge;
}
}
.is-multiply {
&::after {
mix-blend-mode: multiply;
}
}
.is-normal {
&::after {
mix-blend-mode: normal;
}
}
.is-hue {
&::after {
mix-blend-mode: hue;
}
}
.is-screen {
&::after {
mix-blend-mode: screen;
}
}
/*
* STRETCH TYPO
* Move your mouse or drag your finger to stretch the typo and stop the animation.
* Click the black banner or your right/left arrow keys to switch the CSS mix-blend-mode, and experience the different effects with the masked galaxy photo in the background.
*
* Headline is editable, so place your cursor in the text and type anything else you'd like.
*
* #041 - #100DaysOfCode
* By ilithya | 2020
* https://www.ilithya.rocks/
* https://twitter.com/ilithya_rocks
*/
const blendModes = [
"overlay",
"color",
"exclusion",
"hard-light",
"color-burn",
"darken",
"difference",
"saturation",
"color-dodge",
"multiply",
"normal", // Same effect as lighten
"hue",
"screen",
];
function updateBlendMode(parentSelector) {
const wrapper = document.querySelector("#typo-wrapper");
const classPrefix = "is-";
// Create current classes array
const currentClasses = wrapper.className.split(" ");
// Filter all classes NOT starting with the classPrefix
const filteredClasses = currentClasses.filter(c => !c.startsWith(classPrefix));
// Add all filteredClasses to wrapper
wrapper.className = filteredClasses.join(" ").trim();
const modeContainer = parentSelector.querySelector("span");
const modeVal = blendModes[modeIndex];
// Add the appropriate text inside button, depeding on which mix-blend-mode value is running
modeContainer.textContent = modeVal;
// Add the appropriate class name, depeding on which mix-blend-mode value is running
wrapper.classList.add(`is-${modeVal}`);
}
let modeIndex = 0;
function nextBlendMode(e, el = null) {
// Update blend mode array index after last selection
modeIndex = modeIndex >= blendModes.length - 1 ? 0 : ++modeIndex;
const parentContainer = el === null ? e.currentTarget : el;
updateBlendMode(parentContainer);
}
function prevBlendMode(el) {
// Update blend mode array index after last selection
modeIndex = modeIndex <= 0 ? blendModes.length - 1 : --modeIndex;
updateBlendMode(el);
}
const btn = document.querySelector("#btn");
btn.addEventListener("click", nextBlendMode);
function onClickArrowKeys(e) {
// Right arrow key
if (e.keyCode === 39) {
nextBlendMode(null, btn);
}
// Left arrow key
if (e.keyCode === 37) {
prevBlendMode(btn);
}
}
// Let's add the key events for the blend mode toggling
document.onkeydown = onClickArrowKeys;
function createShadows(e, currTarget) {
// Walk effect based on Wes Bos' Mouse Move Shadow Exercise
// https://tinyurl.com/touabxe
const walk = Math.round(Math.max(window.innerWidth, window.innerHeight) / 2.5);
const coordWalk = (coord, side) =>
Math.round((coord / side * walk) - (walk / 2));
const xWalk = coordWalk(e.clientX, currTarget.offsetWidth);
const yWalk = coordWalk(e.clientY, currTarget.offsetHeight);
const root = document.querySelector(":root");
const cssVarX = "--shadow_x";
const cssVarY = "--shadow_y";
root.style.setProperty(cssVarX, `${xWalk / 10}px`);
root.style.setProperty(cssVarY, `${yWalk / -10}px`);
const typo = currTarget.querySelector(".typo__heading");
typo.classList.remove("has-anim");
typo.classList.add("has-shadow");
typo.style.transform = `translate(${xWalk}px, ${yWalk}px)`;
typo.blur();
}
function onMouseMove(e) {
createShadows(e, e.currentTarget);
}
function onTouchMove(e) {
createShadows(e.changedTouches[0], e.currentTarget);
}
const heading = document.querySelector(".typo");
heading.addEventListener("mousemove", onMouseMove);
heading.addEventListener("touchmove", onTouchMove);
Also see: Tab Triggers