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

              
                h1.text-center Super awesome flex grid

h2.text-center By default everything is just equally spaced out
.flex-container
  .flex-item.box 1
  .flex-item.box 2
  .flex-item.box 3
  .flex-item.box 4
  .flex-item.box 5

h2.text-center Add class of .flex-wrap and it can break to multiple lines
.flex-container.flex-wrap
  .flex-item.flex-1-3.box .flex-1-3
  .flex-item.flex-1-3.box .flex-1-3
  .flex-item.flex-1-3.box .flex-1-3
  .flex-item.flex-2-3.box .flex-2-3
  .flex-item.flex-1-3.box .flex-1-3

h2.text-center Goes up to a 12 column grid
.flex-container.flex-wrap
  - var n = 1;
  while n <= 12
    .flex-item.flex-1-12.box=n++

h2.text-center anything .flex-1-1 to .flex-12-12 works
.flex-container.flex-wrap
  .flex-item.flex-2-12.box .flex-2-12
  .flex-item.flex-3-12.box .flex-3-12
  .flex-item.flex-4-12.box .flex-4-12
  .flex-item.flex-1-12.box .flex-1-12
  .flex-item.flex-1-12.box .flex-1-12
  .flex-item.flex-1-6.box .flex-1-6
  .flex-item.flex-2-6.box .flex-2-6
  .flex-item.flex-3-6.box .flex-3-6
  .flex-item.flex-1-2.box .flex-1-2
  .flex-item.flex-1-4.box .flex-1-4
  .flex-item.flex-1-4.box .flex-1-4
  .flex-item.flex-3-12.box .flex-3-12
  .flex-item.flex-9-12.box .flex-9-12
  
h2.text-center 
  | add .row to any wrapper to make max-width of 1400px (configurable with variable)
.flex-container.flex-wrap.row
  - var n = 1;
  while n <= 12
    .flex-item.flex-1-12.box=n++
    
h2.text-center can add flex-1-x classes to wrapper to change width of items (this is flex-1-2)
.flex-container.flex-wrap.flex-1-2
  .flex-item.box 
  .flex-item.box
  .flex-item.box
  .flex-item.box
  
h2.text-center can add flex-1-x classes to wrapper to change width of items (this is flex-1-5)
.flex-container.flex-wrap.flex-1-5
  .flex-item.box 
  .flex-item.box
  .flex-item.box
  .flex-item.box
  .flex-item.box
  .flex-item.box
  .flex-item.box
  
h2.text-center can handle responsive classes based on variable breakpoints
h3.text-center (sm-flex-1-1, md-flex-1-2, lg-flex-1-3, xl-flex-1-4, jumbo-flex-1-5)
.flex-container.flex-wrap.flex-1-1.sm-flex-1-1.md-flex-1-2.lg-flex-1-3.xl-flex-1-4.jumbo-flex-1-5
  .flex-item.box 
  .flex-item.box
  .flex-item.box
  .flex-item.box
  .flex-item.box
              
            
!

CSS

              
                html {
  box-sizing: border-box;
  font-size: 16px;

  * {
    box-sizing: inherit;
  }
}

.box {
  width: 100px;
  height: 100px;
  color: white;
  text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.6);
  font-size: 2rem;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.text-center {
  text-align: center;
}

$default: 0px;
$sm: 600px;
$md: 900px;
$lg: 1200px;
$xl: 1440px;
$jumbo: 1920px;
$row-width: 1400px;
$inner-row-width: 800px;
$gutter-width: 15px;

.row {
  margin: 0 auto;
  max-width: $row-width;
  padding: 0 $gutter-width;

  @media (min-width: $row-width + $gutter-width) {
    padding: 0;
  }
}

.row-full {
  left: 50%;
  position: relative;
  transform: translateX(-50%);
  width: 100vw;
}

.inner-row {
  margin: 0 auto;
  max-width: $inner-row-width;
  padding: 0 $gutter-width;

  @media (min-width: $inner-row-width + $gutter-width) {
    padding: 0;
  }
}

// I cannot figure out how to get around defining what breakpoints exist for the grid here & in variables.scss
$breakpoints: (
  default: $default,
  sm: $sm,
  md: $md,
  lg: $lg,
  xl: $xl,
  jumbo: $jumbo
);

@each $key, $breakpoint in $breakpoints {
  $beginning: '';
  @if $key != default {
    $beginning: "#{$key}-"; // sass-lint:disable-line space-around-operator
  }

  @media (min-width: $breakpoint) {
    .#{$beginning}flex-container {
      display: flex;
    }

    .#{$beginning}flex-wrap {
      flex-wrap: wrap;
    }

    .#{$beginning}flex-nowrap {
      flex-wrap: nowrap;
    }

    .#{$beginning}flex-wrap-reverse {
      flex-wrap: wrap-reverse;
    }

    .#{$beginning}flex-row,
    .#{$beginning}flex-dir-row {
      flex-direction: row;
    }

    .#{$beginning}flex-dir-row-reverse {
      flex-direction: row-reverse;
    }

    .#{$beginning}flex-column,
    .#{$beginning}flex-dir-column {
      flex-direction: column;
    }

    .#{$beginning}flex-dir-column-reverse {
      flex-direction: column-reverse;
    }

    .#{$beginning}flex-jc-flex-start {
      justify-content: flex-start;
    }

    .#{$beginning}flex-jc-flex-end {
      justify-content: flex-end;
    }

    .#{$beginning}flex-jc-center {
      justify-content: center;
    }

    .#{$beginning}flex-jc-space-between {
      justify-content: space-between;
    }

    .#{$beginning}flex-jc-space-around {
      justify-content: space-around;
    }

    .#{$beginning}flex-jc-space-evenly {
      justify-content: space-evenly;
    }

    .#{$beginning}flex-ai-flex-start {
      align-items: flex-start;
    }

    .#{$beginning}flex-ai-flex-end {
      align-items: flex-end;
    }

    .#{$beginning}flex-ai-center {
      align-items: center;
    }

    .#{$beginning}flex-ai-stretch {
      align-items: stretch;
    }

    .#{$beginning}flex-ai-baseline {
      align-items: baseline;
    }

    .#{$beginning}flex-ac-flex-start {
      align-content: flex-start;
    }

    .#{$beginning}flex-ac-flex-end {
      align-content: flex-end;
    }

    .#{$beginning}flex-ac-center {
      align-content: center;
    }

    .#{$beginning}flex-ac-stretch {
      align-content: stretch;
    }

    .#{$beginning}flex-ac-space-between {
      align-content: space-between;
    }

    .#{$beginning}flex-ac-space-around {
      align-content: space-around;
    }

    .#{$beginning}flex-as-flex-start {
      align-self: flex-start;
    }

    .#{$beginning}flex-as-flex-end {
      align-self: flex-end;
    }

    .#{$beginning}flex-as-center {
      align-self: center;
    }

    .#{$beginning}flex-as-baseline {
      align-self: baseline;
    }

    .#{$beginning}flex-as-stretch {
      align-self: stretch;
    }

    .flex-container > *,
    .flex-item {
      flex: 1 1 100%;
      // on ie11 there is a bug with flex item's padding and box-sizing: border-box, but forcing 0 padding
      // caused other issues like forcing people to use !important tags just to add some padding to flex items.
      padding: 0;

      &.#{$beginning}flex-1-12,
      .#{$beginning}flex-1-12 & {
        flex: 1 1 8.333%;
      }

      &.#{$beginning}flex-1-11,
      .#{$beginning}flex-1-11 & {
        flex: 1 1 9.09%;
      }

      &.#{$beginning}flex-1-10,
      .#{$beginning}flex-1-10 & {
        flex: 1 1 10%;
      }

      &.#{$beginning}flex-1-9,
      .#{$beginning}flex-1-9 & {
        flex: 1 1 11.111%;
      }

      &.#{$beginning}flex-1-8,
      .#{$beginning}flex-1-8 & {
        flex: 1 1 12.5%;
      }

      &.#{$beginning}flex-1-7,
      .#{$beginning}flex-1-7 & {
        flex: 1 1 14.285%;
      }

      &.#{$beginning}flex-1-6,
      &.#{$beginning}flex-2-12,
      .#{$beginning}flex-1-6 & {
        flex: 1 1 16.666%;
      }

      &.#{$beginning}flex-2-11 {
        flex: 1 1 18.181%;
      }

      &.#{$beginning}flex-1-5,
      &.#{$beginning}flex-2-10,
      .#{$beginning}flex-1-5 & {
        flex: 1 1 20%;
      }

      &.#{$beginning}flex-2-9 {
        flex: 1 1 22.222%;
      }

      &.#{$beginning}flex-1-4,
      &.#{$beginning}flex-2-8,
      &.#{$beginning}flex-3-12,
      .#{$beginning}flex-1-4 & {
        flex: 1 1 25%;
      }

      &.#{$beginning}flex-3-11 {
        flex: 1 1 27.272%;
      }

      &.#{$beginning}flex-2-7 {
        flex: 1 1 28.571%;
      }

      &.#{$beginning}flex-3-10 {
        flex: 1 1 30%;
      }

      &.#{$beginning}flex-1-3,
      &.#{$beginning}flex-2-6,
      &.#{$beginning}flex-3-9,
      &.#{$beginning}flex-4-12,
      .#{$beginning}flex-1-3 & {
        flex: 1 1 33.333%;
      }

      &.#{$beginning}flex-4-11 {
        flex: 1 1 36.363%;
      }

      &.#{$beginning}flex-3-8 {
        flex: 1 1 37.5%;
      }

      &.#{$beginning}flex-2-5,
      &.#{$beginning}flex-4-10 {
        flex: 1 1 40%;
      }

      &.#{$beginning}flex-5-12 {
        flex: 1 1 41.666%;
      }

      &.#{$beginning}flex-3-7 {
        flex: 1 1 42.857%;
      }

      &.#{$beginning}flex-4-9 {
        flex: 1 1 44.444%;
      }

      &.#{$beginning}flex-5-11 {
        flex: 1 1 45.454%;
      }

      &.#{$beginning}flex-1-2,
      &.#{$beginning}flex-2-4,
      &.#{$beginning}flex-3-6,
      &.#{$beginning}flex-4-8,
      &.#{$beginning}flex-5-10,
      &.#{$beginning}flex-6-12,
      .#{$beginning}flex-1-2 & {
        flex: 1 1 50%;
      }

      &.#{$beginning}flex-6-11 {
        flex: 1 1 54.545%;
      }

      &.#{$beginning}flex-5-9 {
        flex: 1 1 55.555%;
      }

      &.#{$beginning}flex-4-7 {
        flex: 1 1 57.142%;
      }

      &.#{$beginning}flex-7-12 {
        flex: 1 1 58.333%;
      }

      &.#{$beginning}flex-6-10 {
        flex: 1 1 60%;
      }

      &.#{$beginning}flex-5-8 {
        flex: 1 1 62.5%;
      }

      &.#{$beginning}flex-7-11 {
        flex: 1 1 63.636%;
      }

      &.#{$beginning}flex-2-3,
      &.#{$beginning}flex-3-5,
      &.#{$beginning}flex-4-6,
      &.#{$beginning}flex-6-9,
      &.#{$beginning}flex-8-12 {
        flex: 1 1 66.666%;
      }

      &.#{$beginning}flex-7-10 {
        flex: 1 1 70%;
      }

      &.#{$beginning}flex-5-7 {
        flex: 1 1 71.428%;
      }

      &.#{$beginning}flex-8-11 {
        flex: 1 1 72.727%;
      }

      &.#{$beginning}flex-3-4,
      &.#{$beginning}flex-6-8,
      &.#{$beginning}flex-9-12 {
        flex: 1 1 75%;
      }

      &.#{$beginning}flex-7-9 {
        flex: 1 1 77.777%;
      }

      &.#{$beginning}flex-4-5,
      &.#{$beginning}flex-8-10 {
        flex: 1 1 80%;
      }

      &.#{$beginning}flex-9-11 {
        flex: 1 1 81.818%;
      }

      &.#{$beginning}flex-5-6,
      &.#{$beginning}flex-10-12 {
        flex: 1 1 83.333%;
      }

      &.#{$beginning}flex-6-7 {
        flex: 1 1 85.714%;
      }

      &.#{$beginning}flex-7-8 {
        flex: 1 1 87.5%;
      }

      &.#{$beginning}flex-8-9 {
        flex: 1 1 88.888%;
      }

      &.#{$beginning}flex-9-10 {
        flex: 1 1 90%;
      }

      &.#{$beginning}flex-10-11 {
        flex: 1 1 90.909%;
      }

      &.#{$beginning}flex-11-12 {
        flex: 1 1 91.666%;
      }

      &.#{$beginning}flex-1-1,
      &.#{$beginning}flex-2-2,
      &.#{$beginning}flex-3-3,
      &.#{$beginning}flex-4-4,
      &.#{$beginning}flex-5-5,
      &.#{$beginning}flex-6-6,
      &.#{$beginning}flex-7-7,
      &.#{$beginning}flex-8-8,
      &.#{$beginning}flex-9-9,
      &.#{$beginning}flex-10-10,
      &.#{$beginning}flex-11-11,
      &.#{$beginning}flex-12-12 {
        flex: 1 1 100%;
      }

      &.#{$beginning}flex-shrink-0 {
        flex-shrink: 0;
      }
      
      &.#{$beginning}flex-grow-0 {
        flex-grow: 0;
      }

      &.#{$beginning}flex-grow-2 {
        flex-grow: 2;
      }

      &.#{$beginning}flex-grow-3 {
        flex-grow: 3;
      }

      &.#{$beginning}flex-grow-4 {
        flex-grow: 4;
      }

      &.#{$beginning}flex-grow-5 {
        flex-grow: 5;
      }
    }
  }
}



              
            
!

JS

              
                const randomColor = () => '#'+Math.floor(Math.random()*16777215).toString(16);

let boxes = document.querySelectorAll('.box');

for (let i=0; i<boxes.length; i++) {
  boxes[i].style.background = randomColor();
}
              
            
!
999px

Console