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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
.c-toggle#theme
.c-toggle__body
i.c-toggle__icon(data-feather="moon")
i.c-toggle__icon(data-feather="sun")
.l-wrapper
header.c-header
h4 Design Session Cheat Sheet
p Even if you’re working with people who are on your team, reiterating project goals is beneficial and can help focus the group. Fill out this template to share at the start of a session. You don’t have to recite it word-for-word, unless you want.
main#main
.c-field
label.c-field__label Project Name
input.c-field__input(name="projectName" type="text" placeholder="Threat Level Midnight")
.c-field
label.c-field__label Project Goal
input.c-field__input(name="projectGoal" type="text" placeholder="to chill with my homies")
.c-field
label.c-field__label Project Scenario
input.c-field__input(name="projectScenario" type="text" placeholder="How might we...")
.c-field
label.c-field__label Constraints
label.c-radio
input.c-radio__input(type="checkbox" value="Time")
span.c-radio__checkbox
span.c-radio__label Time
label.c-radio
input.c-radio__input(type="checkbox" value="Technical Limits")
span.c-radio__checkbox
span.c-radio__label Technical Limits
label.c-radio
input.c-radio__input(type="checkbox" value="Scope")
span.c-radio__checkbox
span.c-radio__label Scope
label.c-radio
input.c-radio__input(type="checkbox" value="Cost")
span.c-radio__checkbox
span.c-radio__label Cost
label.c-radio
input.c-radio__input(type="checkbox" value="Legal")
span.c-radio__checkbox
span.c-radio__label Legal
.c-field
label.c-field__label Project Stage
label.c-radio
input.c-radio__input(type="radio" checked name="projectStage" value="early")
span.c-radio__checkbox.c-radio__radiobox
span.c-radio__label Early
label.c-radio
input.c-radio__input(type="radio" name="projectStage" value="on time")
span.c-radio__checkbox.c-radio__radiobox
span.c-radio__label On Time
label.c-radio
input.c-radio__input(type="radio" name="projectStage" value="late")
span.c-radio__checkbox.c-radio__radiobox
span.c-radio__label Late
.c-field
label.c-field__label Research
textarea.c-field__input(name="projectResearch" rows="5" placeholder="Usage behaviors, surveys, qualitative findings, or competitive examples")
.c-field
label.c-field__label Areas of interest
input.c-field__input(name="projectInterest" type="text" placeholder="I'd like to focus on...")
.c-field
label.c-field__label Session Goal
input.c-field__input(name="projectSessionGoals" type="text" placeholder="to chill with my homies")
button.c-button.c-button--full.c-button--primary(onclick="generateText(addDesignSheet())") Generate Introduction
:root {
--black: #000000;
--white: #ffffff;
--trans-black: rgba(0,0,0, 0.2);
--system-base-9: rgba(28, 28, 30, 1);
--system-base-8: rgba(44, 44, 46, 1);
--system-base-7: rgba(58, 58, 60, 1);
--system-base-6: rgba(72, 72, 74, 1);
--system-base-5: rgba(99, 99, 102, 1);
--system-base-4: rgba(142, 142, 147, 1);
--system-base-3: rgba(174, 174, 178, 1);
--system-base-2: rgba(199, 199, 204, 1);
--system-base-1: rgba(209, 209, 214, 1);
--system-base-50: rgba(229, 229, 234, 1);
--system-base-0: rgba(242, 242, 247, 1);
--danger: rgba(255,69,58,1);
--success: rgba(48,209,88,1);
--warning: rgba(255,159,10,1);
--info: rgba(255,69,58,1);
--secondary: var(--system-base-4);
--primary: rgba(10,132,255,1);
--trans-primary: rgba(10,132,255,.2);
--root-bg: var(--system-base-50);
--root-color: var(--system-base-7);
--header-color: var(--system-base-9);
--component-border: var(--system-base-2);
--component-bg-hover: var(--system-base-1);
}
:root.theme--dark {
--root-bg: var(--system-base-9);
--root-color: var(--system-base-4);
--header-color: var(--system-base-1);
--component-border: var(--system-base-2);
--component-bg-hover: var(--system-base-8);
}
$states: (
primary: var(--primary),
secondary: var(--secondary),
danger: var(--danger),
success: var(--success),
warning: var(--warning),
info: var(--info),
light: var(--header-color)
);
$spacing-unit: 0.8rem;
$border-radius: 0.4rem;
$transition-time: 240ms;
$type-sizes: (
h1: 70px,
h2: 40px,
h3: 28px,
h4: 24px,
h5: 16px,
h6: 14px,
p-lead: 20px,
p-small: 14px,
p: 17px,
small: 14px,
small-caps: 12px
);
$type-sizes-mobile: (
h1: 40px,
h2: 32px,
h3: 26px,
h4: 22px,
h5: 18px,
h6: 16px,
p-lead: 18px,
p-small: 14px,
p: 16px,
small: 14px,
small-caps: 12px
);
@function type-size($key) {
@if(map-get($type-sizes, $key)) {
@return map-get($type-sizes, $key)
}
@else {
@warn 'The size you entered does not exist'
}
}
@function type-size-mobile($key) {
@if(map-get($type-sizes-mobile, $key)) {
@return map-get($type-sizes-mobile, $key)
}
@else {
@warn 'The size you entered does not exist'
}
}
@mixin transition($variance) {
transition: all $transition-time*$variance ease-out 0s;
}
html {
box-sizing: border-box;
font-size: 62.5%;
}
*,*:before, *:after {
box-sizing: inherit;
}
html, body {
width: 100%;
height: 100%;
}
body {
font-size: 1.6rem;
background: var(--root-bg);
color: var(--root-color);
font-family: system-ui;
}
@mixin headerType($letter-spacing, $margin-bottom, $map-size) {
letter-spacing: $letter-spacing;
margin-bottom: $margin-bottom;
margin-top: 0;
font-size: type-size($map-size);
color: var(--header-color);
@media screen and (max-width: 768px) {
font-size: type-size-mobile($map-size);
}
}
$headers: (h1,h2,h3,h4,h5,h6);
@each $header in $headers {
#{$header} {
@include headerType(0, 1.6rem, #{$header});
}
}
p {
line-height: 1.6;
margin-top: 0;
margin-bottom: 1.6rem;
}
.l-wrapper {
width: 100%;
max-width: 700px;
margin: auto;
padding-left: $spacing-unit*2;
padding-right: $spacing-unit*2;
padding-top: 10vh;
}
.c-field {
margin: 0 0 $spacing-unit*2;
display: block;
width: 100%;
position: relative;
&__label {
position: relative;
font-size: type-size(small-caps);
text-transform: uppercase;
color: var(--secondary);
margin-bottom: $spacing-unit;
display: block;
}
&__input {
border: 0;
color: inherit;
font-family: inherit;
padding: $spacing-unit*2;
border-radius: $border-radius;
line-height: 1;
display: inline-flex;
align-items: center;
background: var(--component-bg-hover);
width: 100%;
@include transition(.5);
&:focus, &:active {
outline: 0;
box-shadow: 0px 0px 0px 1px var(--primary);
}
}
&__text {
cursor: pointer;
color: var(--primary);
&:hover {
&:after {
opacity: 1;
}
}
}
}
.c-radio {
user-select: none;
cursor: pointer;
display: inline-flex;
align-items: center;
margin-right: $spacing-unit*2;
margin-bottom: $spacing-unit*2;
border-radius: $border-radius/2;
&__input {
position: absolute;
opacity: 0;
height: 1px;
width: 1px;
}
&__label {
color: var(--secondary);
}
&:hover, &:focus {
background: var(--trans-primary);
box-shadow: 0px 0px 0px $spacing-unit/2 var(--trans-primary);
.c-radio__checkbox {
background: var(--trans-black);
&:after {
opacity: .3;
}
}
}
&__checkbox {
$size: $spacing-unit*2.5;
width: $size;
height: $size;
border-radius: $border-radius;
border: 1px solid var(--component-border);
display: inline-block;
margin-right: $spacing-unit;
position: relative;
@include transition(.5);
&.c-radio__radiobox {
border-radius: 50%;
}
&:after {
content: '';
color: var(--white);
width: $spacing-unit*.8;
height: $spacing-unit*1.5;
position: absolute;
border-bottom: 2px solid;
border-right: 2px solid;
top: 40%;
left: 50%;
transform: translate(-50%, -50%) rotate(45deg);
opacity: 0;
}
}
&__input:checked ~ .c-radio__checkbox {
background: var(--primary);
border-color: var(--primary);
&:after {
opacity: 1;
}
}
&__input:checked ~ .c-radio__label {
color: inherit;
}
}
.c-button {
font-family: inherit;
color: inherit;
background: var(--secondary);
color: var(--white);
text-shadow: 0px 1px 1px rgba(black, .2);
border: 0;
cursor: pointer;
padding: $spacing-unit*2;
border-radius: $border-radius;
margin-bottom: 1.6rem;
@include transition(.5);
&--primary {
background: var(--primary);
}
&--success {
background: var(--success);
}
&--full {
width: 100%;
display: block;
}
&--link {
padding: 0;
text-decoration: underline;
text-shadow: none;
color: var(--primary);
background: transparent;
}
&__icon {
width: 1em;
position: relative;
top: 0.5rem;
margin-right: 0.8rem;
}
&:hover, &:focus {
opacity: .8;
}
&:focus, &:active {
outline: 0;
}
}
@each $key,$val in $states {
.u-text--#{$key} {
color: $val !important;
}
}
.u-fade {
opacity: 0;
animation: fade 240ms ease-out 0s forwards;
}
.loader {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.hollow-dots-spinner, .hollow-dots-spinner * {
box-sizing: border-box;
}
.hollow-dots-spinner {
height: 15px;
width: calc(30px * 3);
}
.hollow-dots-spinner .dot {
width: 15px;
height: 15px;
margin: 0 calc(15px / 2);
border: calc(15px / 5) solid var(--primary);
border-radius: 50%;
float: left;
transform: scale(0);
animation: hollow-dots-spinner-animation 1000ms ease infinite 0ms;
}
.hollow-dots-spinner .dot:nth-child(1) {
animation-delay: calc(300ms * 1);
}
.hollow-dots-spinner .dot:nth-child(2) {
animation-delay: calc(300ms * 2);
}
.hollow-dots-spinner .dot:nth-child(3) {
animation-delay: calc(300ms * 3);
}
.c-toggle {
$size: 4rem;
width: $size;
height: $size;
overflow: hidden;
display: inline-block;
background: red;
position: absolute;
top: 1.6rem;
right: 1.6rem;
border-radius: $border-radius;
cursor: pointer;
color: var(--component-bg-hover);
background: var(--header-color);
box-shadow: 0px 2px 2px rgba(black, .2), 0px 5px 12px rgba(black, .1);
&__body {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
padding-top: 0.4rem;
padding-bottom: 0.4rem;
position: absolute;
top: 0;
transition: all 320ms ease-out 100ms;
}
&__icon {
display: block;
width: 3.2rem;
margin: 0.4rem;
}
&--active {
.c-toggle__body {
top: -3.2rem;
}
}
}
@keyframes hollow-dots-spinner-animation {
50% {
transform: scale(1);
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes fade {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
console.clear();
document.getElementById('theme').addEventListener('click', () => {
document.documentElement.classList.toggle('theme--dark');
document.getElementById('theme').classList.toggle('c-toggle--active');
})
feather.replace();
function genConstraints() {
var constraints = [];
document.querySelectorAll('input[type="checkbox"]:checked').forEach(item => {
constraints.push(item.value);
})
return constraints;
}
var designSheet = {}
function addDesignSheet() {
var designSheet = {
name: document.getElementsByName("projectName")[0].value,
goal: document.getElementsByName("projectGoal")[0].value,
scenario: document.getElementsByName("projectScenario")[0].value,
constraints: genConstraints(),
stage: document.querySelector('input[type="radio"]:checked').value,
research: document.getElementsByName("projectResearch")[0].value,
interests: document.getElementsByName("projectInterest")[0].value,
sessionGoals: document.getElementsByName("projectSessionGoals")[0].value
};
return designSheet;
}
const loader = () => {
const newLoader = document.createElement('div');
newLoader.classList = 'loader';
newLoader.innerHTML = '<div class="hollow-dots-spinner" :style="spinnerStyle"><div class="dot"></div><div class="dot"></div><div class="dot"></div></div>';
document.body.appendChild(newLoader);
}
const generateForm = () => {
document.querySelector('.l-wrapper').innerHTML = '';
loader();
setTimeout(() => {
const newBlock = document.createElement('div');
newBlock.classList = 'u-fade';
const styleClass = 'u-text--light';
newBlock.innerHTML = `
<header class="c-header">
<h4>Design Session Cheat Sheet</h4>
<p>Even if you’re working with people who are on your team, reiterating project goals is beneficial and can help focus the group. Fill out this template to share at the start of a session. You don’t have to recite it word-for-word, unless you want.</p>
</header>
<main id="main">
<div class="c-field">
<label class="c-field__label">Project Name</label>
<input class="c-field__input" name="projectName" type="text" placeholder="Threat Level Midnight"/>
</div>
<div class="c-field">
<label class="c-field__label">Project Goal</label>
<input class="c-field__input" name="projectGoal" type="text" placeholder="to chill with my homies"/>
</div>
<div class="c-field">
<label class="c-field__label">Project Scenario</label>
<input class="c-field__input" name="projectScenario" type="text" placeholder="How might we..."/>
</div>
<div class="c-field">
<label class="c-field__label">Constraints</label>
<label class="c-radio">
<input class="c-radio__input" type="checkbox" value="Time"/><span class="c-radio__checkbox"></span><span class="c-radio__label">Time</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="checkbox" value="Technical Limits"/><span class="c-radio__checkbox"></span><span class="c-radio__label">Technical Limits</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="checkbox" value="Scope"/><span class="c-radio__checkbox"></span><span class="c-radio__label">Scope</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="checkbox" value="Cost"/><span class="c-radio__checkbox"></span><span class="c-radio__label">Cost</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="checkbox" value="Legal"/><span class="c-radio__checkbox"></span><span class="c-radio__label">Legal</span>
</label>
</div>
<div class="c-field">
<label class="c-field__label">Project Stage</label>
<label class="c-radio">
<input class="c-radio__input" type="radio" checked="checked" name="projectStage" value="early"/><span class="c-radio__checkbox c-radio__radiobox"></span><span class="c-radio__label">Early</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="radio" name="projectStage" value="on time"/><span class="c-radio__checkbox c-radio__radiobox"></span><span class="c-radio__label">On Time</span>
</label>
<label class="c-radio">
<input class="c-radio__input" type="radio" name="projectStage" value="late"/><span class="c-radio__checkbox c-radio__radiobox"></span><span class="c-radio__label">Late</span>
</label>
</div>
<div class="c-field">
<label class="c-field__label">Research</label>
<textarea class="c-field__input" name="projectResearch" rows="5" placeholder="Usage behaviors, surveys, qualitative findings, or competitive examples"></textarea>
</div>
<div class="c-field">
<label class="c-field__label">Areas of interest</label>
<input class="c-field__input" name="projectInterest" type="text" placeholder="I'd like to focus on..."/>
</div>
<div class="c-field">
<label class="c-field__label">Session Goal</label>
<input class="c-field__input" name="projectSessionGoals" type="text" placeholder="to chill with my homies"/>
</div>
</main>
<button class="c-button c-button--full c-button--primary" onclick="generateText(addDesignSheet())">Generate Introduction</button>
`;
document.querySelector('.loader').remove();
document.querySelector('.l-wrapper').appendChild(newBlock);
feather.replace()
}, 1000);
}
const generateText = (formData) => {
document.querySelector('.l-wrapper').innerHTML = '';
loader();
setTimeout(() => {
const newBlock = document.createElement('div');
newBlock.classList = 'u-fade';
const styleClass = 'u-text--light';
newBlock.innerHTML = `
<button class="c-button c-button--link" onclick="generateForm()"><i class="c-button__icon" data-feather="arrow-left"></i>Back to edit</button>
<h4>Welcome, everyone!</h4>
<p>I’m currently working on <strong class="${styleClass}">${formData.name}</strong>. The goal of this project is <strong class="${styleClass}">${formData.goal}</strong>. In other words, how might we <strong class="${styleClass}">${formData.scenario}</strong>.</p>
<p>Currently, we're constrained by <strong class="${styleClass}">${formData.constraints.map((item, i) => {
if (formData.constraints.length === i + 1) {
return " and " + item
} else {
return " " + item
}
})}</strong>. The stage of this project is <strong class="${styleClass}">${formData.stage}</strong> as well.</p>
<p>Through our user research, we've discovered <strong class="${styleClass}">${formData.research}</strong>.</p>
<p>In this session, I'd like to focus on <strong class="${styleClass}">${formData.interests}</strong> and would consider this session successful if <strong class="${styleClass}">${formData.sessionGoals}</strong>.</p>
<p>Are there any questions before we begin?</p>
`;
document.querySelector('.loader').remove();
document.querySelector('.l-wrapper').appendChild(newBlock);
feather.replace();
}, 2000);
}
Also see: Tab Triggers