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. 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

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

              
                		<body>
	<div class="banner">
		<p>This site uses cookies to improve the user experience and to collect data. You can <button type="button" id="configure-button">configure</button> which cookies you want to give your consent to.</p>
		<button type="button" id="accept-button" class="button">Accept all</button>
	</div>
	<div hidden class="modal">
		<div class="modal-content" role="dialog">
			<div class="modal-header">
				<h2>Configure cookies</h2>
				<button id="close-button" type="button">Close</button>
			</div>
			<div class="modal-body">
				<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem atque dolorem, ipsam temporibus veniam, rem, rerum tempora doloribus quasi earum recusandae quas praesentium optio quod sapiente consequatur labore incidunt voluptatem?</p>
			
				<h3>User experience</h3>
				<div class="modal-cookie">
					<input checked type="checkbox" id="appcues" />
					<label for="appcues">Appcues</label>
				</div>

				<div class="modal-cookie">
					<input checked type="checkbox" id="ab-tasty" />
					<label for="ab-tasty">AB Tasty</label>
				</div>

				<h3>Tracking</h3>
				<div class="modal-cookie">
					<input checked type="checkbox" id="google-analytics" />
					<label for="google-analytics">Google Analytics</label>
				</div>
			</div>
			
			<button id="confirm-button" class="modal-confirm button" type="button">Confirm</button>
		</div>
	</div>
	<header>
		<a href="#main">Skip to main content</a>
		<nav>
			<ul>
				<li><a href="#">Home</a></li>
				<li><a href="#">About</a></li>
				<li><a href="#">Contact</a></li>
				<li><a href="#">Blog</a></li>
			</ul>
		</nav>
	</header>
	<main id="main">
		<h1>Accessible cookie banner 🍪</h1>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sed quam ac nulla finibus tincidunt. Sed id erat rhoncus, sodales risus a, ultricies dui. Praesent id diam malesuada, aliquet felis et, volutpat magna. Sed ut risus aliquam, mattis purus vitae, consequat nisl. Duis interdum consequat orci id finibus. Fusce venenatis elit ante, vel posuere purus suscipit nec. <a href="">Duis sit amet risus</a> eu odio feugiat venenatis. Aenean lobortis nisi nec nulla cursus, vitae elementum nulla euismod. Suspendisse potenti. Donec ex diam, placerat eu odio vel, ornare varius nisi. Duis tempus fermentum nunc, eget condimentum dui molestie sed. Aliquam erat volutpat. Fusce leo arcu, consequat vel odio ac, varius porttitor augue. Nam maximus enim semper lorem consequat, ut maximus ante efficitur. Ut aliquam mi vitae quam luctus, vel elementum dui hendrerit. Etiam laoreet enim commodo, laoreet felis at, gravida ex.</p>

<p>Suspendisse potenti. Nam aliquet convallis volutpat. Aliquam elementum leo odio, eu porta est porttitor et. Vivamus <a href="">egestas molestie diam</a>, eu ultrices eros molestie quis. Nullam id eleifend tortor, a tristique augue. Donec pretium felis a suscipit accumsan. Nulla a turpis sit amet elit interdum scelerisque. Vestibulum et risus elementum, facilisis lacus non, dictum felis. Aliquam interdum finibus nisl interdum convallis. Etiam quis porta justo. Maecenas egestas iaculis ipsum quis finibus. Duis quis ullamcorper mauris, non bibendum diam. Nunc aliquet ipsum ac dictum efficitur. Nulla non enim nec metus finibus placerat. Fusce at tempor justo.</p>

<p>Sed lobortis ante eu mauris cursus tristique. Praesent condimentum dui vel nisi consectetur, sed ullamcorper erat elementum. Nulla tincidunt tellus vel mauris ornare, eu hendrerit justo viverra. Suspendisse justo dui, mollis eu lorem eu, suscipit fringilla quam. Nunc fringilla tortor vitae dignissim convallis. Nam cursus libero id vehicula eleifend. Fusce porta erat nec dolor sollicitudin, et interdum lorem imperdiet. Sed vestibulum vitae velit fermentum sagittis. Fusce quis tincidunt risus. Cras efficitur dolor at massa pulvinar faucibus. Maecenas porttitor pulvinar risus quis vestibulum. Proin dapibus efficitur augue nec finibus. Vestibulum id placerat dui. Nam a hendrerit ipsum, non gravida ante. Suspendisse potenti.</p>

<p>Donec at sagittis libero, nec malesuada leo. Mauris dapibus purus in tellus hendrerit accumsan. Nulla suscipit, risus vel faucibus condimentum, sapien libero tincidunt ipsum, ac varius nisl diam id lectus. Donec eget pretium mauris. Duis finibus tortor at massa imperdiet feugiat. Nulla sit amet nisi vel lorem sodales porta non vitae mauris. Aliquam pellentesque lacinia est. Praesent nisl ligula, cursus a turpis in, laoreet consequat lectus. Nam id mi tempus, consequat magna quis, ultrices eros. Pellentesque hendrerit pretium fringilla.</p>
	</main>
</body>
              
            
!

CSS

              
                :root {
	--color-main: #008694;
	--color-black: black;
}

/* Banner */
.banner {
	background: white;
	box-shadow: 0 0 5px 1px rgba(black, 0.3);
	padding: 1rem;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	
	p {
		margin-bottom: 1rem;
		
		& > button {
			background: none;
			border: none;
			font: inherit;
			padding: 0;
			text-decoration: underline;

			&:hover,
			&:focus {
				text-decoration: none;
			}
		}
	}
}
	
/* Modal */
.modal {
	background: rgba(black, 0.3);
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
}

.modal-header {
	align-items: center;
	display: flex;
	justify-content: space-between;
	margin-bottom: 1rem;
	
	h2 {
		color: var(--color-main);
		font-size: 2rem;
		font-weight: 700;
	}
	
	button {
		background: none;
		border: none;
		font: inherit;
	}
}

.modal-body {
	margin-bottom: 3rem;

	h3 {
		color: var(--color-main);
		font-size: 1.2rem;
		font-weight: 600;
		margin: 0.5rem 0;
	}
	
	.modal-cookie {
		& + .modal-cookie {
			margin-top: 0.5rem;
		}
	}
}

.modal-confirm {
	margin-top: auto;
}

.modal-content {
	background: white;
	overflow: auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	position: fixed;
	top: 1rem;
	left: 1rem;
	right: 1rem;
	bottom: 1rem;
}

/* Button */
.button {
	background: white;
	border: 1px solid var(--color-main);
	font: inherit;
	padding: 0.5rem 1rem;
	
	&:hover,
	&:focus {
		background: var(--color-main);
		color: white;
	}
}

/* Main layout */
body {
	font-family: sans-serif;
	line-height: 1.5;
	margin: 0;
	padding: 0;	
}

*:focus {
	outline: 2px dashed var(--color-black);
	outline-offset: 0.25rem;
}

header {
	background: var(--color-main);
	padding: 1rem 2rem;
	
	[href="#main"] {
		background: white;
		color: var(--color-main);
		padding: 0.5rem;
		position: absolute;
		top: -100%;
		left: 1rem;
		
		&:focus {
			text-decoration: none;
			top: 1rem;
		}
	}
	
	ul {
		align-items: center;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
	}
	
	li {
		&:first-child {
			margin-right: auto;
		}
		
		& + li {
			margin-left: 1rem;
		}
		
		a {
			color: white;
			
			&:hover,
			&:focus {
				text-decoration: none;
			}
		}
	}
}

main {
	margin: 0 auto;
	max-width: 45rem;
	padding: 4rem 1rem;
	
	h1 {
		color: var(--color-main);
		font-size: 3rem;
		font-weight: 700;
		line-height: 1.2;
		margin-bottom: 2rem;
	}
	
	p {
		font-size: 1.2rem;
		
		& + p {
			margin-top: 1rem;
		}
	}
	
	a {
		color: var(--color-main);
		
		&:hover,
		&:focus {
			text-decoration: none;
		}
	}
}
              
            
!

JS

              
                const acceptButton = document.querySelector('#accept-button')
const configureButton = document.querySelector('#configure-button')
const closeButton = document.querySelector('#close-button')
const confirmButton = document.querySelector('#confirm-button')
const banner = document.querySelector('.banner')
const modal = document.querySelector('.modal')
const skipLink = document.querySelector('[href="#main"]')

let focusables = []

/* Hide banner if user accepts cookies */
acceptButton.addEventListener('click', () => {
	banner.hidden = true
})

/* Open modal if user wants to configure cookies */
configureButton.addEventListener('click', () => {
	modal.hidden = false
	closeButton.focus()
	document.body.style.overflow = 'hidden'
	focusables = Array.from(modal.querySelectorAll('button, a, input, textarea, select'))
	
	document.addEventListener('keydown', handleModalKeyboard)
})

/* Close modal on close */
closeButton.addEventListener('click', () => {
	modal.hidden = true
	document.body.style.overflow = 'initial'
	document.removeEventListener('keydown', handleModalKeyboard)
	configureButton.focus()
})

/* Close modal on confirm */
confirmButton.addEventListener('click', () => {
	banner.hidden = true
	modal.hidden = true
	document.body.style.overflow = 'initial'
	document.removeEventListener('keydown', handleModalKeyboard)
	skipLink.focus()
})

const handleModalKeyboard = e => {
	if (e.key === 'Escape') {
		modal.hidden = true
		configureButton.focus()
	}
	
	if (e.key === 'Tab') {
		e.preventDefault()

		let index = focusables.findIndex(f => f === modal.querySelector(':focus'))
		console.log(index)
    if (e.shiftKey === true) {
      index--
    } else {
      index++
    }
    if (index >= focusables.length) {
      index = 0
    }
    if (index < 0) {
      index = focusables.length - 1
    }
    focusables[index].focus()
	}
}
              
            
!
999px

Console