cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

              <!DOCTYPE html>
<html lang="en">
      <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">
     <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>
      <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><br />
            <input id="fname" type="text" name="textfield"/>
            <span class="errorMsg" id="fnameError"></span>
         <div><label for="sample">Sample field with tooltip<span class="reqField">*</span>:&nbsp;<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>
               <legend tabindex="0" 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">Pepperoni</label><br>
               <input id="mushrooms" type="checkbox" name="toppings" value="mushrooms">
               <label for="mushrooms">Mushrooms</label><br>
               <input id="olives" type="checkbox" name="toppings" value="olives">
               <label for="olives">Olives</label>
            <legend tabindex="0" 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</label><br>
            <input id="twoday" type="radio" name="shipping" value="twoday">
            <label for="twoday">Two day</label><br>
            <input id="ground" type="radio" name="shipping" value="ground">
            <label for="ground">Ground</label>
         <label id="favcityLabel" for="favcity" tabindex="0">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>
         <div><input type="submit" name="submit" value="Submit"/>
            <input type="reset" name="reset" value="Reset"/>
                            /* Accessible form styles begin */
label, fieldset {
	font-weight: bold;
fieldset label, input {
	font-weight: normal;
fieldset {
	margin-bottom: 20px;
  padding: 5px;
select {
	margin-bottom: 30px;
.errorMsg, .reqField {
.errorMsg {
	font-weight: normal;
input {
  padding: 4px;
/* 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/ */

*: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;

	//validate select menu
	var z = document.forms["myForm"]["favcity"].value;
	if (z == 0) {
		applyError("favcity","&nbsp;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","&nbsp;You must enter some text here.");
	var y = document.forms["myForm"]["fname"].value;
	if (y == "") {
		document.getElementById("fnameErrorHidden").innerHTML = "You must enter your first name.";
		applyError("fname","&nbsp;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) {
	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("sampleError").innerHTML = "";
	document.getElementById("toppingsLegendError").innerHTML = "";
	document.getElementById("shippingLegendError").innerHTML = "";
	document.getElementById("favcityError").innerHTML = "";
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................