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="scroller" data-scroller>
<header data-header>
<nav class="header__nav">
<div class="header__left-content">
<a class="header__home-link" href="#home">Home</a>
</div>
<ul class="header__list">
<li>
<a href="#about-us" data-link>About us</a>
</li>
<li>
<a href="#the-flavours" data-link>The flavours</a>
</li>
<li>
<a href="#get-in-touch" data-link>Get in touch</a>
</li>
</ul>
</nav>
</header>
<main>
<section data-section="raspberry" id="home">
<div class="container grid">
<div class="section__img-col">
<img class="section__img" src="https://assets.codepen.io/85648/ice-creams-03.svg" alt="drawing of three smiling ice cream scoops in a bowl" />
</div>
<div class="section__content-col">
<h1>Happy Face Ice Cream Parlour</h1>
<p>A little ice cream parlour with big dreams.</p>
<p>We pride ourselves on flavours beyond your wildest dreams, and customer service that’s out of this world!</p>
<p>Order your favourite flavours online, or call us today to find out how we can make your special occasions extra delightful!</p>
<a class="section__link" href="#0">Shop now</a>
</div>
</div>
</section>
<section data-section="mint" id="about-us">
<div class="container grid">
<div class="section__img-col">
<img src="https://assets.codepen.io/85648/ice-creams-04.svg" alt="smiling scoop of ice cream with drips" />
</div>
<div class="section__content-col">
<h2>About us</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</section>
<section data-section="vanilla" id="the-flavours">
<div class="container grid">
<div class="section__img-col">
<img src="https://assets.codepen.io/85648/ice-creams-01.svg" alt="three happy ice creams" />
</div>
<div class="section__content-col">
<h2>The flavours</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</section>
<section data-section="chocolate" id="get-in-touch">
<div class="container grid">
<div class="section__img-col">
<img class="section__img" src="https://assets.codepen.io/85648/ice-creams-02.svg" alt="spoon with drips" />
</div>
<div class="section__content-col">
<h2 data-section-title>Get in touch</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</section>
</main>
</div>
@import url("https://fonts.googleapis.com/css?family=Open+Sans:400,700");
/* Variables */
:root {
--mint: #5ae8d5;
--chocolate: #573e31;
--raspberry: #f2308e;
--vanilla: #faf2c8;
--headerText: var(--vanilla);
--headerBg: var(--raspberry);
}
/* --Reset and boilerplate stuff-- */
* {
box-sizing: border-box;
}
body {
font-family: "Open Sans", sans-serif;
margin: 0;
background: var(--vanilla);
color: var(--chocolate);
line-height: 1.6;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
svg {
width: 100%;
height: auto;
fill: currentColor;
}
img {
display: block;
max-width: 100%;
}
h1 {
line-height: 1.2;
}
@media (min-width: 40em) {
body {
font-size: 1.2rem;
}
h1 {
font-size: 3.5rem;
}
}
a {
color: inherit;
text-decoration: none;
}
section {
padding: 5rem 0;
min-height: 100vh;
display: grid;
place-items: center;
}
/* ----- */
/* --Header-- */
header {
position: fixed;
width: 100%;
padding: 0 max(1rem, 3vw);
background-color: var(--headerBg);
color: var(--headerText);
font-weight: 700;
}
/* ----- */
/* --Layout stuff-- */
.section__img {
max-width: 12rem;
margin: 0 auto;
}
@media (min-width: 40em) {
.section__img {
max-width: none;
}
}
section:last-child .section__img {
max-width: 10rem;
}
.container {
max-width: 60rem;
padding: 0 min(2rem, 5vw);
}
@media (min-width: 40rem) {
.grid {
display: grid;
align-items: center;
grid-template-columns: 1fr 2fr;
gap: 3rem;
}
}
.header__nav {
display: flex;
align-items: center;
}
.header__list {
display: none;
margin-left: auto;
}
@media (min-width: 40rem) {
.header__list {
display: flex;
}
}
.header__list a {
display: block;
padding: 1rem;
}
/* ----- */
/* --Secton specific styles, not related to demo-- */
.section__link {
display: inline-block;
background: var(--chocolate);
padding: 1rem 1.5rem;
color: var(--vanilla);
border-radius: 0.5rem;
font-weight: 700;
margin-top: 1.5rem;
}
/* ----- */
/* --Section colors-- */
[data-section="raspberry"] {
background-color: var(--raspberry);
color: var(--vanilla);
}
[data-section="mint"] {
background-color: var(--mint);
color: var(--chocolate);
}
[data-section="vanilla"] {
background-color: var(--vanilla);
color: var(--chocolate);
}
[data-section="chocolate"] {
background-color: var(--chocolate);
color: var(--vanilla);
}
/* ----- */
/* --Setting the custom properties for header colors-- */
[data-theme="raspberry"] {
--headerText: var(--raspberry);
--headerBg: var(--vanilla);
}
[data-theme="mint"] {
--headerText: var(--mint);
--headerBg: var(--chocolate);
}
[data-theme="chocolate"] {
--headerText: var(--chocolate);
--headerBg: var(--vanilla);
}
/* ----- */
/* --Setting the scroll root - because Codepen puts the content in an iframe-- */
.scroller {
height: 100vh;
width: 100%;
overflow: auto;
}
/* ----- */
const header = document.querySelector('[data-header]')
const sections = [...document.querySelectorAll('[data-section]')]
const scrollRoot = document.querySelector('[data-scroller]')
const headerLinks = [...document.querySelectorAll('[data-link]')]
const options = {
root: scrollRoot,
rootMargin: `${header.offsetHeight * -1}px`,
threshold: 0
}
const onIntersect = (entries) => {
entries.forEach((entry) => {
const theme = entry.target.dataset.section
header.setAttribute('data-theme', theme)
})
}
const observer = new IntersectionObserver(onIntersect, options)
sections.forEach((section) => {
observer.observe(section)
})
Also see: Tab Triggers