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="container mx-auto py-3 lg:py-9 lg:max-w-5xl">
<h1 class="block text-center text-2xl">Create account</h1>
<p class="block text-center text-base opacity-50 font-light">TourGuide JS example</h>
<div class="flex justify-center mt-9">
<aside class="max-w-sm" id="aside">
<div class="p-4 rounded-md bg-white border mb-4">
<input class="border px-3 py-2 rounded-md w-full" placeholder="Email address" type="email" id="userEmailInput"/>
<span id="emailErr" class="text-red-500 text-xs mt-2 text-center block"></span>
<button id="tg-trigger" class="bg-indigo-600 mt-3 w-full text-white rounded-md px-6 py-2">Create account</button>
</div><!-- end card -->
<div class="p-4 rounded-md bg-white border mb-4">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi aspernatur ipsam ex suscipit, deserunt tempora incidunt dicta error alias amet fugit quaerat sint ab magnam, provident vitae! Iusto, nobis dolorum.</p>
</div><!-- end card -->
</aside>
<main id="appMain" class="max-w-4xl p-4 w-full rounded-md bg-white border" style="display:none">
<div class="flex items-center mb-6">
<div id="profile" class="inline-flex items-center">
<picture class="text-center mr-4 block" style="width:60px;height:60px;">
<img src="https://avatars.dicebear.com/api/adventurer-neutral/bob.svg?r=33&scale=82" width="60" height="60">
</picture>
<div class="profile-meta">
<p id="userName" class="font-bold">Jeff Jones</p>
<p id="userEmail" class="text-gray-400 text-xs font-medium">jeff@mail.net</p>
</div><!-- end profile meta: name/email -->
</div>
<span id="tag" class="rounded-md border border-red-200 text-xs ml-auto bg-red-50 text-red-800 px-2 font-medium">Onboarded</span><!-- end onboarded tag -->
</div><!-- end profile header -->
<ul class="flex items-center gap-x-2 mb-4 justify-center border-b border-t py-4">
<li class="inline-block"><button id="homeBtn" class="inline-block rounded-sm py-1 px-3 bg-indigo-100" data-tg-placement="top">Home</button></li>
<li class="inline-block"><button id="listingsBtn" class="inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm">Listings</button></li>
</ul>
<section id="sectionHome">
<p class="mb-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis voluptatem consequuntur dolor eos praesentium accusamus voluptas nemo, magnam architecto fugit. Quam a assumenda blanditiis. Sapiente ea nulla rem quidem hic.</p>
<p class="mb-3">Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis voluptatem consequuntur dolor eos praesentium accusamus voluptas nemo, magnam architecto fugit. Quam a assumenda blanditiis. Sapiente ea nulla rem quidem hic.</p>
</section>
<section id="sectionListings" style="display:none;">
<div class="flex gap-x-3 items-center mb-4">
<input class="border px-3 py-2 rounded-md w-full h-10" placeholder="Search terms"/>
<select class="border px-3 py-2 rounded-md w-auto h-10">
<option>Example option 1</option>
<option>Example option 2</option>
</select>
<button id="tg-trigger" class="bg-indigo-600 h-10 w-33 text-white rounded-md px-6 py-1 max-w-12">Find</button>
</div>
<div class="grid grid-cols-6 gap-3">
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
<div class="col-span-2 bg-gray-100 rounded-md block" style="height: 180px;"></div>
</div>
</section>
</main>
</div><!-- end grid wrapper -->
</div><!-- end container -->
body{
background: #f1f1f1;
}
import TourGuideClient from "https://cdn.skypack.dev/@sjmc11/tourguidejs@0.0.7"; // Script
let userDisplayName = "test"
const tg = new TourGuideClient({
progressBar: "#999",
exitOnEscape: false,
exitOnClickOutside: false,
closeButton: false
});
tg.onFinish(()=>{
if(tag){
tag.innerHTML = "Tour complete"
tag.classList = "rounded-md border border-green-200 text-xs ml-auto bg-green-50 text-green-800 px-2 font-medium"
}
})
console.log("loaded");
function handleTourStart() {
emailErr.innerHTML = "";
// Validate email
if (!emailInput.value) {
console.log("emailErr", emailErr);
emailErr.innerHTML = "Enter email";
return;
}
// Create welcome step
tg.addSteps([
{
title: "First things first",
content:
`<p class="mb-3">Nice to have to you here ` +
emailInput.value +
`<p><p class="mb-3">Before we complete your registration we require your name.<p><input type="text" class="border px-3 py-2 rounded-md w-full" id="userNameInput" placeholder="Display name"/><span id="userNameErr" class="text-red-500 block"></span>`,
beforeLeave: ()=>{
return new Promise((resolve, reject)=>{
const nameInput = document.getElementById("userNameInput");
const nameErr = document.getElementById("userNameErr");
if(nameErr) nameErr.innerHTML = ""
if(nameInput && !nameInput.value) {
if(nameErr) nameErr.innerHTML = "Enter name"
return reject(false)
}
if(nameInput) userDisplayName = nameInput.value
return resolve(true)
})
}
},
{
title: "Welcome aboard 👋",
content: `<p class="mb-3">Awesome, you're officially registered.</p><p class="mb-3">Here's a tour of our application to get you started.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
target: "#profile",
beforeEnter: () => {
return new Promise((resolve) => {
if(aside) aside.style.display = 'none'
if(appMain) appMain.style.display = 'block'
if(userEmail) userEmail.innerHTML = emailInput.value
if(userName) userName.innerHTML = userDisplayName
return resolve(true)
});
},
},
{
title: "View your home screen 🏠",
content: `<p class="mb-3">The home screen is an overview of the application information that is relevant to you.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
target: "#homeBtn",
beforeEnter: () => {
return new Promise((resolve) => {
handleHomeClick()
return resolve(true)
});
},
},
{
title: "View the latest listings 🔍",
content: `<p class="mb-3">View the latest listings on the website and choose ones that suit you.</p><p class="text-xs opacity-50">Use the arrow keys or click next to continue.</p>`,
target: "#listingsBtn",
beforeEnter: () => {
return new Promise((resolve) => {
handleListingsClick()
return resolve(true)
});
},
},
{
title: "Looks like you're all set ✅",
content: `<p class="mb-3">Enjoy using our app.</p>`,
order: 99999999 // Enforce this as the final step
}
]);
console.log(emailInput.value);
tg.start();
}
const trigger = document.getElementById("tg-trigger");
const emailInput = document.getElementById("userEmailInput");
const emailErr = document.getElementById("emailErr");
const appMain = document.getElementById("appMain");
const aside = document.getElementById("aside");
const userName = document.getElementById("userName");
const userEmail = document.getElementById("userEmail");
const homeBtn = document.getElementById("homeBtn");
const sectionHome = document.getElementById("sectionHome");
const listingsBtn = document.getElementById("listingsBtn");
const sectionListings = document.getElementById("sectionListings");
const tag = document.getElementById("tag");
if (trigger) trigger.addEventListener("click", handleTourStart);
const handleHomeClick = ()=>{
homeBtn.classList = "inline-block rounded-sm py-1 px-3 bg-indigo-100"
listingsBtn.classList = "inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm"
if(sectionHome) sectionHome.style.display = "block"
if(sectionListings) sectionListings.style.display = "none"
}
if (homeBtn) homeBtn.addEventListener("click", handleHomeClick);
const handleListingsClick = ()=>{
homeBtn.classList = "inline-block rounded-sm py-1 px-3 bg-gray-100 hover:bg-gray-50 hover:shadow-sm"
listingsBtn.classList = "inline-block rounded-sm py-1 px-3 bg-indigo-100"
if(sectionHome) sectionHome.style.display = "none"
if(sectionListings) sectionListings.style.display = "block"
}
if (listingsBtn) listingsBtn.addEventListener("click", handleListingsClick);
Also see: Tab Triggers