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

              
                <main>

  <!-- Rectangles -->
  <div class="rectangle-1 red"></div>
  <div class="rectangle-2 yellow-opacity"></div>
  <div class="rectangle-3 lightBlue-opacity"></div>
  <div class="rectangle-4 orange-opacity"></div>

  <!-- Circles -->
  <div class="circle-1-container">
    <div class="circle-1 blue"></div>
  </div>

  <!-- Triangles -->
  <div class="triangle-1 yellow-svg-opacity"></div>
  <div class="triangle-2 orange-svg-opacity"></div>
  <div class="triangle-3 red-svg"></div>
  <div class="triangle-4 lightBlue-svg"></div>

  <!-- Dots -->
  <div class="dot-1-container">
    <div class="dot-1"></div>
  </div>
  <div class="dot-2-container">
    <div class="dot-2"></div>
  </div>
  <div class="dot-3-container">
    <div class="dot-3"></div>
  </div>
  <div class="dot-4-container">
    <div class="dot-4"></div>
  </div>
  <div class="dot-5-container">
    <div class="dot-5"></div>
  </div>

  <!-- Outlines -->
  <div class="outline-1"></div>
  <div class="outline-2"></div>
  <div class="outline-3"></div>
  <div class="outline-4"></div>
  <div class="outline-5"></div>
  <div class="outline-6"></div>
  <div class="outline-7">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
  <div class="outline-8"></div>
  <div class="outline-9">
    <div></div>
    <span class="outline-9-mask"></span>
  </div>
  <div class="outline-10">
    <div></div>
  </div>
  <div class="outline-10-triangles">
    <div class="triangles">
      <div></div>
      <div></div>
      <div></div>
    </div>
  </div>
  <div class="outline-11"></div>
  <div class="outline-12">
    <div></div>
  </div>
  <div class="outline-13">
    <div></div>
  </div>
  <div class="outline-14">
    <div></div>
  </div>

  <!-- Text -->
  <div class="text">
    <svg xmlns="http://www.w3.org/2000/svg" width="210" height="32" viewBox="0 0 210 32">
      <path d="M0,0.919c1.793-0.367,5.058-0.643,8.229-0.643c4.185,0,6.759,0.506,8.874,1.977c1.932,1.149,3.219,3.172,3.219,5.793
               c0,2.851-1.793,5.471-5.149,6.713v0.092c3.265,0.827,6.252,3.401,6.252,7.679c0,2.758-1.195,4.918-2.987,6.39
               c-2.208,1.931-5.84,2.896-11.495,2.896c-3.126,0-5.518-0.229-6.942-0.413V0.919z M5.609,13.149h2.896
               c3.908,0,6.114-1.84,6.114-4.461c0-2.896-2.206-4.229-5.793-4.229c-1.655,0-2.62,0.092-3.218,0.229V13.149z M5.609,27.402
               c0.736,0.092,1.701,0.138,2.988,0.138c3.633,0,6.851-1.38,6.851-5.195c0-3.587-3.126-5.058-7.034-5.058H5.609V27.402z"/>
      <path d="M35.422,22.713l-2.667,8.781h-5.839l9.932-30.989h7.219l10.068,30.989h-6.069l-2.804-8.781H35.422z M44.296,18.437
               l-2.437-7.632c-0.598-1.886-1.104-4.001-1.563-5.794h-0.092c-0.46,1.793-0.92,3.954-1.472,5.794l-2.391,7.632H44.296z"/>
      <path d="M65.466,0.505v18.069c0,6.069,2.529,8.873,6.346,8.873c4.092,0,6.528-2.804,6.528-8.873V0.505h5.655v17.702
               C83.995,27.77,79.075,32,71.627,32c-7.172,0-11.815-4-11.815-13.748V0.505H65.466z"/>
      <path d="M99.002,0.505v12.414h13.104V0.505h5.654v30.989h-5.654V17.839H99.002v13.655h-5.655V0.505H99.002z"/>
      <path d="M133.318,22.713l-2.667,8.781h-5.839l9.931-30.989h7.219l10.069,30.989h-6.068l-2.805-8.781H133.318z M142.191,18.437
               l-2.437-7.632c-0.598-1.886-1.104-4.001-1.563-5.794H138.1c-0.459,1.793-0.919,3.954-1.472,5.794l-2.391,7.632H142.191z"/>
      <path d="M163.36,0.505v18.069c0,6.069,2.528,8.873,6.346,8.873c4.092,0,6.528-2.804,6.528-8.873V0.505h5.655v17.702
               c0,9.563-4.92,13.793-12.367,13.793c-7.174,0-11.817-4-11.817-13.748V0.505H163.36z"/>
      <path d="M191.103,25.333c1.84,1.058,4.599,1.978,7.495,1.978c3.632,0,5.656-1.702,5.656-4.23c0-2.345-1.563-3.725-5.518-5.149
               c-5.104-1.839-8.368-4.552-8.368-9.012c0-5.057,4.229-8.919,10.943-8.919c3.355,0,5.839,0.735,7.447,1.563l-1.379,4.551
               c-1.104-0.598-3.266-1.471-6.162-1.471c-3.586,0-5.148,1.931-5.148,3.724c0,2.392,1.793,3.495,5.931,5.104
               c5.38,2.022,8,4.735,8,9.194c0,4.966-3.77,9.288-11.771,9.288c-3.264,0-6.666-0.921-8.367-1.931L191.103,25.333z"/>
    </svg>
  </div>

</main>

              
            
!

CSS

              
                // Artwork based on
// https://static.theceomagazine.net/wp-content/uploads/2019/02/04085338/Bauhaus.jpg

*,
*:before,
*:after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: #f3f3f3;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 1010px;
}


//
// Colors
// -----------------------------------------

$colors: (
    red: #d42424,
    orange: #fc4f0b,
    yellow: #ffe600,
    blue: #13459e,
    lightBlue: #9cbbff
);

@each $color, $hex in $colors {

    // CSS shapes
    // ----------------------

    .#{$color} {
        background-color: #{$hex};
    }

    .#{$color}-opacity {
        background-color: rgba($hex, .75);
    }


    // SVG shapes
    // ----------------------

    .#{$color}-svg {
        polygon {
            fill: #{$hex};
        }
    }

    .#{$color}-svg-opacity {
        polygon {
            fill: rgba($hex, .75);
        }
    }
}


//
// Grid content
// -----------------------------------------

main {
    display: grid;
    width: 1000px;
    grid-template-columns: repeat(20, 1fr);
    grid-template-rows: none;
    grid-auto-rows: 35px;
}


// Rectangles
// ----------------------

.rectangle-1 {
    grid-column: 8 / span 11;
    grid-row: 4 / span 4;
}

.rectangle-2 {
    grid-column: 18 / span 3;
    grid-row: 2 / span 3;
}

.rectangle-3 {
    grid-column: 16 / span 3;
    grid-row: 8 / span 3;
}

.rectangle-4 {
    grid-column: 3 / span 2;
    grid-row: 2;
}


// Circles
// ----------------------

.circle-1-container {
    grid-column: 10 / span 8;
    grid-row: 2 / span 11;
}

.circle-1 {
    border-radius: 50%;
    width: 100%;
    padding-bottom: 100%;
}


// Triangle containers
// ----------------------

.triangle-1 {
    grid-column: 7 / span 4;
    grid-row: 2 / span 7;
}

.triangle-2 {
    grid-column: 6 / span 7;
    grid-row: 10 / span 5;
}

.triangle-3 {
    grid-column: 9 / span 7;
    grid-row: 8 / span 8;
}

.triangle-4 {
    grid-column: 4 / span 10;
    grid-row: 11 / span 6;
}


// Dots
// ----------------------

%dotStyle {
    position: relative;
    height: 26px;
    width: 26px;
    border-radius: 50%;
    background-color: #000;
}

.dot-1-container {
    grid-column: 11;
    grid-row: 1;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
}

.dot-1 {
    @extend %dotStyle;
    left: -13px;
    bottom: -2px;
}

.dot-2-container {
    grid-column: 2;
    grid-row: 10;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
}

.dot-2 {
    @extend %dotStyle;
    top: -11px;
    right: -2px;
}

.dot-3-container {
    grid-column: 3;
    grid-row: 8;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
}

.dot-3 {
    @extend %dotStyle;
    top: -13px;
    right: -11px;
}

.dot-4-container {
    grid-column: 16;
    grid-row: 1;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
}

.dot-4 {
    @extend %dotStyle;
    left: 12px;
    bottom: -10px;
}

.dot-5-container {
    grid-column: 10;
    grid-row: 18;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

.dot-5 {
    @extend %dotStyle;
    bottom: -10px;
}


// Outlines
// ----------------------

.outline-1 {
    grid-column: 1 / span 10;
    grid-row: 2 / span 7;
    border-top: 4px solid;
    border-right: 4px solid;
}

.outline-2 {
    grid-column: 3 / span 1;
    grid-row: 1 / span 2;
    border-left: 4px solid;
    border-bottom: 4px solid;
}

.outline-3 {
    grid-column: 3 / span 1;
    grid-row: 3 / span 5;
    border-right: 4px solid;
}

.outline-4 {
    grid-column: 16 / span 5;
    grid-row: 1 / span 4;
    border-right: 4px solid;
    border-bottom: 4px solid;
}

.outline-5 {
    grid-column: 19 / span 1;
    grid-row: 5 / span 7;
    border-right: 4px solid;
}

.outline-6 {
    position: relative;
    grid-column: 3 / span 9;
    grid-row: 10 / span 1;
    border-top: 4px solid;
}

.outline-7 {
    grid-column: 14 / span 4;
    grid-row: 2 / span 8;
    border-left: 5px solid; // compensates the skew
    transform: skew(-31.8deg) translate3d(33.5px, 3px, 0);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 20px;

    div {
        height: 20px;
        width: 55px;
        background-color: #000;
        margin-bottom: 8px;
        margin-left: -1px;
    }
}

.outline-8 {
    grid-column: 11 / span 5;
    grid-row: 16 / span 3;
    border-bottom: 4px solid;
    border-right: 4px solid;
}

.outline-9 {
    grid-column: 16 / span 4;
    grid-row: 12 / span 4;
    display: flex;
    justify-content: center;
    overflow: hidden;

    div {
        height: 100%;
        width: 7px;
        background-color: #000;
        transform: skew(-55deg) translate3d(-1px,0,0);
    }
}

.outline-10,
.outline-10-triangles {
    grid-column: 4 / span 2;
    grid-row: 8 / span 2;
}

.outline-10 {
    display: flex;
    justify-content: center;

    div {
        height: 100%;
        width: 7px;
        background-color: #000;
        transform: skew(55deg);
    }
}

.outline-10-triangles {
    .triangles {
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        transform: rotate(-55deg);

        div {
            height: 0;
            width: 0;
            border-top: 15px solid;
            border-left: 22px solid transparent;
            border-right: 22px solid transparent;
        }
    }

}

.outline-11 {
    grid-column: 2 / span 1;
    grid-row: 17 / span 2;
    border-left: 4px solid;
}

.outline-12 {
    grid-column: 2 / span 5;
    grid-row: 10 / span 7;
    display: flex;
    justify-content: center;
    overflow: hidden;

    div {
        height: 100%;
        width: 5px;
        background-color: #000;
        transform: skew(-45deg) scale(1, 0.95) translate3d(-1px, 15px, 0);
        box-shadow: 1px 1px 0 0 #000;
    }
}

.outline-13 {
    grid-column: 2 / span 2;
    grid-row: 15 / span 2;
    display: flex;
    justify-content: center;

    div {
        height: 100%;
        width: 4px;
        background-color: #000;
        transform: rotate(-45deg) translate3d(13px, 11px, 0) scale(1, 1.4);
    }
}

.outline-14 {
    grid-column: 1 / span 2;
    grid-row: 15 / span 2;
    display: flex;
    justify-content: center;

    div {
        height: 100%;
        width: 4px;
        background-color: #000;
        transform: rotate(45deg) translate3d(-1px,-1px,0) scale(1, 1.4);
    }
}


// Text
// ----------------------

.text {
    grid-column: 2 / span 5;
    grid-row: 10 / span 7;

    svg {
        transform: rotate(-45deg) translate3d(-37px, 123px, 0);
    }
}


//
// Z-index
// -----------------------------------------

$z-index: (
    rectangle-1: 0,
    rectangle-2: 10,
    outline-4: 20,
    circle-1-container: 30,
    rectangle-3: 40,
    triangle-3: 50,
    triangle-1: 60,
    triangle-4: 70,
    triangle-2: 80,
    outline-1: 90,
    outline-2: 100,
    outline-3: 110,
    outline-5: 120,
    outline-6: 130,
    outline-7: 140,
    outline-8: 150,
    outline-9: 160,
    outline-10: 170,
    outline-10-triangles: 180,
    outline-11: 190,
    outline-12: 200,
    outline-13: 210,
    outline-14: 220,
    rectangle-4: 230,
    dot-1-container: 240,
    dot-2-container: 250,
    dot-3-container: 260,
    dot-4-container: 270,
    dot-5-container: 280,
    text: 290
);

@each $class, $value in $z-index {
    .#{$class} {
        z-index: $value;
    }
}

              
            
!

JS

              
                //
// Utilities
// -----------------------------------------

var getHeight = el => el.getBoundingClientRect().height;
var getWidth = el => el.getBoundingClientRect().width;

//
// Class definition
// -----------------------------------------

class RegularTriangle {
    constructor(parent, points, hasBorder) {
        this.parent = parent;
        this.points = points;
        this.hasBorder = hasBorder;
    }

    doTrianglePolygon(
        parentElement,
        strokeWidth = 4,
        strokeColor = "#000"
    ) {
        var polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");

        if (!this.hasBorder) {
            var pointsString = this.points.join(" ");
            polygon.setAttribute("points", pointsString);
        } else {
            // preventing overflow by setting
            // a safe area to draw the stroke
            var strokeOffset = strokeWidth / 2;
            var newPoints = this.points.map(pointItem =>
                pointItem.map(num => {
                    if (num === 0) {
                        return num + strokeOffset
                    } else if (
                        num === getHeight(this.parent) || num === getWidth(this.parent)) {
                        return num - strokeOffset
                    } else {
                        return num
                    }
                } )
            )

            var pointsString = newPoints.join(" ");
            polygon.setAttribute("points", pointsString);
            polygon.style.stroke = strokeColor;
            polygon.style.strokeWidth = strokeWidth;
        }

        parentElement.appendChild(polygon);
    }

    draw() {
        var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
        svg.setAttribute("height", getHeight(this.parent));
        svg.setAttribute("width", getWidth(this.parent));
        this.parent.appendChild(svg);

        this.doTrianglePolygon(svg);
    }
}

class ComplexTriangle extends RegularTriangle {
    constructor(parent, points, hasBorder, innerPoints) {
        super(parent, points, hasBorder);
        this.innerPoints = innerPoints;
    }

    doInnerTrianglePolygon(
        parentElement,
        nextElement = null
    ) {
        var polygon = document.createElementNS("http://www.w3.org/2000/svg", "polygon");

        var pointsString = this.innerPoints.join(" ");
        polygon.setAttribute("points", pointsString);

        if (nextElement) {
            parentElement.insertBefore(polygon, nextElement);
        } else {
            parentElement.appendChild(polygon);
        }
    }

    doGroupOfLines(
        parent,
        nextSibling,
        linesNum,
        linesWidth,
        linesColor
    ) {
        var group = document.createElementNS("http://www.w3.org/2000/svg", "g");
        group.setAttribute("clip-path", "url(#mask)");
        parent.insertBefore(group, nextSibling);

        var distance = getHeight(this.parent) / (linesNum + 1);
        var n = 0;
        while (n < linesNum) {
            var line = document.createElementNS("http://www.w3.org/2000/svg", "line");
            line.style.stroke = linesColor;
            line.style.strokeWidth = linesWidth;

            line.setAttribute("x1", 0);
            line.setAttribute("x2", getWidth(this.parent));
            line.setAttribute("y1", distance.toFixed(2));
            line.setAttribute("y2", distance.toFixed(2));
            group.appendChild(line);

            n++;
            distance += distance / n;
        }
    }

    draw(
        linesNum = 16,
        linesWidth = 4,
        linesColor = "#000"
    ) {
        super.draw();

        // references to the elements created
        // in the inherited `draw()` method
        var svg = this.parent.children[0];
        var triangle = svg.children[0];

        // removing fill color from main triangle
        triangle.style.fill = "none";

        // lines
        this.doGroupOfLines(svg, triangle, linesNum, linesWidth, linesColor);

        // clipping path: same as main triangle
        var clipPath = document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
        clipPath.id = "mask";
        svg.prepend(clipPath);
        this.doTrianglePolygon(clipPath);

        // inner triangle
        this.doInnerTrianglePolygon(svg, triangle);
    }
}


//
// Regular triangles
// -----------------------------------------

var t1 = document.querySelector(".triangle-1");
var t2 = document.querySelector(".triangle-2");
var t3 = document.querySelector(".triangle-3");

var regularTriangles = [
    {
        parent: t1,
        polygonPoints: [
            [getWidth(t1), 0],
            [getWidth(t1), getHeight(t1)],
            [0, getHeight(t1)]
        ],
        hasBorder: false
    },
    {
        parent: t2,
        polygonPoints: [
            [0, 0],
            [getWidth(t2), 0],
            [Math.round(getWidth(t2) * .7), getHeight(t2)]
        ],
        hasBorder: true
    },
    {
        parent: t3,
        polygonPoints: [
            [getWidth(t3) / 2, 0],
            [getWidth(t3), getHeight(t3)],
            [0, getHeight(t3)]
        ],
        hasBorder: true
    }
]


//
// Complex triangles
// -----------------------------------------

var t4 = document.querySelector(".triangle-4");

var complexTriangles = [
    {
        parent: t4,
        polygonPoints: [
            [getWidth(t4) * .42, 0],
            [getWidth(t4), getHeight(t4)],
            [0, getHeight(t4)]
        ],
        hasBorder: true,
        innerPolygonPoints: [
            [getWidth(t4) * .42, 0],
            [getWidth(t4) * .3, getHeight(t4)],
            [0, getHeight(t4)]
        ]
    }
]


//
// Create instances and run methods
// -----------------------------------------

var trianglesArray = []

for (triangle of regularTriangles) {
    trianglesArray.push(new RegularTriangle(
        triangle.parent,
        triangle.polygonPoints,
        triangle.hasBorder
    ));
}

for (triangle of complexTriangles) {
    trianglesArray.push(new ComplexTriangle(
        triangle.parent,
        triangle.polygonPoints,
        triangle.hasBorder,
        triangle.innerPolygonPoints
    ));
}

trianglesArray.forEach(triangle => triangle.draw());
              
            
!
999px

Console