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.
<!-- 10 Simple Yet Cool Popular Effects in Modern UI in the form of a landing page: 1. Loading Screen, 2. Color blending, 3. Custom Cursor, 4. GSAP smooth scrolling, 5. GSAP Horizontal scrolling, 6. GSAP Zooming on scroll, 7. Fixed Cards on scroll, 8. Transitioning text effects, 9. Responsive texts, 10. Creative buttons -->
<!-- If you're resizing the screen make sure to reload by simply adding a space here -->
<!-- LOADING SCREEN -->
<div id="loading-screen">
<div id="progress-bar"></div>
<div id="progress-counter">0%</div>
</div>
<!-- HERO SECTION -->
<div class="hero">
<div class="sun">
<div class="semicircle"></div>
<div class="line"></div>
</div>
<div class="road"></div>
</div>
<!-- HUGE TEXTS + ABSOLUTE POSITIONING TO RELATIVE POSITIONING -->
<div class="part1">
<p class="sitename">UI ROAD TRIP</p>
<div class="spacer"></div>
<div class="big-text">
<p class="fadein">SAY HELLO</p>
<p class="fadein">TO THESE</p>
<p class="fadein">HUGE TEXTS</p>
</div>
</div>
<!-- GSAP HORIZONTAL SCROLL -->
<div class="horizontal-container">
<div class="horizontal-wrapper">
<div class="horizontal-scroller">
<div class="row">
<div class="item filled"><p>We have some amazing content on this site. Wanna check 'em out?</p><a class="link item-link"><span class="link-text" data-text="Check our content">Check our content</span></a></div>
<div class="item filled"><p>Fun fact: Did you know that minimalism is on the rise? UIs now use fewer colors, simple and clear typography, and a generous amount of white space.</p></div>
<div class="item big"><p>5,667 Cups of Coffee</p></div>
<div class="item filled"><p>Did you know that users can memorize only around 6-7 chunks of data while browsing a webpage?</p><a class="link item-link"><span class="link-text" data-text="Learn more">Learn more</span></a></div>
<div class="item filled big"><p>How is your UX doing?</p></div>
<div class="item"><p>Fun fact 3: CSS Grids were first introduced in 2011 by Microsoft. How did we ever do without 'em?</p></div>
</div>
<div class="row">
<div class="item big"><p>Scroll is the new click.</p></div>
<div class="item filled"><p>Do you like scrolling forever? Check out our infinite scrolling page. This site fulfills your passion for scrolling. It just won't stop!</p><a class="link item-link"><span class="link-text" data-text="Check it out">Check it out</span></a></div>
<div class="item filled"><p>Fun fact 2: None of these links actually lead anywhere except the last link on this page.</p></div>
<div class="item big"><p># I <3 GSAP<p></div>
<div class="item filled"><p><b>Tip:</b> Search 'GSAP Horizontal Scroll' in the HTML, CSS, or JS parts of the code.</p></div>
<div class="item filled"><p>Gotta go already? That was a short visit. Check back later some time. Ba-bye!</p></div>
</div>
</div>
</div>
</div>
<!-- FIXED CARDS -->
<div class="cards-container">
<div class="cards">
<div class="cards-text-container">
<div class="cards-text"><h2>DO YOU LIKE CARDS?</h2><p>Well, you'd better. 'Cause you're getting a bunch of 'em.'</p><p>No worries though. You just keep scrollin'.</p><p>This is just the beginning of your card adventure.</p></div>
<div class="cards-text"><h2>CARD AFTER CARD</h2><p>Just to get your focus here.</p><p>Nothing special here. What a nice day, by the way.</p><p>Hope you're enjoying your free set of cards.</p></div>
<div class="cards-text"><h2>NOW YOU TRY</h2><p>Time to get your hands dirty.</p><p>Search 'Cards' in the HTML, CSS, or JS to find the code for this whole card thing.</p><p>And enjoy the rest of your scrollin'.</p></div>
<div class="cards-cta">GET STARTED</div>
</div>
<div class="cards-image-container">
<div class="cards-image"><img class="image" src="https://github.com/juxtopposed/codepen/blob/main/cards.png?raw=true"><img class="alt" src="https://github.com/juxtopposed/codepen/blob/main/cards.png?raw=true"></div>
<div class="cards-image"><img class="image" src="https://github.com/juxtopposed/codepen/blob/main/zoom.png?raw=true">
<img class="alt" src="https://github.com/juxtopposed/codepen/blob/main/zoom.png?raw=true">
</div>
<div class="cards-image"><img class="image" src="https://github.com/juxtopposed/codepen/blob/main/3dcards.png?raw=true"><img class="alt" src="https://github.com/juxtopposed/codepen/blob/main/3dcards.png?raw=true"></div>
</div>
</div>
</div>
<!-- ZOOM IN -->
<div class="zoom-container">
<div class="zoom">
<h2 class="zoom-heading">KEEP SCROLLING TO ZOOM</h2>
<div class="zoom-circle"></div>
<h3 class="zoom-content">ZOOM INNN</h3>
<div class="footer">
<p class="footer-content">Thanks for watching!</p>
<a class="footer-content link" href="https://twitter.com/juxtopposed" target="_blank"><span class="link-text" data-text="Let's connect">Let's connect</span></a>
</div>
</div>
</div>
<!-- just extra scrolling space -->
<div style="height: 300vh">
</div>
body {
font-family: 'IBM Plex Sans', sans-serif;
margin: 0;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
scroll-behavior: smooth;
font-weight: bold;
}
/* CUSTOM CURSOR */
* {
cursor: none;
}
/* HERO SECTION */
.hero {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
height: 100vh;
opacity: 0;
transition: opacity 1s ease-in;
}
.road {
background-color: white;
clip-path: polygon(50% 0, 100% 100%, 0 100%);
width: 100vw;
height: 100%;
position: relative;
bottom: 0;
color: white;
mix-blend-mode: difference;
}
.semicircle {
width: 40%;
height: 20vw;
background-color: white;
border-radius: 2000px 2000px 0 0;
position: relative;
color: white;
mix-blend-mode: difference;
position: absolute;
bottom: 0;
}
.sun {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
width: 100%;
height: 100%;
justify-content: flex-end;
}
.line {
width: 100vw;
height: 1px;
background-color: white;
}
/* LOADING SCREEN */
#loading-screen {
width: 100vw;
height: 100vh;
background-color: white;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-start;
position: absolute;
top: 0;
opacity: 1;
transition: opacity 0.5s ease-out;
}
#progress-bar {
width: 0%;
height: 100vh;
bottom: 0;
position: absolute;
background-color: white;
mix-blend-mode: difference;
transition: width 0.5s ease-in-out;
}
#progress-counter {
color: white;
font-size: 23vw;
mix-blend-mode: difference;
}
/* HUGE TEXTS + ABSOLUTE POSITIONING TO RELATIVE POSITIONING */
.part1 {
background-color: white;
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: space-between;
width: 100vw;
position: relative;
padding-bottom: 2em;
height: 100%;
}
.sitename {
position: fixed;
font-size: 14.5vw;
color: white;
mix-blend-mode: difference;
top: 0;
margin: 0;
opacity: 0;
animation: fade-in 0.5s forwards;
height: 20vw;
}
.sitename.relative {
position: relative;
}
@keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.spacer {
position: relative;
height: 20vw;
}
.spacer.absolute {
position: absolute;
height: 0;
}
.big-text {
font-size: 16vw;
margin: 0;
position: relative;
bottom: 0;
height: 100%;
width: 100%;
}
.big-text > p {
margin: 0;
}
.fadein {
opacity: 0;
transform: translateY(1em);
transition: opacity 0.5s, transform 1s;
}
.fadein.move-up {
transform: translateY(0);
}
/* GSAP HORIZONTAL SCROLL */
.horizontal-scroller {
display: grid;
grid-template-rows: repeat(2, 1fr);
gap: 5px;
width: 100%;
height: 100vh;
}
.horizontal-wrapper {
width: 100%;
height: calc(100vh + 210vw);
}
.horizontal-container {
width: 100%;
height: calc(100vh + 210vw);
margin-top: 2em;
}
.row {
display: flex;
justify-content: flex-start;
gap: 5px;
}
.item {
padding: 5vw;
border: 5px solid white;
border-radius: 5vw;
box-sizing: border-box;
font-size: 2vw;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
height: 50vh;
color: white;
font-weight: normal;
width: 50vw;
}
.item > p {
margin: 0;
}
.big {
font-size: 5vw;
align-items: center;
justify-content: center;
text-align: center;
}
.item-link {
border-bottom: 1px solid black;
align-self: flex-end;
}
.filled {
background-color: white;
color: black;
}
/* FIXED CARDS */
.cards-container {
height: 100%;
width: 100%;
/* margin-top: 60vw; */
}
.cards {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: space-between;
width: 100%;
height: 323vh;
gap: 0;
margin-top: 2em;
}
.cards-text-container {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
width: 50%;
gap: 0;
position: relative;
}
.cards-text {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
gap: 2vh;
height: 100vh;
background-color: white;
padding: 2em;
}
.cards-text > h2 {
font-size: 6vw;
margin: 0;
}
.cards-text > p {
font-size: 2vw;
margin: 0;
font-weight: normal;
line-height: 2;
}
.cards-image-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
width: 50%;
gap: 0;
position: relative;
height: 100%;
}
.cards-image {
height: 100vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
top: 0;
right: 0;
opacity: 0;
width: 100%;
}
img {
max-width: 100%;
mix-blend-mode: luminosity;
}
.image {
mix-blend-mode: luminosity;
opacity: 1;
z-index: 2;
}
.alt {
position: absolute;
mix-blend-mode: normal;
opacity: 0;
z-index: 1;
transition: opacity 0.5s ease;
}
.cards-image:hover > .alt {
opacity: 1;
transition: opacity 0.5s ease;
}
.cards-cta {
padding: 1em 0;
background-color: #e1e1e1;
color: black;
bottom: 0;
left: 0;
box-sizing: padding-box;
text-align: center;
font-size: 2vw;
position: relative;
overflow: hidden;
z-index: 9999;
opacity: 0;
transition: opacity 0.3s ease;
}
.cards-cta::before {
content: "";
position: absolute;
bottom: 0;
left: 0;
height: 100%;
width: 0;
background-color: white;
transition: width 0.3s ease;
mix-blend-mode: difference;
}
.cards-cta:hover::before {
width: 100%;
}
.fixed {
position: fixed;
opacity: 1;
transition: opacity 0.3s ease;
width: 50%;
}
/* ZOOM IN */
.zoom-heading {
mix-blend-mode: difference;
color: white;
font-size: 6vw;
}
.zoom-container {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.zoom {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
width: 100vw;
}
.zoom-circle {
height: 30vw;
width: 30vw;
border-radius: 100vw;
background-color: white;;
mix-blend-mode: difference;
display: flex;
flex-direction: column;
position: absolute;
justify-self: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.zoom-content {
color: white;
mix-blend-mode: difference;
position: absolute;
justify-self: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 5vw;
margin: 0;
}
.zoom-fixed {
position: fixed;
bottom: 0;
left: 0;
}
/* FOOTER */
.footer-content {
color: black;
font-size: 3vw;
z-index: 5;
margin: 0;
width: 50%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.footer {
display: flex;
flex-direction: row;
width: 100vw;
justify-content: space-between;
margin-bottom: 2vw;
}
.link {
overflow:hidden;
position:relative;
text-align:center;
color:black;
transition:0.3s;
}
.link-text {
display:block;
height:100%;
position:relative;
top:0%;
transition:0.3s;
}
.link-text::after {
content: attr(data-text);
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 100%;
transition: transform 0.3s;
color: black;
}
.link:hover .link-text {
top:-100%;
}
a {
text-decoration: none;
color: inherit;
}
/* CUSTOM CURSOR */
.custom-cursor {
position: fixed;
top: 0;
left: 0;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: white;
mix-blend-mode: difference;
pointer-events: none;
z-index: 9999;
transition: transform 0.3s ease;
}
.custom-cursor.scale-up {
transform: scale(5);
transition: transform 0.3s ease;
}
/* RESPONSIVENESS */
@media screen and (max-width: 800px) {
.cards {
flex-direction: column-reverse;
height: 230vh;
}
.cards-text {
width: 100vw;
height: 50vh;
}
.cards-image {
width: 100vw;
height: 50vh;
display: none;
}
img {
max-height: 100%;
}
.cards-image-container {
width: 100%;
}
.cards-cta {
width: 100%;
}
.comment {
font-size: 4vw;
}
.fixed {
position: fixed;
opacity: 1;
}
.cards-cta {
transition: none;
}
.item {
font-size: 5vw;
}
}
// LOADING SCREEN
const progressBar = document.getElementById('progress-bar');
const counter = document.getElementById('progress-counter');
const loadingScreen = document.getElementById('loading-screen');
const heroSection = document.querySelector('.hero');
function updateProgress(progress) {
progressBar.style.width = `${progress}%`;
counter.textContent = `${progress}%`;
}
updateProgress(0);
document.body.style.overflow = 'hidden';
document.addEventListener('DOMContentLoaded', () => {
let progress = 0;
const increment = 5;
const updateLoop = setInterval(() => {
if (progress >= 100) {
clearInterval(updateLoop);
setTimeout(() => {
loadingScreen.style.opacity = '0';
loadingScreen.style.height = '0';
heroSection.style.opacity = '1';
setTimeout(() => {
window.addEventListener('wheel', handleScroll);
document.body.style.overflowY = 'scroll';
}, 700);
}, 0);
}
updateProgress(progress);
progress += increment;
}, 100);
});
// SITENAME ABSOLUTE POSITIONING TO RELATIVE POSITIONING
window.addEventListener('scroll', () => {
const part1 = document.querySelector('.part1');
const sitename = document.querySelector('.sitename');
const spacer = document.querySelector('.spacer');
const part1Top = part1.getBoundingClientRect().top;
const sitenameHeight = sitename.offsetHeight;
const scrollThreshold = part1.offsetTop - sitenameHeight;
if (part1Top <= 0) {
sitename.classList.add('relative');
spacer.classList.add('absolute');
} else {
sitename.classList.remove('relative');
spacer.classList.remove('absolute');
}
});
// HUGE TEXTS TRANSITIONING UPWARDS
window.addEventListener('scroll', () => {
const elements = document.querySelectorAll('.fadein');
elements.forEach((element) => {
if (isElementInMiddleViewport(element)) {
element.style.opacity = '1';
element.classList.add('move-up');
}
});
});
function isElementInMiddleViewport(element) {
const rect = element.getBoundingClientRect();
const elementMiddle = rect.top + rect.height / 2;
return elementMiddle >= 0 && elementMiddle <= window.innerHeight;
}
// GSAP SMOOTH SCROLLING
gsap.registerPlugin(ScrollToPlugin);
function handleScroll(event) {
event.preventDefault();
const deltaY = event.deltaY;
const deltaX = event.deltaX;
if (deltaY !== 0) {
const scrollAmount = deltaY * 5;
gsap.to(window, {
scrollTo: {
y: '+=' + scrollAmount,
autoKill: false
},
duration: 1,
ease: 'power2.out'
});
}
}
// GSAP HORIZONTAL SCROLL
gsap.registerPlugin(ScrollTrigger);
window.addEventListener("load", function() {
let container = document.querySelector(".horizontal-scroller");
let containerWidth = container.scrollWidth - document.documentElement.clientWidth;
gsap.to(container, {
x: () => -containerWidth,
scrollTrigger: {
markers: false,
trigger: '.horizontal-wrapper',
start: 'top top',
scrub: 0.5,
pin: '.horizontal-container',
end: () => "+=" + containerWidth,
invalidateOnRefresh: true,
}
})
});
// ROAD SHRINKING WHILE SCROLLING
window.addEventListener("scroll", function() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
var road = document.querySelector(".road");
var windowHeight = window.innerHeight;
var roadHeight = windowHeight - (scrollTop / windowHeight) * windowHeight * 1;
road.style.height = roadHeight + "px";
});
// FIXED CARDS
const cards = document.querySelector('.cards');
const cardTexts = document.querySelectorAll('.cards-text');
const images = document.querySelectorAll('.cards-image');
const cta = document.querySelector('.cards-cta');
window.addEventListener('scroll', () => {
const windowHeight = window.innerHeight;
const cardsTop = cards.getBoundingClientRect().top;
const cardsBottom = cards.getBoundingClientRect().bottom;
if (cardsTop <= 0 && cardsBottom >= windowHeight) {
images.forEach((image) => {
image.classList.add('fixed');
});
cta.classList.add('fixed');
} else {
images.forEach((image) => {
image.classList.remove('fixed');
});
cta.classList.remove('fixed');
}
cardTexts.forEach((cardText, index) => {
const windowHeight = window.innerHeight;
const cardTextTop = cardText.getBoundingClientRect().top;
if (cardTextTop <= windowHeight / 2 || index === 0) {
images[index].style.opacity = '1';
images[index].style.display = 'flex';
} else {
images[index].style.opacity = '0';
images[index].style.display = 'none';
}
});
});
// ZOOM IN
gsap.timeline({
scrollTrigger: {
trigger: ".zoom",
scrub: true,
start: "top top",
end: "+=1000%",
pin: true,
}
})
.to(".zoom-circle", {
scale: 12
}, "sameTime")
.to(".zoom-content", {
scale: 1
}, "sameTime");
// CUSTOM CURSOR
document.addEventListener('DOMContentLoaded', function() {
var cursor = document.createElement('div');
cursor.classList.add('custom-cursor');
document.body.appendChild(cursor);
document.addEventListener('mousemove', function(e) {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
});
var linkElements = document.querySelectorAll('.link, .cards-cta');
linkElements.forEach(function(element) {
element.addEventListener('mouseenter', function() {
cursor.classList.add('scale-up');
});
element.addEventListener('mouseleave', function() {
cursor.classList.remove('scale-up');
});
});
});
Also see: Tab Triggers