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 id="content"></div>
<!--
"results" DIV is just for demonstration purposes
it shows the data that was collected from the
Sign Up panel.
-->
<div id="results">cpc-forms codepenchallenge</div>
body {
background: linear-gradient(to left, #000066 0%, #336699 100%);
}
#results {
position:absolute;
top:8px;
left:630px;
background-color:lightyellow;
height:438px;
width:300px;
display:none;
}
.signupTextBox {
font-size: 13pt;
}
.signupPanel {
background-color:silver;
font-family: Roboto, Arial, sans-serif;
font-size: 13pt;
font-weight: normal;
width:600px;
height:425px;
padding:6px;
border:solid gray 1px;
box-shadow: 8px 9px 5px gray;
}
.signupInnerPanel {
position:relative;
top:0px;
left:0px;
}
.signupHdr {
font-weight: bold;
font-size: 26px;
margin-left:9px;
color:#333333;
}
.signupFirstNameLbl {
position: absolute;
top: 45px;
left: 10px;
}
#signupFname {
position: absolute;
top: 40px;
left:180px;
border:solid gray 1px;
height:20px;
width:200px;
margin:0;
}
.signupLastNameLbl {
position: absolute;
top: 75px;
left: 10px;
}
#signupLname {
position: absolute;
top: 70px;
left:180px;
border:solid gray 1px;
height:20px;
width:200px;
margin:0;
}
.signupEmailLbl {
position: absolute;
top: 105px;
left: 10px;
}
#signupEmail {
position: absolute;
top: 100px;
left:180px;
border:solid gray 1px;
height:20px;
margin:0;
width:340px;
}
.signupPasswordLbl {
position: absolute;
top: 135px;
left: 10px;
}
#signupPassword {
position: absolute;
top: 130px;
left:180px;
border:solid gray 1px;
height:20px;
margin:0;
width:200px;
}
.signupPasswordReenterLbl {
position: absolute;
top: 165px;
left: 10px;
}
#signupPasswordReenter {
position: absolute;
top: 160px;
left:180px;
margin:0;
border:solid gray 1px;
height:20px;
width:200px;
}
.signupFavoritesTitle {
position: absolute;
left:15px;
top:209px;
font-weight:bold;
background-color:#999999;
color:white;
border:solid #595959 1px;
z-index:100;
width:95px;
padding-left:10px;
border-radius:6px;
}
.signupFavoritesPanel {
background-color:#e0e0eb;
position: absolute;
border:solid #3c3c5d 1px;
left:5px;
top:220px;
width:590px;
height:90px;
box-shadow: 7px 6px 3px gray;
border-radius:3px;
}
.signupFavColor {
position:absolute;
left:5px;
top:18px;
}
#signupColorBox {
position:absolute;
left:270px;
top:18px;
}
.signupSwatch {
width:20px;
height:20px;
border:solid white 2px;
cursor:pointer;
position:absolute;
}
.red {
background: linear-gradient(to top right, #ff0000 0%, #ff99cc 100%);
left:0px;
}
.orange {
background: linear-gradient(to top right, #ff6600 0%, #ffcc99 100%);
left:25px;
}
.yellow {
background-color:yellow;
left:50px;
}
.green {
background: linear-gradient(to left, #009933 0%, #99ff99 100%);
left:75px;
}
.blue {
background: linear-gradient(to bottom left, #0000ff 0%, #99ccff 100%);
left:100px;
}
.purple {
background: linear-gradient(to bottom, #6600ff 0%, #99ccff 100%);
left:125px;
}
.signupFavTurtle {
position:absolute;
left:5px;
top:55px;
}
.signupTurtles {
position:absolute;
left:270px;
top:55px;
width:300px;
height:25px;
}
.signupLeo {
position:absolute;
left:0;
}
.signupMikey {
position:absolute;
left:60px;
}
.signupDonnie {
position:absolute;
left:130px;
}
.signupRaph {
position:absolute;
left:220px;
}
.signupImAmazing {
position:absolute;
left:6px;
top:320px;
}
.signupYesYouAre {
position:absolute;
top:323px;
left:180px;
font-weight:bold;
display:none;
}
.signupImAmazingLbl {
position:absolute;
top:2px;
width:200px;
}
.signupBtn {
position:absolute;
left:6px;
top:362px;
width:110px;
height:30px;
font-weight: bold;
font-size:12pt;
}
#msg {
background-color:lightyellow;
position:absolute;
top:345px;
left:130px;
width:465px;
height:78px;
font-size:12pt;
overflow:scroll;
display:none;
font-size:10pt;
border: solid red 1px;
color:#80002a;
}
.signUpUl {
margin:0;
}
.signupSubmissionHdr {
position:absolute;
width:595px;
font-weight: bold;
font-size: 26px;
left:0;
top:40px;
color:#333333;
}
.signupThankyou {
position:absolute;
width:595px;
font-weight: bold;
font-size: 18px;
left:0;
top:200px;
color:#333333;
}
var pageDomain = {};
pageSetup();
function pageSetup() {
pageDomain.signup = SignUpObj({domElementId:"content",
title:"Codepen Challenge",
runWhenFilledOut:function(dta) {
// this demo code
// takes the interesting contents of dta
// and displays them out...
var results = $("#results")[0];
var s =[];
s[s.length] ="<b>Form Data Filled Out:</b>";
s[s.length] ="First Name: "+dta.firstName;
s[s.length] ="Last Name: "+dta.lastName;
s[s.length] ="Email Adr: "+dta.emailAdr; s[s.length] ="Password: "+dta.password;
s[s.length] ="Favorite Color: "+dta.favoriteColor;
s[s.length] ="Favorite Ninja Turtle: "+dta.favoriteNinjaTurtle;
s[s.length] ="I'm Amazing Flag: "+dta.imAmazing;
results.innerHTML = s.join("<br>");
results.style.display = "block";
}});
pageDomain.signup.renderForm();
} // end of function pageSetup()
/*
All a page might need is code like above.
Scroll down to see actual code for SignUpObj() function...
*/
function SignUpObj(params) {
var sId = params.domElementId;
var sTitle = params.title;
var cntr = $("#"+sId)[0];
var signupObj = {};
signupObj.sId = sId;
signupObj.domElement = cntr;
signupObj.title = sTitle;
signupObj.lastErrMsg = "";
signupObj.runWhenFilledOut = params.runWhenFilledOut;
signupObj.firstName = "";
signupObj.lastName = "";
signupObj.emailAdr = "";
signupObj.password = "";
signupObj.passwordReentered = "";
signupObj.favoriteColor = "";
signupObj.favoriteNinjaTurtle = "";
signupObj.imAmazing = false;
signupObj.renderForm = function() {
var s = [];
var Q = '"';
s[s.length] = "<div class='signupPanel'>";
s[s.length] = "<div class='signupInnerPanel' id='signupInnerPanel'>";
s[s.length] = "<div class='signupHdr'>";
// s[s.length] = "<center>";
s[s.length] = sTitle;
s[s.length] = " Sign Up";
// s[s.length] = "</center>";
s[s.length] = "</div>"; // signupHdr
s[s.length] = "<div class='signupFirstNameLbl'>";
s[s.length] = "First Name:";
s[s.length] = "</div>"; // signupFirstNameLbl
s[s.length] = "<input id='signupFname' maxlength='50'";
s[s.length] = " class='signupTextBox'>";
s[s.length] = "<div class='signupLastNameLbl'>";
s[s.length] = "Last Name:";
s[s.length] = "</div>"; // signupLastNameLbl
s[s.length] = "<input id='signupLname' maxlength='50'";
s[s.length] = " class='signupTextBox'>";
s[s.length] = "<div class='signupEmailLbl'>";
s[s.length] = "Email Address:";
s[s.length] = "</div>"; // signupEmailLbl
s[s.length] = "<input id='signupEmail' maxlength='255'";
s[s.length] = " class='signupTextBox'>";
s[s.length] = "<div class='signupPasswordLbl'>";
s[s.length] = "Password:";
s[s.length] = "</div>"; // signupPasswordLbl
s[s.length] = "<input id='signupPassword' maxlength='40'";
s[s.length] = " type='password' class='signupTextBox'>";
s[s.length] = "<div class='signupPasswordReenterLbl'>";
s[s.length] = "Re-enter Password:";
s[s.length] = "</div>"; //signupPasswordReenterLbl
s[s.length] = "<input id='signupPasswordReenter' maxlength='40'";
s[s.length] = " type='password' class='signupTextBox'>";
s[s.length] = "<div class='signupFavoritesTitle'>";
s[s.length] = "Favorites:";
s[s.length] = "</div>"; // signupFavoritesTitle
s[s.length] = "<div class='signupFavoritesPanel'>";
s[s.length] = "<div class='signupFavColor'>";
s[s.length] = "What's your Favorite Color?";
s[s.length] = "</div>"; //
s[s.length] = "<div id='signupColorBox'>";
s[s.length] = mkSwatch("red");
s[s.length] = mkSwatch("orange");
s[s.length] = mkSwatch("yellow");
s[s.length] = mkSwatch("green");
s[s.length] = mkSwatch("blue");
s[s.length] = mkSwatch("purple");
s[s.length] = "</div>"; // colorBox
s[s.length] = "<div class='signupFavTurtle'>";
s[s.length] = "What's your favorite Ninja Turtle?";
s[s.length] = "</div>"; // signupFavTurtle
s[s.length] = "<div class='signupTurtles'>";
s[s.length] = "<div class='signupLeo'>";
s[s.length] = "<input type='radio' name='favTurtle' value='Leo'>";
s[s.length] = "Leo";
s[s.length] = "</div>"; // signupLeo
s[s.length] = "<div class='signupMikey'>";
s[s.length] = "<input type='radio' name='favTurtle' value='Mikey'>";
s[s.length] = "Mikey";
s[s.length] = "</div>"; // signupMikey
s[s.length] = "<div class='signupDonnie'>";
s[s.length] = "<input type='radio' name='favTurtle' value='Donnie'>";
s[s.length] = "Donnie";
s[s.length] = "</div>"; // signupDonnie
s[s.length] = "<div class='signupRaph'>";
s[s.length] = "<input type='radio' name='favTurtle' value='Raph'>";
s[s.length] = "Raph";
s[s.length] = "</div>"; // signupRaph
s[s.length] = "</div>"; //signupTurtles
s[s.length] = "</div>"; // signupFavoritesPanel
s[s.length] = "<div class='signupImAmazing'>";
s[s.length] = "<input id='signupImAmazing' type="+Q+"checkbox"+Q+">";
s[s.length] = "<label class='signupImAmazingLbl'> I'm amazing</label>";
s[s.length] = "</div>"; // signupImAmazing
s[s.length] = "<div class='signupYesYouAre' id='signupYesYouAre'>";
s[s.length] = "Yes You Are!!</div>"; //
s[s.length] = "<button id='signupBtn' class='signupBtn' onclick='doSignup()'>Sign Up</button>";
s[s.length] = "<div id='msg'>nnnn";
s[s.length] = "</div>";
s[s.length] = "</div>"; // signupPanel
s[s.length] = "</div>"; // signupInnerPanel
cntr.innerHTML = s.join("");
cntr.addEventListener("click", checkClicks);
cntr.addEventListener("keyup", checkUserTextInputs);
cntr.addEventListener("change", checkChanges);
var sGiveFocusCode = [];
sGiveFocusCode[sGiveFocusCode.length] = "document.getElementById(";
sGiveFocusCode[sGiveFocusCode.length] = Q;
sGiveFocusCode[sGiveFocusCode.length] = "signupFname";
sGiveFocusCode[sGiveFocusCode.length] = Q;
sGiveFocusCode[sGiveFocusCode.length] = ").focus()";
/* if you are editing your own copy of the code, be
sure to comment out the line below before you do
so the code Pen Code code editor won't lose focus!
When you are done, don't forget to uncomment it! :)
... or, turn Auto Updating Preview Off!
*/
// setTimeout(sGiveFocusCode.join(""),20)
} // end of signupObj.renderForm()
function mkSwatch(sColor) {
var s=[];
var Q='"';
s[s.length] = "<div id='fav";
s[s.length] = sColor;
s[s.length] = "' ";
s[s.length] = "title=";
s[s.length] = Q;
s[s.length] = "click here to select "+sColor+" as your favorite color";
s[s.length] = Q;
s[s.length] = " class='signupSwatch ";
s[s.length] = sColor;
s[s.length] = "'></div>";
return s.join("");
} // end of function
function checkClicks(evt) {
var el = evt.target;
if (el.id === "signupBtn") {
doSignup();
return;
} // end if
var sClasses = el.className.split(" ");
if (sClasses[0] === "signupSwatch") {
if (signupObj.favoriteColor !== "") {
signupObj.prevSelColorElement.style.borderColor = "white";
} // end if
signupObj.favoriteColor = sClasses[1];
el.style.borderColor = "#003399";
signupObj.prevSelColorElement = el;
doValidation();
} // end if
} // end of function checkClicks()
function checkUserTextInputs(evt) {
var el = evt.target;
if (el.id === "signupFname") {
signupObj.firstName = el.value;
doValidation();
} // end if
if (el.id === "signupLname") {
signupObj.lastName = el.value;
doValidation();
} // end if
if (el.id === "signupEmail") {
signupObj.emailAdr = el.value;
doValidation();
} // end if
if (el.id === "signupPassword") {
signupObj.password = el.value;
doValidation();
} // end if
if (el.id === "signupPasswordReenter") {
signupObj.passwordReentered = el.value;
doValidation();
} // end if
} // end of function checkUserTextInputs()
function checkChanges(evt) {
var el = evt.target;
if (el.name==="favTurtle") {
signupObj.favoriteNinjaTurtle = el.value;
} // end if
if (el.id==="signupImAmazing") {
signupObj.imAmazing = el.checked;
var signupYesYouAre = $("#signupYesYouAre")[0];
if (signupObj.imAmazing) {
signupYesYouAre.style.display = "block";
} else {
signupYesYouAre.style.display = "none";
}
} // end if
// below happens when user picks option that
// the browser provides
if (el.id==="signupEmail") {
// signupObj.emailAdr = el.value;
} // end if
doValidation();
} // end of function
function doSignup() {
var dta = {};
var sMsg;
var msg = $("#msg")[0];
sMsg = doValidation(true);
if (sMsg.length>0) {
msg.style.display = "block";
return;
} // end if
// if we get this far, everything is validated and we can move on
dta.firstName = signupObj.firstName;
dta.lastName = signupObj.lastName;
dta.emailAdr = signupObj.emailAdr;
dta.password = signupObj.password;
dta.favoriteColor = signupObj.favoriteColor;
dta.favoriteNinjaTurtle = signupObj.favoriteNinjaTurtle;
dta.imAmazing = signupObj.imAmazing;
showSubmissionMsg();
signupObj.runWhenFilledOut(dta);
} // end of function doSignup()
function isValidEmailAdr(sAdr) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(sAdr);
} // end of function
function doValidation(iFromButton) {
var sMsg = [];
var msg = $("#msg")[0];
var s=[];
var n,nMax;
var xyz = signupObj;
var sErrMsg;
var bFromButton = false;
if (typeof iFromButton !== "undefined") {
bFromButton = iFromButton;
} // end if
if (signupObj.firstName.length < 1) {
sMsg[sMsg.length] = "First Name is a required field";
}
if (signupObj.lastName.length < 2) {
sMsg[sMsg.length] = "The Last Name field needs to be at least 2 characters long";
}
if (bFromButton) {
var xyz = signupObj;
}
if (signupObj.emailAdr.length < 1) {
sMsg[sMsg.length] = "Email Address is a required field";
} else {
if (!isValidEmailAdr(signupObj.emailAdr)) {
sMsg[sMsg.length] = "Invalid Email Address";
} // end if
} // end if/else
if (signupObj.password.length < 6) {
sMsg[sMsg.length] = "You must provide a password with 6 characters or more";
} else {
if (signupObj.passwordReentered !== signupObj.password) {
sMsg[sMsg.length] = "Password and Reentered Password do not match";
} // end if
} // end if/else (signupObj.password.length < 7)
if (signupObj.favoriteColor === "") {
sMsg[sMsg.length] = "You must select your favorite color";
} // end if
if (signupObj.favoriteNinjaTurtle === "") {
sMsg[sMsg.length] = "You must select your favorite Ninja Turtle";
} // end if
if (sMsg.length>0) {
// Did not pass validation
nMax = sMsg.length;
s[s.length] = "<ul class='signUpUl'>";
for (n=0;n<nMax;n++) {
s[s.length] = "<li>";
s[s.length] = sMsg[n];
s[s.length] = "</li>";
} // next n
s[s.length] = "</ul>";
sErrMsg = s.join("");
if (signupObj.lastErrMsg !==sErrMsg) {
signupObj.lastErrMsg = sErrMsg;
msg.innerHTML = sErrMsg;
} // end if
} else {
signupObj.lastErrMsg = "";
msg.innerHTML = "";
msg.style.display = "none"; // no problems
} // end if
return sMsg;
} // end of function doValidation()
function showSubmissionMsg() {
var s=[];
var signupInnerPanel = $("#signupInnerPanel")[0];
s[s.length] = "<div class='signupSubmissionHdr'>";
s[s.length] = "<center>";
s[s.length] = sTitle;
s[s.length] = " Site Sign Up";
s[s.length] = "</center>";
s[s.length] = "</div>"; // signupSubmissionHdr
s[s.length] = "<div class='signupThankyou'>";
s[s.length] = "<center>";
s[s.length] = "Thank You For Signing Up!";
s[s.length] = "</center>";
s[s.length] = "</div>"; // signupThankyou
signupInnerPanel.innerHTML = s.join("");
} // end of function
return signupObj;
} // end of function SignUpObj()
Also see: Tab Triggers