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 id="app">
    
    <header>
        <h1>Tailwind Outside Rounded Corners</h1>
        <p>Simple outside corners using a <strong><code>radial mask</code></strong>, allowing the background to be
            exposed without any need for fake background colors. <strong>
            Even works with Gradients/Images!</strong></p>
        <p>Also <a href="https://github.com/simeydotme/tailwind-rounded-out" target="_blank">available as a Tailwind Plugin</a></p>
    </header>

    <section>
        <div class="top">
            <div class="tab selected">
                simple
            </div>
            <div class="tab">
                outside
            </div>
            <div class="tab">
                rounded
            </div>
            <div class="tab">
                corners
            </div>
        </div>
        <div class="bottom">
            <div class="tab selected">
                simple
            </div>
            <div class="tab">
                outside
            </div>
            <div class="tab">
                rounded
            </div>
            <div class="tab">
                corners
            </div>
        </div>
    </section>
    
    <div class="inputs">
        <input type="color" value="#ffffff" id="fg">
        <input type="color" value="#1d1d29" id="bg">
        <button id="gradient"></button>
        <input type="range" id="size" min=4 max=32 value=16>
    </div>
    
</main>

<!-- 













    social icons
-->
<a class="social-icon codepen" href="https://codepen.io/simeydotme" title="view my codepens">
    Made by Simey
</a>

<a class="social-icon twitter" href="https://twitter.com/simeydotme">
    <svg viewBox="0 0 24 24">
        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
        <path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z"></path>
    </svg>
</a>
<a class="social-icon github" href="https://github.com/simeydotme">
    <svg viewBox="0 0 24 24">
        <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
        <path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path>
    </svg>
</a>
              
            
!

CSS

              
                /*
    comments / explanations below 👇
*/

#app {
    --radius: 16px;
    --height: max(48px, calc( var(--radius) * 2 ));
}

.tab {
    
    height: var(--height);
    border-radius: var(--radius) var(--radius) 0 0;
        
    /*
        these --height and --radius variables are not explicitly needed
        for the effect, they could be hard-set into the css if you know you always
        want your rounded corners to be the same size. I've used variables here so 
        you can edit them and see the dynamic change of the corners easily!
    */
    
    position: relative; /* relative so we can position the corners */
}

.tab::after,
.tab::before {
    
    /* 
        here's the magic.
        - I set a background color of inherit to the :before and :after
            = so it perfectly matches the parent it's set on
        - I set a radial mask to cover the :before and :after perfectly
            = with a little 0.25px buffer for sub-pixel anti-aliasing
        - I make the mask 200% to cover the other edges of the :before and :after
        - Then I position the mask in the bottom corner 
    */
    
    aspect-ratio: 1;
    width: var(--radius, 20px); 
    /* the width of the :before/:after is the outer corner size */
    background: inherit;
    mask-image: radial-gradient(100% 100% at center, transparent calc(50% - 0.25px), black calc(50% + 0.25px));
    /* the mask is flexible and scales with the width, no need to edit it */
    mask-size: 200% 200%;
    mask-position: 100% 100%;
    pointer-events: none;
        
    /*
        this is just normal positioning of the :before and :after to
        get them set at the bottom left of the parent container
    */
    content: "";
    position: absolute;
    bottom: 0;
    left: calc( var(--radius, 20px) * -1);
}
.tab::after {
    /*
        and for the other side, I simply flip the whole box horizontally
        and position it at the end of the parent container
    */
    scale: -1 1;
    left: auto;
    right: calc( var(--radius, 20px) * -1);
}

/*
    just some extra styling for the top-tabs to show
    the outside corners can be easily set on top (or sides)
*/
.top .tab {
    border-radius: 0 0 var(--radius) var(--radius);
}
.top .tab::before,
.top .tab::after {
    bottom: auto;
    top: 0;
    scale: 1 -1;
}
.top .tab::after {
    bottom: auto;
    top: 0;
    scale: -1 -1;
}


/* 






not important for the effect, just for demo purpose 






*/

:root {
    --h: 240;
    --s: 18%;
    --light: hsl(var(--h), var(--s), 95%);
    --dark: hsl(var(--h), var(--s), 15%);
    --fg: var(--light);
    --bg: var(--dark);
    --grad: url("data:image/svg+xml,%3Csvg viewBox='0 0 0 0' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"), radial-gradient(circle at 68% 1%, hsla(253, 66%, 75%, 1) 7%, transparent 61%), radial-gradient(circle at 1% 48%, hsla(226, 66%, 63%, 1) 13%, transparent 54%), radial-gradient(circle at 58% 29%, hsla(359, 63%, 67%, 1) 19%, transparent 81%), radial-gradient(circle at 83% 79%, hsla(181, 88%, 59%, 1) 15%, transparent 61%), radial-gradient(circle at 85% 56%, hsla(293, 91%, 54%, 1) 0%, transparent 78%), radial-gradient(circle at 20% 43%, hsla(293, 89%, 59%, 1) 8%, transparent 55%), radial-gradient(circle at 63% 14%, hsla(197, 99%, 92%, 1) 9%, transparent 69%), radial-gradient(circle at 51% 27%, hsla(251, 96%, 90%, 1) 4%, transparent 50%), radial-gradient(circle at 26% 50%, hsla(270, 63%, 55%, 1) 20%, transparent 71%), radial-gradient(circle at 65% 83%, hsla(278, 99%, 97%, 1) 2%, transparent 90%);
    /*
    
        I'm only setting colors with variables here so that I can
        easily change them with the color inputs and javascript in the
        demo to demonstrate the flexibility.
    
        The variables are not needed for the effect!
    
    */
}

section {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    resize: horizontal;
    background: var(--bg);
    background-image: var(--img, var(--grad));
    background-blend-mode: overlay, normal, normal, normal, normal, normal, normal, normal, normal, normal, normal;
    background-size: cover;
    border-radius: 12px;
    padding-inline: 2em;
    min-height: 200px;
}
section > div {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 2px;
}
section > div.top {
    align-items: flex-start;
}

.tab:not(section) {
    min-width: 3em;
    padding-inline: 2.5em;
    transition: all 0.25s ease;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    
    background-color: var(--fg);
    color: var(--bg);
    color: color-mix(in hsl, var(--fg), var(--bg) 50%);
}

.tab.selected {
    z-index: 2;
    height: calc(var(--height) + 4px);
}

.tab {
    background-color: color-mix(in hsl, var(--fg), var(--bg) 30%);
    &:hover {
       background-color: color-mix(in hsl, var(--fg), var(--bg) 20%);
        z-index: 1;
    }
}

.inputs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

#app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: max-content 200px 120px;
    max-width: 600px;
    margin: auto;
    place-content: center;
    row-gap: 2em;
    text-align: center;
}


html, body {
    display: grid;
    grid-template: 1fr / 1fr;
    min-height: 100%;
    justify-content: center;
    align-items: center;
    background: var(--bg);
}

button {
    height: 2.5em;
    border: 6px solid white;
    background: var(--grad);
    border-radius: 100px;
    &:hover,
    &:focus {
        box-shadow: none;
        border-color: white;
    }
}

input[type=color] {
    max-width: 76px!important;
}

input[type=range] {
    --bg: var(--light);
    --fg: var(--dark);
}

header {
    color: var(--light);
    text-wrap: balance;
}

header p {
    color: hsl(var(--h), var(--s), 60%);
}

header strong {
    color: hsl(var(--h), var(--s), 90%);
}

#app {
  --bor: hsl(var(--h), var(--s), 85%);
  --bg: var(--dark);
  --fg: var(--light);
  --b: hsla(var(--h), var(--s), 100%, 1);
  --svg: var(--fg);
}
              
            
!

JS

              
                const $app = document.querySelector("#app");
const $tabs = document.querySelectorAll(".tab");
const $fg = document.querySelector("#fg");
const $bg = document.querySelector("#bg");
const $g = document.querySelector("#gradient");
const $range = document.querySelector("#size");

$fg.addEventListener('input', (e) => {
    $app.style.setProperty('--fg', e.target.value);
});

$bg.addEventListener('input', (e) => {
    $app.style.setProperty('--bg', e.target.value);
});

$bg.addEventListener('click', (e) => {
    $app.style.setProperty('--img', 'none');
});

$g.addEventListener('click', (e) => {
    $app.style.setProperty('--img', 'var(--grad)');
});

$tabs.forEach((t) => {
    t.addEventListener('click', () => {
        $tabs.forEach( tt => {
            tt.classList.remove("selected");
        })
        t.classList.add("selected");
    })
})

$range.addEventListener('input', (e) => {
    $app.style.setProperty('--radius', e.target.value + 'px');
});
              
            
!
999px

Console