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.
<body>
<div class="feedback-container">
<div class="steps">
<div class="step active"></div>
<div class="step"></div>
<div class="step"></div>
<div class="step"></div>
</div>
<h2>We'd love your feedback!</h2>
<p class="subtitle">Help us make our product even better for you.</p>
<form id="feedbackForm" novalidate>
<div class="input-group">
<label>What aspects are you reviewing?</label>
<div class="tags" role="group" aria-label="Select categories">
<button type="button" class="tag" role="checkbox" aria-checked="false">User Interface</button>
<button type="button" class="tag" role="checkbox" aria-checked="false">Performance</button>
<button type="button" class="tag" role="checkbox" aria-checked="false">Features</button>
<button type="button" class="tag" role="checkbox" aria-checked="false">Support</button>
<button type="button" class="tag" role="checkbox" aria-checked="false">Documentation</button>
</div>
<div class="validation-message"></div>
</div>
<div class="input-group">
<label>How was your experience?</label>
<div class="mood-selector" role="radiogroup" aria-label="Rate your experience">
<div class="mood" role="radio" tabindex="0" aria-checked="false">
<span class="mood-emoji" aria-hidden="true">😞</span>
<span class="mood-label">Poor</span>
</div>
<div class="mood" role="radio" tabindex="0" aria-checked="false">
<span class="mood-emoji" aria-hidden="true">😐</span>
<span class="mood-label">Okay</span>
</div>
<div class="mood" role="radio" tabindex="0" aria-checked="false">
<span class="mood-emoji" aria-hidden="true">🙂</span>
<span class="mood-label">Good</span>
</div>
<div class="mood" role="radio" tabindex="0" aria-checked="false">
<span class="mood-emoji" aria-hidden="true">😊</span>
<span class="mood-label">Great</span>
</div>
<div class="mood" role="radio" tabindex="0" aria-checked="false">
<span class="mood-emoji" aria-hidden="true">🤩</span>
<span class="mood-label">Amazing</span>
</div>
</div>
<div class="validation-message"></div>
</div>
<div class="input-group">
<label for="feedback">Tell us more about it</label>
<textarea
id="feedback"
placeholder="Share your thoughts and suggestions..."
maxlength="500"
required
aria-required="true"
></textarea>
<div class="char-counter">0/500</div>
<div class="validation-message"></div>
</div>
<button type="submit" class="submit-btn">Submit Feedback</button>
</form>
</div>
</body>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Inter', -apple-system, sans-serif;
}
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #0f172a;
padding: 20px;
color: #fff;
}
.feedback-container {
width: 100%;
max-width: 600px;
background: #1e293b;
border-radius: 24px;
padding: 2rem;
position: relative;
overflow: hidden;
animation: fadeIn 0.5s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.feedback-container::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 6px;
background: linear-gradient(90deg, #00f5a0 0%, #00d9f5 100%);
}
.steps {
display: flex;
gap: 10px;
margin-bottom: 2rem;
}
.step {
width: 25%;
height: 3px;
background: #334155;
border-radius: 4px;
transition: all 0.3s ease;
}
.step.active {
background: #00f5a0;
box-shadow: 0 0 10px rgba(0, 245, 160, 0.3);
}
h2 {
font-size: 1.75rem;
margin-bottom: 0.5rem;
background: linear-gradient(90deg, #00f5a0 0%, #00d9f5 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.subtitle {
color: #94a3b8;
margin-bottom: 2rem;
}
.input-group {
margin-bottom: 1.5rem;
position: relative;
}
.input-group label {
display: block;
margin-bottom: 0.5rem;
color: #e2e8f0;
font-size: 0.9rem;
}
.input-group input,
.input-group textarea {
width: 100%;
padding: 1rem;
background: #334155;
border: 2px solid transparent;
border-radius: 12px;
color: #fff;
font-size: 1rem;
transition: all 0.3s ease;
}
.input-group input:focus,
.input-group textarea:focus {
outline: none;
border-color: #00f5a0;
background: #475569;
box-shadow: 0 0 0 4px rgba(0, 245, 160, 0.15);
}
.input-group input.invalid,
.input-group textarea.invalid {
border-color: #ff4d4d;
}
.input-group input.invalid:focus,
.input-group textarea.invalid:focus {
box-shadow: 0 0 0 4px rgba(255, 77, 77, 0.15);
}
.validation-message {
position: absolute;
bottom: -20px;
left: 0;
color: #ff4d4d;
font-size: 0.8rem;
opacity: 0;
transform: translateY(-10px);
transition: all 0.3s ease;
}
.validation-message.visible {
opacity: 1;
transform: translateY(0);
}
.input-group textarea {
height: 120px;
resize: vertical;
}
.char-counter {
position: absolute;
right: 1rem;
bottom: 1rem;
color: #94a3b8;
font-size: 0.8rem;
pointer-events: none;
}
.tags {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 1.5rem;
}
.tag {
padding: 0.75rem 1.25rem;
background: #334155;
border: none;
border-radius: 100px;
color: #fff;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
.tag:hover {
background: #475569;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 245, 160, 0.15);
}
.tag:focus {
outline: none;
box-shadow: 0 0 0 3px rgba(0, 245, 160, 0.3);
}
.tag.active {
background: #00f5a0;
color: #0f172a;
font-weight: 600;
}
.mood-selector {
display: flex;
justify-content: space-between;
margin-bottom: 2rem;
}
.mood {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
cursor: pointer;
transition: all 0.3s ease;
padding: 0.5rem;
border-radius: 12px;
}
.mood:hover {
background: #334155;
}
.mood:hover .mood-emoji {
transform: scale(1.2);
}
.mood-emoji {
font-size: 2rem;
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.mood.selected {
background: #334155;
}
.mood.selected .mood-label {
color: #00f5a0;
}
.mood-label {
font-size: 0.8rem;
color: #94a3b8;
transition: color 0.3s ease;
}
.submit-btn {
width: 100%;
padding: 1rem;
background: linear-gradient(90deg, #00f5a0 0%, #00d9f5 100%);
border: none;
border-radius: 12px;
color: #0f172a;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
.submit-btn:hover {
opacity: 0.9;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 245, 160, 0.2);
}
.submit-btn:focus {
outline: none;
box-shadow: 0 0 0 4px rgba(0, 245, 160, 0.3);
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
transform: scale(0);
animation: ripple 0.6s linear;
pointer-events: none;
}
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
@media (max-width: 480px) {
.feedback-container {
padding: 1.5rem;
}
.mood-selector {
flex-wrap: wrap;
gap: 1rem;
justify-content: center;
}
.mood {
width: 30%;
}
}
// Ripple effect
function createRipple(event) {
const button = event.currentTarget;
const ripple = document.createElement('span');
const diameter = Math.max(button.clientWidth, button.clientHeight);
const radius = diameter / 2;
ripple.style.width = ripple.style.height = `${diameter}px`;
ripple.style.left = `${event.clientX - button.offsetLeft - radius}px`;
ripple.style.top = `${event.clientY - button.offsetTop - radius}px`;
ripple.className = 'ripple';
button.appendChild(ripple);
ripple.addEventListener('animationend', () => {
ripple.remove();
});
}
// Tag selection
const tags = document.querySelectorAll('.tag');
tags.forEach(tag => {
tag.addEventListener('click', () => {
tag.classList.toggle('active');
tag.setAttribute('aria-checked', tag.classList.contains('active'));
});
tag.addEventListener('click', createRipple);
});
// Mood selection
const moods = document.querySelectorAll('.mood');
moods.forEach(mood => {
mood.addEventListener('click', () => {
moods.forEach(m => {
m.classList.remove('selected');
m.setAttribute('aria-checked', 'false');
});
mood.classList.add('selected');
mood.setAttribute('aria-checked', 'true');
});
// Keyboard navigation
mood.addEventListener('keypress', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
mood.click();
}
});
});
// Character counter
const textarea = document.querySelector('textarea');
const charCounter = document.querySelector('.char-counter');
textarea.addEventListener('input', () => {
const length = textarea.value.length;
charCounter.textContent = `${length}/500`;
});
// Form validation
const form = document.getElementById('feedbackForm');
form.addEventListener('submit', (e) => {
e.preventDefault();
let isValid = true;
// Validate tags
const selectedTags = document.querySelectorAll('.tag.active');
if (selectedTags.length === 0) {
isValid = false;
showError(tags[0].parentElement, 'Please select at least one category');
}
// Validate mood
const selectedMood = document.querySelector('.mood.selected');
if (!selectedMood) {
isValid = false;
showError(moods[0].parentElement, 'Please select your experience rating');
}
// Validate textarea
if (!textarea.value.trim()) {
isValid = false;
showError(textarea, 'Please provide your feedback');
}
if (isValid) {
// Add success animation or submit form
console.log('Form submitted successfully');
}
});
function showError(element, message) {
const validationMessage = element.parentElement.querySelector('.validation-message');
validationMessage.textContent = message;
validationMessage.classList.add('visible');
if (element.classList) {
element.classList.add('invalid');
}
setTimeout(() => {
validationMessage.classList.remove('visible');
if (element.classList) {
element.classList.remove('invalid');
}
}, 3000);
}
// Add ripple to submit button
document.querySelector('.submit-btn').addEventListener('click', createRipple);
Also see: Tab Triggers