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 data-theme="dark"

	// Below would be shifted to an external asset (icons.svg) to be cacheable (see notes below)
	// Refer https://codepen.io/scootman/project/editor/28a25d9b324f8b1ce54b2917b241ca14 for production ready cacheable demo
	svg.defs xmlns="http://www.w3.org/2000/svg"
		defs
			symbol id="package" viewBox="0 0 36 36"
				g data-note="darker elements"
					path d="M33.94,10.08A3.11,3.11,0,0,0,33.56,9L18,18l-7-4h0L27,4.72,25,3.57,9,12.8H9L2.44,9a3.11,3.11,0,0,0-.38,1.07,1.26,1.26,0,0,0,0,.27,2.64,2.64,0,0,0,0,.29V25.38a3.28,3.28,0,0,0,1.63,2.8l12.75,7.36a3.27,3.27,0,0,0,3.24,0l12.76-7.36.35-.24A3.27,3.27,0,0,0,34,25.38V10.64a2.64,2.64,0,0,0,0-.29A1.26,1.26,0,0,0,33.94,10.08Z"
				g data-note="lighter elements" style="fill: currentcolor"
					path d="M9,12.8,25,3.56,19.62.46a3,3,0,0,0-.78-.33A3,3,0,0,0,18.11,0a1.92,1.92,0,0,0-.24,0,3.37,3.37,0,0,0-.71.09,3.16,3.16,0,0,0-.79.33L3.62,7.82,3.38,8l-.21.17A3.18,3.18,0,0,0,2.44,9Z"
					path d="M33.56,9a3.18,3.18,0,0,0-.73-.86L32.62,8l-.25-.16L32,7.58,27,4.72,11,14h0l7,4Z"
					path d="M11,14v5.22a.5.5,0,0,1-.75.43l-.75-.43a1,1,0,0,1-.5-.87V12.8H9L2.44,9a3.11,3.11,0,0,0-.38,1.07,1.26,1.26,0,0,0,0,.27,2.64,2.64,0,0,0,0,.29V25.36a2.64,2.64,0,0,0,0,.29,1.26,1.26,0,0,0,0,.27,3.23,3.23,0,0,0,1.11,1.93l.21.16a2.2,2.2,0,0,0,.25.17l.81.47,11.94,6.89A3.27,3.27,0,0,0,18,36V18Z" style="opacity: 0.5"

			symbol id="delivery" viewBox="0 0 36 36"
				g data-note="darker elements"
					path d="M35.72,5.41l-.14-.11-24.93,16,2,8.83a.92.92,0,0,0,.65.69.94.94,0,0,0,.93-.24l5.14-5.22-4-1.87Z"
				g data-note="lighter elements" style="fill: currentcolor"
					path d="M34.81,5.17.68,14.85A.94.94,0,0,0,.54,16.6l10.11,4.71,24.93-16A.9.9,0,0,0,34.81,5.17Z" 
					path d="M35.72,5.41,15.34,23.5l4,1.87,6.52,3a1.87,1.87,0,0,0,2.56-1.06l7.51-21A.92.92,0,0,0,35.72,5.41Z"
					path d="M35.72,5.41l-.14-.11-24.93,16,2,8.83a.92.92,0,0,0,.65.69l2.06-7.33Z" style="opacity: 0.5"


	.layout
	
		.icons
			button#icon-1
				svg.icon viewBox="0 0 36 36"
					use href="#package"
					/ use href="https://assets.codepen.io/436544/icons.svg#package"
					/ ^ this will work in a production environment, but in Codepen you get a error due to assets being served by a different domain (see CodePen project link above)
			button#icon-2.alt
				svg.icon viewBox="0 0 36 36"
					use href="#delivery"
					/ use href="https://assets.codepen.io/436544/icons.svg#delivery"
					
		.segmented-control
			input#light-theme type="radio" name="theme" value="light"
			label for="light-theme" Light
			input#dark-theme {type="radio" name="theme" value="dark" checked}
			label for="dark-theme" Dark
			
		.links
			a href="https://codepen.io/scootman/project/editor/ArpPQr" target="_top" title='Codepen project' Production ready demo
			a href="https://codepen.io/scootman/pen/jOwWpZX" target="_top" title='Codepen demo with stroke also addressable' + Stroke demo
			
			
			
			
			

			a href="https://twitter.com/_AntiAlias_/status/1416989388429352961?s=20" target="_top" title='Twitter thread' Notes · part 1
			a href="https://twitter.com/_AntiAlias_/status/1422794300903944192?s=20" target="_top" title='Twitter thread' part 2

              
            
!

CSS

              
                // This is an extension of the two colour 'SVG use' approach that has been documented for some time (e.g. https://css-tricks.com/lodge/svg/21-get-two-colors-use/)
// This example includes changing the opacity on some lighter elements to create a third colour

// A full explanation about this approach can be found here: https://twitter.com/_AntiAlias_/status/1416989388429352961?s=20


// Defs ---------

// neutral colors
$light-theme-fgd: hsl(240,8%,6%);
$light-theme-fgd-weaker: hsl(240,8%,50%); // weaker contrast
$light-theme-bgd: hsl(240,8%,94%);
$light-theme-bgd-stronger: white; // stronger contrast

$dark-theme-fgd: white;
$dark-theme-fgd-weaker: hsl(240,8%,56%);
$dark-theme-bgd: hsl(240,8%,12%);
$dark-theme-bgd-stronger: hsl(240,8%,6%);

// neutral colors (as applied to svg icons; note reversal of contrast to make 3D icons 'lit' naturally for both themes)
$light-theme-icon-light: $light-theme-fgd-weaker;
$light-theme-icon-dark: $light-theme-fgd;
$dark-theme-icon-light: $dark-theme-fgd;
$dark-theme-icon-dark: $dark-theme-fgd-weaker;

// turquoise (same colors are used for both themes)
$icon-color-a-light: hsl(175,95%,40%);
$icon-color-a-dark: hsl(195,100%,30%);

// amber (same colors are used for both themes)
$icon-color-b-light: hsl(40,100%,50%);
$icon-color-b-dark: hsl(14,78%,54%);


// typeface (an awesome one by Jeremy Tribby)
@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400&display=swap');

// standard transition
$transition: all .1s ease-in-out;

// changing the color state of an SVG may cause it to jiggle in Safari
%svg-safari-jiggle-fix {
	-webkit-backface-visibility: hidden;
	-webkit-transform: translateZ(0) scale(1);
	font-smoothing: antialiased !important;
}



// Rules ---------

body {
	margin: 0;
	display: flex;
	justify-content: center;
	min-height: 100vh;
	min-width: 375px;
	color: $light-theme-fgd;
	background: $light-theme-bgd;
	font-family: 'Barlow', sans-serif;
	font-size: 14px;
	transition: $transition;
	&[data-theme='dark'] {
		color: $dark-theme-fgd;
		background: $dark-theme-bgd;
	}
}

.layout {
	display: grid;
	grid-template-rows: 20fr auto 21fr; // +1fr to shift icons up to optical center
	grid-template-columns: 1fr 2fr 1fr;
	grid-template-areas: 
		"header header header"
    ". icons ."
    "footer footer footer";
	justify-items: center;
	min-height: 192px;
	flex: 1 0 0;
	max-width: 1200px;
}

.icons {
	display: flex;
	grid-area: icons;
	button {
		all: unset;
		position: relative;
  	cursor: pointer;
		@media (hover: hover) {
			&::before {
				// hover background 
				// Making this a (psuedo) child of label helps with transitions sync, however pseudo elements revealed on hover
				// sometimes require an additional touch on mobile devices, so disabed in this case
				content: '';
				position: absolute;
				top: 0;
				bottom: 0;
				left: 0;
				right: 0;
				opacity: 0;
				background: $light-theme-bgd-stronger;
				z-index: -1;
				border-radius: 10%;
				transition: $transition;
				[data-theme='dark'] & {
					background: $dark-theme-bgd-stronger;
				}
			}
		}
		&:hover {
			svg, &::before {
				opacity: 1;
			}
			svg {
				color: $icon-color-a-light;
				fill: $icon-color-a-dark;
			}
		}
		&.alt:hover {
			svg {
				color: $icon-color-b-light;
				fill: $icon-color-b-dark;
			}
		}
	}
}

svg {
	color: $light-theme-icon-light;
	fill: $light-theme-icon-dark;
	@extend %svg-safari-jiggle-fix;
	[data-theme='dark'] & {
		color: $dark-theme-icon-light;
		fill: $dark-theme-icon-dark;
	}
	&.defs {
    position: absolute;
    height: 0;
    width: 0;
  }
	&.icon {
		width: 60%;
		margin: 20%;
		opacity: .75;
		transition: $transition;
	}
}

.segmented-control {
	grid-area: header;
	align-self: start;
	display: flex;
	width: 144px;
	margin: 27px 0;
	height: 27px;
	border-radius: 5px;
	background: $light-theme-bgd-stronger;
	z-index: 1;
	transition: $transition;
	[data-theme='dark'] & {
		background: $dark-theme-bgd-stronger;
		label {
			color: $dark-theme-fgd-weaker;
			&:last-child::before {
				background-color: $dark-theme-bgd;
			}
		}
	}
	input {
		position: absolute;
		transform: scale(0); // not 'hidden' for better accessibilty
		&:checked + label {
			color: inherit;
			~ label:last-child::before {
				// if first radio checked shift background of last radio left
				// this approach can be extended to 3 or 4 segments, but gets messy beyond 4
				// 3 value control example can be found here: https://codepen.io/scootman/pen/qBEPoLO
				transform: translate(-100%); 
			}
		}
	}
	label {
		flex: 1 0 0px;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
		padding-bottom: 1px;
		color: $light-theme-fgd-weaker;
		transition: $transition;
		cursor: pointer;
		&:hover {
			color: inherit;
		}
		&:last-child::before {
			// checked background
			// placed on light item so it can 'detect' if radios are check before it in the DOM &
			// and allows for sliding transition effect
			content: '';
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			background-clip: padding-box;
			background-color: $light-theme-bgd;
			border-radius: 5px;
			border: 2px solid transparent;
			z-index: -1;
			transition: transform .25s ease-in-out, background-color .1s ease-in-out ;
		}
	}
}


.links {
	grid-area: footer;
	align-self: end;
	display: flex;
	opacity: .55;
	a {
		all: unset;
		cursor: pointer;
		margin: 27px 0;
		padding: 0 .5em;
		color: $light-theme-fgd-weaker;
		transition: $transition;
		[data-theme='dark'] & {
			color: $dark-theme-fgd-weaker;
		}
		&:hover {
			color: inherit;
		}
	}
}


              
            
!

JS

              
                $('input[name="theme"]').on('change', function() {
    if ($(this).prop("checked", true)) {
      $('body').attr('data-theme', $(this).prop('value'));
    }
  });
              
            
!
999px

Console