Pen Settings

HTML

CSS

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

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

              
                <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