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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div data-language-select></div>
<!-- Check the HTML options for the rel="alternative" meta data -->
            
          
!

CSS

            
              body {
	min-height: 99vh;
	display: grid;
	place-items: center;
}

[data-language-select] {
	background: #111;
	color: white;
	border-radius: 1.6em;
	overflow: hidden;
	
}

[data-language-select] button {
	padding: .8em 1.2em;
	appearance: none;
	border: none;
	color: inherit;
	background: inherit;
}

[data-language-select] ul {
	display: none;
	list-style: none;
	padding: 0 0 .8em;
	margin: 0;
}

[data-language-select] [aria-expanded="true"] + ul {
	display: block;
}

[data-language-select] a {
	color: inherit;
	padding: .2em 1.2em;
	display: inline-block;
}
            
          
!

JS

            
              // Grab the details element that will be the language select
const langSelect = document.querySelector("[data-language-select]");

// Grab all the alternate translations as an array
const translations = [...document.querySelectorAll("head [hreflang]")];

// Check if both select and translations exist
if (langSelect && translations.length) {
  // Build a list of anchors from the translations
  const links = translations
    .map(link => {
      return `
      <li>
        <a href="${link.href}" hreflang="${link.hreflang}">${link.hreflang}</a>
      </li>
    `;
    })
    .join("");

  // Insert a summary showing the current language
  // and insert the links into a unordered list
  langSelect.innerHTML = `
    <button type="button" aria-expanded="false">Language: ${document.documentElement.lang}</button>
    <ul>${links}</ul>
  `;
}

// Construct state for toggle
let state = {
	buttonExpanded: 'false'
}

// Grab language button
const button = document.querySelector("[data-language-select] button");

// Listen to language button
button.addEventListener('click', () => {
	
	// Grab the aria-expanded attribute value
	let currentExpandedState = button.getAttribute('aria-expanded');
    
	// Set state if it hasn't been done before
	if(currentExpandedState === null) {
		currentExpandedState = 'true';
	}
  
	// The toggle state depending on the current state
	state.buttonExpanded = currentExpandedState === 'true' ? 'false' : 'true'
  
	// Set the aria-expanded attribute value
	button.setAttribute('aria-expanded', state.buttonExpanded);
});
            
          
!
999px

Console