Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource


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


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.


Auto Save

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.


                <label for="credit-card-number">credit card number:</label>
<input id="credit-card-number" inputmode="numeric"/>


                body {
	font: 1.2em Calibri, sans-serif;

input {
	display: block;
	font: inherit;


                const ccInputElement = document.querySelector('#credit-card-number');

ccInputElement.format = () => {
	// split at cursor position
	let cursorPosition = ccInputElement.selectionStart;
	let partBeforeCursorPosition = ccInputElement.value.substring(0, cursorPosition);
	let partAfterCursorPosition = ccInputElement.value.substring(cursorPosition);
	// remove whitespace, set cursor position accordingly
	const originalLength = partBeforeCursorPosition.length;
	partBeforeCursorPosition = partBeforeCursorPosition.replace(/\s/gi, '');
	cursorPosition -= originalLength - partBeforeCursorPosition.length;
	partAfterCursorPosition = partAfterCursorPosition.replace(/\s/gi, '');
	const ccNumber = partBeforeCursorPosition + partAfterCursorPosition;
	// break into groups of 4 digits
	const parts = ccNumber.match(/.{1,4}/g);
	// add spaces, set cursor position accordingly
	ccInputElement.value = parts?.join(' ') || '';
	cursorPosition += Math.floor(cursorPosition * 1/4);
	ccInputElement.setSelectionRange(cursorPosition, cursorPosition);

ccInputElement.addEventListener('input', ccInputElement.format);

ccInputElement.addEventListener('keydown', event => {
	const cursorPosition = ccInputElement.selectionStart;

	// when the cursor is positioned after a space, deleting applies to the space and the digit before the space
	if (event.key == 'Backspace') {	
		// if space before cursor and no selection, remove two characters and set cursor position accordingly
		if (cursorPosition == ccInputElement.selectionEnd
				&& ccInputElement.value[cursorPosition - 1] == ' ') {
			const newCursorPosition = cursorPosition - 2;
			ccInputElement.value = ccInputElement.value.substring(0, newCursorPosition) + ccInputElement.value.substring(cursorPosition);
			ccInputElement.setSelectionRange(newCursorPosition, newCursorPosition);
	else if (event.key == 'ArrowRight') {
		if (ccInputElement.value[cursorPosition + 1] == ' ') {
			const newCursorPosition = cursorPosition + 1;
			ccInputElement.setSelectionRange(newCursorPosition, newCursorPosition);
	else if (event.key == 'ArrowLeft') {
		if (ccInputElement.value[cursorPosition - 1] == ' ') {
			const newCursorPosition = cursorPosition - 1;
			ccInputElement.setSelectionRange(newCursorPosition, newCursorPosition);