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

              
                <div class="shell">
    <div class="intro">
        <h1 class="heading">Reduce the need for pseudo-elements 👋</h1>
        <p class="subheading">Here are some user interface patterns where pseudo-elements are no longer necessary.</p>
    </div>
    <div class="examples">
        <div class="new">
            <h3 class="heading">
                Without pseudo-elements 😀
            </h3>
        </div>
        <div class="old">
            <h3 class="heading">
                With pseudo-elements 😩
            </h3>
        </div>
        
        <div class="descriptor">
            <h2 class="heading">Button shapes via <code>clip-path</code></h2>
            <div>No need to nest elements and worry about all of their respective pseudo-elements.</div>
        </div>
        
        <div class="">
            <button class="button button--angle">An angle button</button>
            <button class="button button--chevron">More angles in this one</button>
            <button class="button button--bevel">Some different shape just because</button>
        </div>

        <div class="">
            <button class="btn btn--shape btn--angle"><span class="btn__inner">An angle button</span></button>
            <button class="btn btn--shape btn--chevron"><span class="btn__outer"><span class="btn__inner">More angles in this one</span></span></button>
            <button class="btn btn--shape btn--bevel"><span class="btn__outer"><span class="btn__inner-left"></span><span class="btn__inner">Some different shape just because</span><span class="btn__inner-right"></span></span></button>
        </div>

        <div class="descriptor">
            <h2 class="heading">Button wipes via <code>linear-gradient()</code></h2>
            <div>No more stacking concerns or transforming pseudo-elements.</div>
        </div>
        
        <div class="">
            <button class="button button--wipe">Wipe left to right</button>
            <button class="button button--wipe button--wipe-vertical">Wipe top to bottom</button>
        </div>

        <div class="">
            <button class="btn btn--wipe"><span class="btn__inner">Wipe left to right</span></button>
            <button class="btn btn--wipe btn--wipe-vertical"><span class="btn__inner">Wipe top to bottom</span></button>
        </div>
        
        <div class="descriptor">
            <h2 class="heading">Link lines via <code>linear-gradient()</code></h2>
            <div>No more stacking concerns or transforming pseudo-elements.</div>
        </div>

        <div class="">
            <button class="button button--line">It's line time</button>
        </div>
        
        <div class="">
            <button class="btn btn--line">It's line time</button>
        </div>
        
        <div class="descriptor">
            <h2 class="heading">Ratio tile with screen color overlay via <code>aspect-ratio</code> and <code>background-blend-mode</code></h2>
            <div>No more nested element positioning and stacking concerns.</div>
        </div>

        <div class="">
            <div class="tile">
                <strong>Hover me. No pseudo, baby!</strong>
            </div>
        </div>
        
        <div class="">
            <div class="tle">
                <div class="tle__inner">
                    <strong>This uses a pseudo-element…sad!</strong>
                </div>
            </div>
        </div>

    </div>

</div>

              
            
!

CSS

              
                /**
 * NO pseudo-elements
 */

/* global no-pseudo-element button styles */

.button,
.btn,
.tile,
.tle {
    --duration: 300ms;
    --easing: cubic-bezier(0.165, 0.840, 0.440, 1);
}

.button {
    --bg-color: wheat;
    --bg-color-hover: steelblue;
    --padding-x: 1.5rem;
    --padding-y: 1rem;
    
    background-color: var(--bg-color);
    color: black;
    display: inline-block;
    line-height: 1;
    padding: var(--padding-y) var(--padding-x);
    transition: background-color var(--duration) var(--easing);
}

.button:hover {
    background-color: var(--bg-color-hover);
    transition: background-color var(--duration) var(--easing);
}


/* button--angle */

.button--angle {
    --bg-color: lightseagreen;
    --angle-width: 2rem;
    --padding-x: 1rem;
    
    background-color: var(--bg-color);
    clip-path: polygon(0% 0%, calc(100% - var(--angle-width)) 0%, 100% 50%, calc(100% - var(--angle-width)) 100%, 0% 100%);
    padding-right: calc(var(--angle-width) + var(--padding-x));
}

/* button--chevron */

.button--chevron {
    --bg-color: lightcoral;
    --angle-width: 1.25rem;
    --padding-x: 0.75rem;
    --padding-y: 0.75rem;
    
    background-color: var(--bg-color);
    clip-path: polygon(
        0% 0%, 
        calc(100% - var(--angle-width)) 0%, 
        100% 50%, 
        calc(100% - var(--angle-width)) 100%, 
        0% 100%, 
        var(--angle-width) 50%
    );
    padding-left: calc(var(--angle-width) + var(--padding-x));
    padding-right: calc(var(--angle-width) + var(--padding-x));
}


/* button--bevel */

.button--bevel {
    --bg-color: deepskyblue;
    --angle-width: 0.75rem;
    --padding-x: 1rem;
    
    background-color: var(--bg-color);
    clip-path: polygon(
        var(--angle-width) 0%, 
        calc(100% - var(--angle-width)) 0%, 
        100% var(--angle-width), 
        100% calc(100% - var(--angle-width)), 
        calc(100% - var(--angle-width)) 100%, 
        var(--angle-width) 100%, 
        0% calc(100% - var(--angle-width)), 
        0% var(--angle-width)
    );
    padding-left: calc(var(--angle-width) + var(--padding-x));
    padding-right: calc(var(--angle-width) + var(--padding-x));
}


/* button--wipe */

.button--wipe {
    --bg-color: thistle;
    --bg-color-hover: darkorange;
    --bg-size: 0% 100%;
    --wipe-dir: 90deg;
        
    background-color: var(--bg-color);
    background-image: linear-gradient(var(--wipe-dir), var(--bg-color-hover), var(--bg-color-hover));
    background-repeat: no-repeat;
    background-size: var(--bg-size);
    transition: background-size var(--duration) var(--easing);
}

.button--wipe:hover {
    --bg-size: 100% 100%;
    
    background-color: var(--bg-color);
    background-image: linear-gradient(var(--wipe-dir), var(--bg-color-hover), var(--bg-color-hover));
    background-size: var(--bg-size);
    transition: background-size var(--duration) var(--easing);
}


/* button--wipe-vertical */

.button--wipe-vertical {
    --bg-size: 100% 0%;
    --wipe-dir: 180deg;
}


/* button--line */

.button--line {
    --bg-color: darkseagreen;
    --bg-color-hover: lightblue;
    --duration: 200ms;
    
    box-shadow: inset 0 -0.125rem 0 0 var(--bg-color);
    background-color: transparent;
    background-image: linear-gradient(180deg, transparent 60%, var(--bg-color-hover) 60%, var(--bg-color-hover) 100%, transparent 100%);
    background-repeat: no-repeat;
    background-size: 0% 100%;
    color: slateblue;
    font-size: 1.5rem;
    padding: 0;
    transition: background-size var(--duration) var(--easing);
}

.button--line:hover {
    background-color: transparent;
    background-size: 100% 100%;
    box-shadow: none;
    transition: background-size var(--duration) var(--easing);
}

.tile {
    --overlay: rgb(250 255 0 / 0.675);
    --overlay-hover: rgb(0 191 255 / 0.675);
    --duration: 150ms;
    
    align-items: flex-end;
    aspect-ratio: 400 / 240;
    background-blend-mode: overlay;
    background-color: var(--overlay);
    /* photo credit: https://unsplash.com/photos/Gk7enstVtGE */
    background-image: url(https://marcel.imarc.host/900x540.jpg);
    display: flex;
    padding: 1rem;
    transition: background-color var(--duration) var(--easing);
}

.tile:hover {
    background-color: var(--overlay-hover);
    transition: background-color var(--duration) var(--easing);
}



/**
 * HAS pseudo-elements
 */

/* global has-pseudo-element button styles */

.btn {
    --bg-color: wheat;
    --bg-color-hover: steelblue;
    --padding-x: 1.5rem;
    --padding-y: 1rem;
    
    background-color: transparent;
    color: black;
    display: inline-block;
    line-height: 1;
    position: relative;
}

/* we need a nested element */

.btn__inner {
    display: block;
    padding: var(--padding-y) var(--padding-x);
}

/* btn--shape global styles */

.btn--shape .btn__inner {
    background-color: var(--bg-color);
    transition: background-color var(--duration) var(--easing);
}

.btn--shape:hover .btn__inner {
    background-color: var(--bg-color-hover);
    transition: background-color var(--duration) var(--easing);
}

/* btn--angle */

.btn--angle {
    --bg-color: lightseagreen;
    --angle-width: 2rem;
    --padding-x: 1rem;
    
    padding-right: var(--angle-width);
}

.btn--angle::before {
    content: '';
    border: 0 solid transparent;
    border-bottom-width: calc(var(--angle-width) * 0.75);
    border-top-width: calc(var(--angle-width) * 0.75);
    border-left: var(--angle-width) solid var(--bg-color);
    position: absolute;
    right: 0;
    top: 0;
    transition: border-color var(--duration) var(--easing);
}

.btn--angle .btn__inner {
    background-color: var(--bg-color);
}

.btn--angle:hover::before {
    border-left-color: var(--bg-color-hover);
    transition: border-color var(--duration) var(--easing);
}


/* btn--chevron */

.btn--chevron {
    --bg-color: lightcoral;
    --angle-width: 1.25rem;
    --padding-x: 0.75rem;
    --padding-y: 0.75rem;
    
    padding-right: var(--angle-width);
}

.btn--chevron::before {
    content: '';
    border: 0 solid transparent;
    border-bottom-width: var(--angle-width);
    border-top-width: var(--angle-width);
    border-left: var(--angle-width) solid var(--bg-color);
    position: absolute;
    right: 0;
    top: 0;
    transition: border-color var(--duration) var(--easing);
}

.btn--chevron .btn__outer {
    display: block;
    padding-left: var(--angle-width);
}

.btn--chevron .btn__outer::after,
.btn--chevron .btn__outer::before {
    content: '';
    border: 0 solid transparent;
    position: absolute;
    left: 0;
    transition: border-color var(--duration) var(--easing);
}

.btn--chevron .btn__outer::after {
    border-left-width: var(--angle-width);
    border-bottom: var(--angle-width) solid var(--bg-color);
    bottom: 0;
}

.btn--chevron .btn__outer::before {
    border-left-width: var(--angle-width);
    border-top: var(--angle-width) solid var(--bg-color);
    top: 0;
}

.btn--chevron:hover::before {
    border-left-color: var(--bg-color-hover);
    transition: border-color var(--duration) var(--easing);
}

.btn--chevron:hover .btn__outer::after,
.btn--chevron:hover .btn__outer::before {
    transition: border-color var(--duration) var(--easing);
}

.btn--chevron:hover .btn__outer::after {
    border-bottom-color: var(--bg-color-hover);
}

.btn--chevron:hover .btn__outer::before {
    border-top-color: var(--bg-color-hover);
}


/* btn--bevel */

.btn--bevel {
    --bg-color: deepskyblue;
    --angle-width: 0.75rem;
    --padding-x: 1rem;
}

.btn--bevel .btn__outer {
    background-color: red;
    padding-left: var(--angle-width);
    padding-right: var(--angle-width);
}

.btn--bevel .btn__outer,
.btn--bevel .btn__inner-left,
.btn--bevel .btn__inner-right {
    display: block;
}

.btn--bevel .btn__inner-left,
.btn--bevel .btn__inner-right {
    background-color: var(--bg-color);
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    transition: background-color var(--duration) var(--easing);
    width: var(--angle-width);
}

.btn--bevel .btn__inner-right {
    left: auto;
    right: 0;
}

.btn--bevel .btn__inner-left::after,
.btn--bevel .btn__inner-right::after,
.btn--bevel .btn__inner-left::before,
.btn--bevel .btn__inner-right::before {
    border: 0 solid transparent;
    content: '';
    left: 0;
    position: absolute;
    transition: border-color var(--duration) var(--easing);
}

.btn--bevel .btn__inner-left::after {
    border-top: var(--angle-width) solid var(--bg-color);
    border-right-width: 0;
    border-left: var(--angle-width) solid ghostwhite;
    bottom: 0;
}

.btn--bevel .btn__inner-left::before {
    border-top: var(--angle-width) solid ghostwhite;
    border-bottom-width: 0;
    border-right: var(--angle-width) solid var(--bg-color);
    top: 0;
}

.btn--bevel .btn__inner-right::after {
    border-bottom: var(--angle-width) solid ghostwhite;
    border-top-width: 0;
    border-left: var(--angle-width) solid var(--bg-color);
    bottom: 0;
}

.btn--bevel .btn__inner-right::before {
    border-bottom: var(--angle-width) solid var(--bg-color);
    border-left-width: 0;
    border-right: var(--angle-width) solid ghostwhite;
    top: 0;
}

.btn--bevel:hover .btn__inner-left::after,
.btn--bevel:hover .btn__inner-right::after,
.btn--bevel:hover .btn__inner-left::before,
.btn--bevel:hover .btn__inner-right::before {
    transition: border-color var(--duration) var(--easing);
}

.btn--bevel:hover .btn__inner-left,
.btn--bevel:hover .btn__inner-right {
   background-color: var(--bg-color-hover);
}

.btn--bevel:hover .btn__inner-left::after {
   border-top-color: var(--bg-color-hover);
}

.btn--bevel:hover .btn__inner-left::before {
   border-right-color: var(--bg-color-hover);
}

.btn--bevel:hover .btn__inner-right::after {
   border-left-color: var(--bg-color-hover);
}

.btn--bevel:hover .btn__inner-right::before {
   border-bottom-color: var(--bg-color-hover);
}


/* btn--wipe */

.btn--wipe {
    --bg-color: thistle;
    --bg-color-hover: darkorange;
    
    background-color: var(--bg-color);
    position: relative;
}

.btn--wipe::before {
    background-color: var(--bg-color-hover);
    content: '';
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    transform: scaleX(0);
    transform-origin: 0 0;
    transition: transform var(--duration) var(--easing);
    width: 100%;
}

.btn--wipe .btn__inner {
    position: relative;
}

.btn--wipe:hover::before {
    transform: scaleX(100%);
}

.btn--wipe-vertical::before {
    transform: scaleY(0);
}


/* btn--line */

.btn--line {
    --bg-color: darkseagreen;
    --bg-color-hover: lightblue;
    --duration: 200ms;
    
    box-shadow: inset 0 -0.125rem 0 0 var(--bg-color);
    color: slateblue;
    font-size: 1.5rem;
    padding: 0;
}

.btn--line::before {
    background-color: var(--bg-color-hover);
    bottom: 0;
    content: '';
    height: 0.625rem;
    position: absolute;
    transform: scaleX(0);
    transform-origin: 0 0;
    transition: transform var(--duration) var(--easing);
    width: 100%;
    z-index: -1;
}

.btn--line:hover {
    box-shadow: none;
}

.btn--line:hover::before {
    transform: scaleX(100%);
    transition: transform var(--duration) var(--easing);
}

.tle {
    --overlay: rgb(250 255 0 / 0.675);
    --overlay-hover: rgb(0 191 255 / 0.675);
    --duration: 150ms;
    
    /* photo credit: https://unsplash.com/photos/Gk7enstVtGE */
    background-image: url(https://marcel.imarc.host/900x540.jpg);
    background-repeat: no-repeat;
    padding-top: 60%;
    position: relative;
    transition: background-color var(--duration) var(--easing);
}

.tle::before {
    background-color: var(--overlay);
    content: '';
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    transition: background-color var(--duration) var(--easing);
    width: 100%;
}

.tle__inner {
    align-items: flex-end;
    display: flex;
    height: 100%;
    left: 0;
    padding: 1rem;
    position: absolute;
    top: 0;
    width: 100%;
}

.tle:hover::before {
    background-color: var(--overlay-hover);
}



/**
 * demo styles
 */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    --shell-width: 1600px;
    
    background-color: ghostwhite;
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
    padding: 1rem;
}

button {
    border: 0;
    cursor: pointer;
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: left;
}

code {
    color: deeppink;
    font-family: SFMono-Regular, Menlo, Monaco, monospace;
    font-weight: 400;
}

h1 {
    font-size: 2.75rem;
    margin: 0;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1.25rem;
    text-transform: uppercase;
}

.shell {
    max-width: var(--shell-width);
}

.intro {
    margin-bottom: 3rem;
}

.heading {
    font-weight: 500;
    margin-bottom: 0.25em;
    margin-top: 0;
}

.subheading {
    color: darkslategray;
    font-size: 1.25rem;
}

.examples {
    display: grid;
    grid-gap: 0;
    grid-row-gap: 3rem;
    grid-template-columns: 360px 1fr 1fr;
    
    @media (min-width: 1140px) {
         grid-template-columns: 480px 1fr 1fr;
    }
}

.new {
    grid-column-start: 2;
}

.old {
    grid-column-start: 3;
}

.descriptor {
    padding-right: 2rem;
}

hr {
    margin: 2rem;
    border: 0;
}

              
            
!

JS

              
                
              
            
!
999px

Console