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

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.

HTML

              
                <div class="grid" style="--items: 12;">
  <div style="--index: 0;" class="item"></div>
  <div style="--index: 1;" class="item item--half"></div>
  <div style="--index: 2;" class="item item--half"></div>
  <div style="--index: 3;" class="item item--third"></div>
  <div style="--index: 4;" class="item item--third"></div>
  <div style="--index: 5;" class="item item--third"></div>
  <div style="--index: 6;" class="item item--fourth"></div>
  <div style="--index: 7;" class="item item--fourth"></div>
  <div style="--index: 8;" class="item item--fourth"></div>
  <div style="--index: 9;" class="item item--fourth"></div>
  <div style="--index: 10;" class="item"></div>
  <div style="--index: 11;" class="item"></div>
</div>
              
            
!

CSS

              
                // Globals we want everyone to have!
// If this were a complete project, these would be things like spacing, theme colors, typography, etc.
:root {
  --color-primary-hue: 200;  
}

.grid {
  // These grid properties will be available to the .item inside it (see below).
	--grid-column-width: 1fr;
	--grid-column-count: 4;
	--grid-gap: 1.25rem;

	@media (min-width: 60em) {
		--grid-column-count: 8;
	}

	@media (min-width: 80em) {
		--grid-gap: 2.5rem;
		--grid-column-count: 12;
	}
  
  display: grid;
  grid-gap: var(--grid-gap);
  grid-template-columns: repeat(
    var(--grid-column-count),
    var(--grid-column-width)
  );
  
  // We can repeat custom property values elsewhere we find them useful.
  // In this case, combining these with calc() might be even more powerful to fit our theme.
  padding-left: var(--grid-gap);
  padding-right: var(--grid-gap);
  margin-left: auto;
  margin-right: auto;
  max-width: 90rem;
}

.item {
  // Calculate saturation based on the position of the element in the set.
  // Since we only manipulate this per item, it makes sense to define it here.
  --saturation: calc(var(--index) * (100 / var(--items)) * 1%);
  
  // You can use the custom property as part of a value like HSL.
  // Notice that we're using a global for the hue (theming anyone?)
  background: hsl(var(--color-primary-hue), var(--saturation), 40%);
  border-color: hsl(var(--color-primary-hue), var(--saturation), 50%);
  
  border-style: solid;
  border-width: 0.125rem;
  border-radius: 0.5rem;
  height: 10rem;
  
  // The grid column is set here and is updated through modifier classes (see below).
  // We're using a fallback which matches our grid automatically all the time.
  grid-column: span var(--span, var(--grid-column-count));
}

.item--half {
  @media (min-width: 60em) {
		--span: 4;
	}

	@media (min-width: 80em) {
		--span: 6;
	}
}

.item--third {
	@media (min-width: 80em) {
		--span: 4;
	}
}

.item--fourth {
  @media (min-width: 60em) {
		--span: 2;
	}

	@media (min-width: 80em) {
		--span: 3;
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console