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.


                <ground-control control-for=".major-tom" set-prop="--scale">
	<label for="font-scale">Font scale</label>
	<input id="font-scale" type="range" min="0" max="3" step="0.1" value="1" />

<ground-control control-for=".major-tom" set-attr="color-mode">
	<label for="color-mode">Color Mode</label>
	<select id="color-mode">
		<option value="light">light</option>
		<option value="dark">dark</option>
		<option value="rainbow">rainbow</option>
	<button reset-for="color-mode">reset</button>

<ground-control control-for="div" set-prop="border">
	<label for="border">Border</label>
	<input id="border" type="text" value="medium solid teal">

<button reset-all>Reset all</button>

<div class="major-tom">
			Scale: <output for="font-scale" with-units="vw">N/A</output>
			Mode: <output for="color-mode">N/A</output>
		This web component is based on
		Eric Meyer's
		<a href=""><code>super-slider</code> component</a>
		and excellent article
		<a href="">
			<em>Blinded By the Light DOM</em></a>.
		My goal was to make it a bit more generic,
		for any <code>input</code> to control
		the properties or attributes
		on any number of target elements.
		It also finds any related <code>ouptut</code> elements,
		and keeps them up to date with changes.
		This experiment keeps escalating,
		as Eric and I continue to fork our forks of forks,
		<a href="">borrowing and sharing ideas</a>,
		and learning as we go.
		<em>I am not a web component expert</em>,
		and may be doing it all wrong.



	The styles are just to visualize results,
	they are not part of the component.

* { box-sizing: border-box; }
html { font-family: sans-serif; }

ground-control {
	display: block;
	margin-block: 1em;

label {
	display: block;
	font-weight: bold;

.major-tom {
	font-size: calc(1em + (1vw * var(--scale)));
	margin-block: 1em;

output {
	font-family: monospace;
	background: linear-gradient(
		transparent 0 50%, 
		var(--output-highlight, papayawhip) 50% 100%
	padding-inline: 0.5em;

[color-mode] {
	background: var(--bg, white);
	border: thin solid;
	color: var(--text, black);
	padding: 1em;
	& a:any-link {
		color: var(--link, blue);

[color-mode='dark'] {
	--bg: black;
	--text: white;
	--link: cyan;
	--output-highlight: mediumvioletred;

[color-mode='rainbow'] {
	linear-gradient(hsl(0deg 0% 100% / 0.9), hsl(0deg 0% 100% / 0.9)),
	linear-gradient(to bottom right,
		maroon 0 12%,
		orange 12% 24%,
		yellow 24% 36%,
		teal 36% 48%,
		midnightblue 48% 60%,
		indigo 60% 72%,
		darkmagenta 72% 84%,
		mediumvioletred 84%
	--output-highlight: cyan;
	--link: mediumvioletred;
	text-shadow: 0 1px 0 white;
	background-size: calc(100% - 1em) calc(100% - 1em), 100% 100%;
	background-repeat: no-repeat;
	background-position: center;


                class groundControl extends HTMLElement {
  static observedAttributes = [

  static attrToPropMap = {
    'control-for': 'targetSelect',
    'set-attr': 'setAttr',
    'set-prop': 'setProp',

  static controls = [


	targetSelect = ':root';

  constructor() {

    // Add direct event listeners when component is created
    this.addEventListener('reset', (e) => this.resetControl());

  // attribute changes
  attributeChangedCallback(name, oldValue, newValue) {
    this[groundControl.attrToPropMap[name]] = newValue;
    if (this.inputEl) { this.setUp(); }

  // first connection
  connectedCallback() {
    this.inputEl = this.querySelector(groundControl.controls.join(', '));

    if (this.inputEl) {

      this.inputEl.addEventListener('input', (e) => this.broadCast());
      this.resetBtn?.addEventListener('click', (e) => this.resetControl());
    } else {
      console.error("Your circuit's dead, there's something wrong (no input/select found)");

  disconnectedCallback() {
    this.inputEl.removeEventListener('input', (e) => this.broadCast());
    this.resetBtn?.removeEventListener('click', (e) => this.resetControl());

  // methods
  setUp = () => {
    this.resetValue = this.inputEl.value;

    const selectors = {
      target: this.targetSelect || ':root',
      output: `output[for=${}]`,
      reset: `button[reset-for=${}]`,

    this.targetEls = document.querySelectorAll(;
    this.displayEls = document.querySelectorAll(selectors.output);
    this.resetBtn = this.querySelector(selectors.reset);

  // change target attrs/props, and update output displayEls
  broadCast = () => {
    this.targetEls.forEach((el) => {
      if (this.setProp) {, this.inputEl.value);
      if (this.setAttr) {
        el.setAttribute(this.setAttr, this.inputEl.value);

    this.displayEls.forEach((el) => {
      const units = el.getAttribute('with-units') || '';
      el.value = `${this.inputEl.value}${units}`;

  // reset the value of the control
  resetControl = (value) => {
    this.inputEl.value = value || this.resetValue;

// register the ground-control element
customElements.define("ground-control", groundControl);

// the reset-all button is not part of the component,
// but triggers the ground-control 'reset' event
	.querySelectorAll('[reset-all]:is(button, [type=button])')
	.forEach((btn) => {
		btn.addEventListener('click', (e) => {
			document.querySelectorAll('ground-control').forEach((control) => {
					new Event("reset", { view: window, bubbles: false })