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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Accessible Form Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="content-wrapper">
<h1>Accessible form validation example:</h1>
<p>The following is an example of a keyboard accessible form. Notice the following accessibility features: visible focus indicator, accessible tooltips, labels for every field, and accessible error messaging. </p>
<p>Notice how the "First Name" field has a hidden message within the field's label for the screen reader, then a visible message for the sighted user in a slightly different spot. This is what you need to do if the design shows the error message in a place that precludes you from placing it within the field's label. </p>
<p>Try it out yourself by tabbing through this page with your keyboard and screen reader. Purposely leave fields blank and see what happens. Let me know if you notice any issues.</p>
<hr>
</hr>
<h2>Sample Form</h2>
<form action="#" name="myForm" onsubmit="return validateForm()" method="get">
<p>Required fields are indicated with a "<span class="reqField">*</span>".</p>
<p><label for="fname">First Name:<span class="reqField">*</span><span class="element-invisible" id="fnameErrorHidden"></span></label>(<a href="https://www.publicissapient.com">link to ps.com</a>)<br />
<input id="fname" type="text" name="textfield" />
<span class="errorMsg" id="fnameError"></span>
<p><label for="lname">Last Name:<span class="reqField">*</span><span class="element-invisible" id="lnameErrorHidden"></span></label><br />
<input id="lname" type="text" name="textfield"/>
<span class="errorMsg" id="lnameError"></span>
</p>
<div><label for="sample">Sample field with tooltip:<span class="reqField">*</span><span class="errorMsg" id="sampleError"></span></label><br />
<input id="sample" type="text" name="textfield2" aria-describedby="sample-tip"/>
<div role="tooltip" id="sample-tip">Hint: Type anything here.</div>
</div>
<p>
<fieldset>
<legend id="toppingsLegend">Select your pizza toppings:<span class="reqField">*</span><span class="errorMsg" id="toppingsLegendError"></span></legend>
<input id="ham" type="checkbox" name="toppings" value="ham"/>
<label for="ham">Ham</label><br>
<input id="pepperoni" type="checkbox" name="toppings" value="pepperoni">
<label for="pepperoni"><span aria-label="Pepperoni, add $5.00 to price">Pepperoni,</span> <span aria-hidden="true">+ $5.00</span></label><br>
<input id="mushrooms" type="checkbox" name="toppings" value="mushrooms">
<label for="mushrooms">Mushrooms <a href="https://en.wikipedia.org/wiki/Mushroom">What is a mushroom?</a></label><br>
<input id="olives" type="checkbox" name="toppings" value="olives">
<label for="olives">olives</label>
</fieldset>
</p>
<fieldset>
<legend id="shippingLegend">Choose a shipping method:<span class="reqField">*</span><span class="errorMsg" id="shippingLegendError"></span></legend>
<input id="overnight" type="radio" name="shipping" value="overnight" checked/>
<label for="overnight">Overnight <a href="https://www.google.com">What does this mean?</a></label><br>
<input id="twoday" type="radio" name="shipping" value="twoday">
<label class="with-badge" for="twoday">Two day</label><br>
<input id="ground" type="radio" name="shipping" value="ground">
<label for="ground">Ground</label>
</fieldset>
<label id="favcityLabel" for="favcity" >Choose your favorite city?<span class="reqField">*</span><span class="errorMsg" id="favcityError"></span></label><br />
<select id="favcity" name="select" aria-labelledby="favcityLabel">
<option value="0">Select</option>
<option value="1">Amsterdam</option>
<option value="2">Buenos Aires</option>
<option value="3">Delhi</option>
<option value="4">Hong Kong</option>
<option value="5">London</option>
<option value="6">Los Angeles</option>
<option value="7">Moscow</option>
<option value="8">Mumbai</option>
<option value="9">New York</option>
<option value="10">Sao Paulo</option>
<option value="11">Tokyo</option>
</select>
<div><input type="submit" name="submit" value="Submit"/>
<input type="reset" name="reset" value="Reset"/>
</div>
</form></div>
</body>
</html>
/* Accessible form styles begin */
label, fieldset {
font-weight: bold;
}
fieldset label, input {
font-weight: normal;
}
fieldset {
margin-bottom: 20px;
padding: 5px;
}
label.with-badge {
padding-left: 30px;
background: no-repeat url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASkAAACqCAMAA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VkFgxiRKwSaRejVIlQOmOuaAQqiCltX/+++9flI8WTMFQwmEP4brQV+mlv7tfmM3o5dbfBWbsYC1+6QzZ7Eu00MlgP0AzsPziEhqMUKqzCEy8aySs4LRkt4wOfSbrUKh0LIL85dVwGM5PNmTS5Hx6kIvSnbmkZRQF90LLRzJowt7y4sSjNd/1/PPBVEPeCg7NpczFAYk/sJB0gtB0wNlodnF+NFkZc73J0WI8n/V7pqkjXTk0g+8l8XK8uTHEhrP4DfvxXyYYrnAc09zT8Zfw7x30JVvgLInr9i3u2/Yxj9DpzeWvDJhM5j1YQhbUTa2/qd+XnqPzvuGYOutvFEB9z7GDuaRf9382+xdR3x37Wv1RggQ9cmSF04GyhBPVA/vj+I8SnE2DIJhO+8vRYH7k+997yikUCoVCoVAoFAqFQqFQKBQKhUKhUCgUCoVCoVAoEP4HrkDWmNP/KXMAAAAASUVORK5CYII=");
background-size: 30px;
}
select {
margin-bottom: 30px;
font-size:14px;
}
.errorMsg, .reqField {
color:#bb4e00;
}
.errorMsg {
font-weight: normal;
}
input {
font-size:16px;
padding: 4px;
color:#333;
}
/* Accessible form styles end */
/* hides content from sighted users, can be accessed by screen reader */
.element-invisible {
position: absolute !important;
height: 1px; width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
/* set up hidden tooltip */
[role="tooltip"] {
display: none;
padding: 0.25em;
margin: 0;
color: #666;
width: 100%;
z-index: 2;
font-weight: normal;
font-style: italic;
}
/* reveal associated tooltip on focus of preceeding input */
input:focus + [role="tooltip"] {
display: block;
}
/* Reference: http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/ */
/* GLOBALS */
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
font-family: sans-serif;
/* margin: 0; */
}
::selection {
background: white;
}
::-moz-selection {
background: red;
}
#content-wrapper {
width: 60%;
margin: 0 auto;
min-width: 320px;
max-width: 800px;
}
//Form validation
var formValid;
function validateForm() {
//set initial value of formValid to true
formValid = 1;
resetErrors();
//validate select menu
var z = document.forms["myForm"]["favcity"].value;
if (z == 0) {
applyError("favcity"," You must choose a favorite city.");
}
//validate radio buttons
if(validateGroup("shipping")==false) {
document.getElementById("shippingLegendError").style.padding = "0 5px";
applyError("shippingLegend","Please pick a shipping method.");
}
//validate checkboxes
if(validateGroup('toppings')==false) {
document.getElementById("toppingsLegendError").style.padding = "0 5px";
applyError("toppingsLegend","You must pick at least one topping.");
}
//validate input fields
var x = document.forms["myForm"]["sample"].value;
if (x == "") {
applyError("sample"," You must enter some text here.");
}
var z = document.forms["myForm"]["lname"].value;
if (z == "") {
document.getElementById("lnameErrorHidden").innerHTML = "You must enter your last name.";
applyError("lname"," You must enter your last name.");
}
var y = document.forms["myForm"]["fname"].value;
if (y == "") {
document.getElementById("fnameErrorHidden").innerHTML = "You must enter your first name.";
applyError("fname"," You must enter your first name.");
}
//if a form field is not valid, do not submit form
if (formValid == 0){
return false;
}
}
//Validates Instruments custom select menu
//Appends error message to label, puts focus on field with error message
function applyError(errorFieldId,errorMessage){
var errorMessageId = errorFieldId + "Error";
document.getElementById(errorMessageId).innerHTML = errorMessage; //puts error in span tag
document.getElementById(errorFieldId).focus(); //puts focus on field with error
formValid = 0; //sets global formValid variable to false
}
//validates grouped form fields like checkboxes or radio buttons. Accepts the name of the group to be validated.
function validateGroup(groupName){
var group = document.getElementsByName(groupName);
var groupCount = 0;
for (var i = 0; i < group.length; i++) {
if (group[i].checked) {
groupCount++;
}
}
if (groupCount < 1) {
return false;
}
return true;
}
//resets error messages so they are turned off
function resetErrors(){
document.getElementById("fnameError").innerHTML = "";
document.getElementById("fnameErrorHidden").innerHTML = "";
document.getElementById("lnameError").innerHTML = "";
document.getElementById("lnameErrorHidden").innerHTML = "";
document.getElementById("sampleError").innerHTML = "";
document.getElementById("toppingsLegendError").innerHTML = "";
document.getElementById("shippingLegendError").innerHTML = "";
document.getElementById("favcityError").innerHTML = "";
}
Also see: Tab Triggers