Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <form action="#" method="get">
	<fieldset>
		<label for="inputLimit_test">Describe our INPUT here</label><br>
		<div class="inputLimit">
			<input
				data-input-limit="5"
				id="inputLimit_test"
				name="test"
				pattern="^(\s*\b\S+\b\s*){0,5}$"
				type="text"
			>
		<!-- .inputLimit --></div>
		<p>
			<em>Enter up to five words above. Space or Enter will separate words automatically.</em>
		</p>
		<button>submit</button>
	</fieldset>
</form>

              
            
!

CSS

              
                form, fieldset, div, ul, li, input, button {
	padding:0;
	margin:0;
	font:normal 1em/1.5 arial,helvetica,sans-serif;
}

fieldset {
	border:none;
	max-width:48em;
	margin:0 auto;
}

fieldset > button {
	padding:0.25em 0.5em;
}

fieldset > label {
	display:inline-block;
	padding:0 0 0.25em 0.5em;
}

.inputLimit {
	display:flex;
	flex-wrap:wrap;
	padding:0 0 0.25em 0.25em;
	border-radius:0.825em;
}

.inputLimit,
.inputLimit li {
	border:0.125em solid #888;
}

.inputLimit:focus-within {
	box-shadow:
		0 0 0.125em 0.125em #08F8;
}

.inputLimit ul {
	flex:0 1 auto;
	list-style:none;
}

.inputLimit input {
	flex:1 0 auto;
}

.inputLimit li {
	display:inline-block;
	padding:0.25em 0.25em 0.25em 0.5em;
	margin:0.25em 0.25em 0 0;
	background:#EEE;
	border-radius:0.5em;
}

.inputLimit input {
	padding:0.375em 0.25em;
	margin-top:0.25em;
	background:transparent;
	border:none;
	outline:none;
}

.inputLimit input:disabled {
	display:none;
}

.inputLimit button {
	width:1.5em;
	height:1.5em;
	margin-left:0.5em;
	text-align:center;
	background:#E66;
	color:#FFF;
	border:none;
	border-radius:0.75em;
}

.inputLimit button:focus,
.inputLimit button:hover {
	background:#F00;
}
              
            
!

JS

              
                (function(d) {

	// start with a couple helper functions

	function make(tagName, attr, forceParent) {
		var e = d.createElement(tagName);
		if (forceParent) forceParent.appendChild(e);
		for (var key in attr) {
			var value = attr[key];
			switch (key) {
				case 'after':
					value.parentNode.insertBefore(e, value.nextSibling);
					continue;
				case 'before':
					value.parentNode.insertBefore(e, value);
					continue;
				case 'first':
					value.insertBefore(e, value.firstChild);
					continue;
				case 'last':
					attr[key].appendChild(e);
					continue;
				case 'content':
					if (value instanceof Array) {
						for (var row of value) {
							if (row instanceof Array) make(row[0], row[1], e);
							else nodeAppend(e, row);
						}
					} else nodeAppend(e, row);
					continue;
				default:
					e[key] = attr[key];
			}
		}
		return e;
	} // make
	
	function nodeAppend(e, value) {
		e.appendChild(value instanceof Node ? value : d.createTextNode(value));
	} // nodeAppend
	
	// now our various event handlers

	var
		inputCallbacks = {
			blur : function(event) {
				if (event.currentTarget.value.trim()) wordAdd(event.currentTarget);
			},
			input : function(event) {
				if (event.data === " ") wordAdd(event.currentTarget);
			},
			keydown : function(event) {
				if (event.key === "Enter") {
					wordAdd(event.currentTarget);
					event.preventDefault();
				}
			}
			
		},
		targets = d.querySelectorAll("input[data-input-limit]");
		
	// apply the event handlers and 
		
	for (var input of targets) {
		for (var event in inputCallbacks) {
			input.addEventListener(event, inputCallbacks[event], false);
		}
		make('ul', { before : input } );
	}
	
	function wordAdd(input) {
		var
			count = (
				input.dataset.inputLimit -
				input.previousElementSibling.childElementCount
			);
		input.value = input.value.trim(); 
		if (!count || !input.value) return;
		make('li', {
			last : input.previousElementSibling,
			content : [
				[ 
					'input', {
						name : input.name + "Words[]",
						type : 'hidden',
						value : input.value
					}
				],
				input.value,
				[
					'button', {
						onclick : wordRemove,
						textContent : "\uD83D\uDDD9",
						title : "Remove",
						type : 'button'
					}
				]
			]
		});
		input.value = "";
		if (count === 1) input.disabled = true;
	} // multiInputEvent
	
	function wordRemove(event) {
		var
			li = event.currentTarget.parentNode,
			ul = li.parentNode,
			input = ul.nextElementSibling;
		ul.removeChild(li);
		input.disabled = false;
		input.focus();
	} // wordRemove
	
})(document); 
              
            
!
999px

Console