css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div class="main-grid actual-grid">

    <main class="about">
        <h1>Hello World</h1>
        <p>About Ipsum</p>
    <aside class="news">
        <h4>Latest News</h4>
        <h3>News article goes here</h3>
        <p class="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae eros a ex consequat interdum. Vestibulum velit felis, fermentum sit amet convallis eget, suscipit ut est. Curabitur aliquet ante sit amet nisl suscipit mollis. Quisque in sodales nulla, eu finibus felis. Nam venenatis blandit metus a dignissim. </p>
        <a href="#">Learn more</a>

        <aside class="photo">
        <img src="https://placekitten.com/1000/800" alt="" />

<div class="controls">
    <h3>Layout On the Grid (click) </h3>
    <button class="button gridButton" data-selectClass="about">About</button>
    <button class="button gridButton" data-selectClass="news">News</button>
    <button class="button gridButton" data-selectClass="photo">Photo</button>
<div class="main-grid">
      <div class="box about" data-row="1" data-column="1"></div>
      <div class="box news" data-row="1" data-column="2"></div>
      <div class="box photo" data-row="1" data-column="3"></div>
      <div class="box" data-row="1" data-column="4"></div>
      <div class="box" data-row="1" data-column="5"></div>
      <div class="box" data-row="1" data-column="6"></div>
      <div class="box" data-row="2" data-column="1"></div>
      <div class="box" data-row="2" data-column="2"></div>
      <div class="box" data-row="2" data-column="3"></div>
      <div class="box" data-row="2" data-column="4"></div>
      <div class="box" data-row="2" data-column="5"></div>
      <div class="box" data-row="2" data-column="6"></div>
      <div class="box" data-row="3" data-column="1"></div>
      <div class="box" data-row="3" data-column="2"></div>
      <div class="box" data-row="3" data-column="3"></div>
      <div class="box" data-row="3" data-column="4"></div>
      <div class="box" data-row="3" data-column="5"></div>
      <div class="box" data-row="3" data-column="6"></div>
      <div class="box" data-row="4" data-column="1"></div>
      <div class="box" data-row="4" data-column="2"></div>
      <div class="box" data-row="4" data-column="3"></div>
      <div class="box" data-row="4" data-column="4"></div>
      <div class="box" data-row="4" data-column="5"></div>
      <div class="box" data-row="4" data-column="6"></div>
      <div class="box" data-row="5" data-column="1"></div>
      <div class="box" data-row="5" data-column="2"></div>
      <div class="box" data-row="5" data-column="3"></div>
      <div class="box" data-row="5" data-column="4"></div>
      <div class="box" data-row="5" data-column="5"></div>
      <div class="box" data-row="5" data-column="6"></div>
      <div class="box" data-row="6" data-column="1"></div>
      <div class="box" data-row="6" data-column="2"></div>
      <div class="box" data-row="6" data-column="3"></div>
      <div class="box" data-row="6" data-column="4"></div>
      <div class="box" data-row="6" data-column="5"></div>
      <div class="box" data-row="6" data-column="6"></div>
    <a class="button save">
    <span class="close">(close)</span>

              img {
    width: 100%;
    object-fit: cover;
    height: 100%;
body {
* {
    box-sizing: border-box;
.button {
    display: inline-block;
    background-color: purple;
    color: white;
    padding: 10px 15px;
    cursor: pointer;
    text-align: center;
    &.save {
        display: block;
    &:hover {
        background-color: darken(purple, 10%);
.actual-grid {
    background-color: tomato;
.controls .main-grid {
    height: 30vh;
    margin: 10px 0;
    grid-template-rows: repeat(6, 1fr);
    grid-gap: 2%;

.controls h3 {
    margin: 0 0 10px 0;
.main-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(100px, 1fr);
    grid-gap: 1vw;
.box {
    background-color: tomato;
    &:hover {
        background-color: darken(tomato, 10%);
    &.about {
        background-color: pink;
        &:hover {
            background-color: darken(pink, 10%);
    &.news {
        background-color: lightblue;
        &:hover {
            background-color: darken(lightblue, 10%);
    &.photo {
        background-color: goldenrod;
        &:hover {
            background-color: darken(goldenrod, 10%);

.controls {
    position: fixed;
    opacity: .5;
    right: 0;
    bottom: 0;
    background-color: #efefef;
    width: 30vw;
    padding: 20px;
    transition: .3s ease-out;
    transform: translatey(87%);
    .close {
        font-size: .7em;
    &:hover {
        opacity: 1;
    &.active {
        opacity: 1;
        transform: translatey(0);
    .active {
        color: tomato;
.about {
    background-color: pink;
    padding: 1vw;
.photo {
    background-color: goldenrod;
.news {
    background-color: lightblue;
    padding: 1vw;

              let selectClass = "";
const classes = ['about', 'news', 'photo'];
$('.gridButton').on('click', function(e) {
    selectClass = $(this).data('selectclass');

$('.controls .main-grid').on('mousedown', function(e) {
    // e.preventDefault;
    $('.box').bind('mouseover', function() {
$(window).on('mouseup', function() {

$('.box').on('click', function(e) {

$('.save').on('click', function(e) {

function findBoxes() {
    let boxes = [];
    $('.box').each(function(i, elem) {
        if (elem.classList.length > 1) {
    return boxes

function splitBoxArray(array) {
    let subArray = [];
    $(classes).each(function(i, elem) {
       subArray[elem] = array.filter(function(item) {
           return $(item).hasClass(elem);
    return subArray;

function setGrid(className, boxes) {
    const rows = [];
    const columns = [];
    $(boxes).each(function(i, elem) {
            let row = $(elem).data("row");
            let col = $(elem).data("column");
    if (rows.length > 0) {
        let firstCol = Math.min(...columns);
        let lastCol = Math.max(...columns) + 1;
        let firstRow = Math.min(...rows);
        let lastRow = Math.max(...rows) + 1;
        let gridArea = firstRow + " / " + firstCol + " / " + lastRow + " / " + lastCol;
        console.log(firstCol, lastCol, firstRow, lastRow);
        $('.actual-grid .' + className).css('grid-area', gridArea);

function getGridPosition(item) {
    let boxArray = findBoxes();
    let splitArray = splitBoxArray(boxArray);

    setGrid("about", splitArray.about);
    setGrid("news", splitArray.news);
    setGrid("photo", splitArray.photo);

$('.controls h3').on('click', function(e) {
$('.close').on('click', function(e) {
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................