Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Unorthodox Tailwind
Lesson Plan
  1. Introduction
    1. Introduction
    2. What Tailwind brings to the table
    3. Tailwind: The Good and The Bad
    4. The First and Most Important Step
    5. Simple Unorthodox System
    6. The System I Use
  2. Tailwind Fundamentals
    1. Introduction
    2. Installing Tailwind
    3. Using Tailwind utilities
    4. Understanding Tailwind’s utility system
    5. Understanding Tailwind values
    6. Understanding Tailwind variants
  3. Unorthodox Fundamentals
    1. Introduction
    2. Making Simple Tailwind Utilities
    3. Components vs Utilities
    4. Specificity, Cascade, and CSS Layers
    5. Debugging Tailwind Styles
    6. Composable Utility System
    7. Create lots of components
  4. Layouts System
    1. Tailwind is great for layouts
    2. Four Types of Layouts
    3. Building Shell Layouts
    4. Building Macro Layouts
    5. Better Responsive Variants
    6. A collection of maximum widths
    7. A note on grid wrappers
    8. Working with sections
    9. Building Micro Layouts
    10. Positioning Layouts
  5. Typography System
    1. Introduction
    2. A system for using multiple typefaces
    3. Tailwind's font-size system
    4. Finding your font-size system
    5. My font-size system
    6. A simple responsive typography system
    7. The main body
    8. Vertical rhythm
  6. Theming System
    1. Introduction
    2. Tailwind's colour system
    3. The pigment system
    4. Tailwind's gradient system
    5. A friendlier gradient system
    6. Handling SVG fill and stroke
    7. Improving Tailwind's colour palette
    8. A simple way to theme
  7. Useful Tools
    1. Introduction
    2. Making functional utilities
    3. Custom variants
    4. Scaffolding tools
    5. Extending Tailwind
  8. Effects System
    1. Introduction
    2. Vertical text
    3. Strikethrough text
    4. Text stroke
    5. Highlighting text
    6. Nicer shadows
    7. Transitioning shadows
    8. Drop shadows
    9. Dark mode tricks
    10. Gradient borders
    11. More effects to explore
  9. Putting Everything Together
    1. The Unorthodox Tailwind process
    2. The 4 systems combined
    3. Create components liberally
    4. Advanced tips
    5. My CSS Structure
    6. A Cheatsheet
    7. Consolidating your thoughts
    8. Parting words

Gradient borders

5m:47s

It is not possible to create rounded gradient borders directly with the border property, so we have to resort to a few tricks.

There are generally three ways of doing it:

  1. Using a wrapper element
  2. Using background-clip
  3. Using a pseudo-element with a mask

The first one gives you an understanding of what’s going on. The second and third ones are generally what I use on a day-to-day basis.

Using a wrapper element

The idea here is simple.

  • First, you have the gradient on the outer element.
  • The outer element should have some padding (that acts as the border).
  • Then you need a background on the inner element
<!-- Here's a simple Tailwind version of this at work. -->
<div class="bg-linear-to-br from-purple-300 to-orange-500 p-[2px]">
<div class="bg-purple-50"></div>
</div>
/* Or CSS, if that's what you prefer */
.outer {
background-image: linear-gradient(
to bottom right,
var(--color-purple-300),
var(--color-orange-300)
);
}
.inner {
background: white;
}
Some content here

Using background-clip

background-clip uses the same concept as above on the same element.

The difference is we’re going to use padding-box for the inner background and border-box for the outer background. This way, we can still use padding to create whitespace for the “inner element”.

.card {
padding: 1rem;
border: 2px solid transparent;
background-image:
linear-gradient(to bottom, white, white),
linear-gradient(
to bottom right,
var(--color-purple-300),
var(--color-orange-300)
);
background-origin: padding-box, border-box;
background-clip: padding-box, border-box;
}

Some content here

The background-clip method works for most cases — and can be extended to include Temani Afif’s highly advanced method of generating tooltip arrows to achieve the following effect.

Top arrow
Linear gradient

Right arrow
Radial gradient

Bottom arrow
Conic Gradient

Left arrow
Radial Gradient

The code to create everything here is way too complicated to show, but the idea here isn’t to inundate you with code. It is to show you that once you have grasped an idea, you can put it into a utility (or a class), and you can use it easily from that point onwards.

I managed to put this into a bezel utility. You can find it in Splendid Effects.

When using bezel, you just need to define:

  1. The inner background color or inner gradient.
  2. The outer gradient.

And if you want an arrow, you use the bezel-arrow-*.

.card {
/* Use both bezel-arrow and arrow-left utilities */
@apply bezel-arrow-left;
/* Use radial gradient for both inner and outer gradients */
@apply inner-radial;
@apply outer-radial;
--bg-color: var(--color-neutral-950); /* Base card color */
--border-width: 2px;
/* Defining the inner and outer gradients */
--gradient-shape: ellipse;
--gradient-position: 0 50%;
--inner-size: 120% 120%;
--outer-size: 140% 140%;
--inner-stops: rgb(34 197 94 / 0.3), transparent 100%;
--outer-stops: rgb(34 197 94 / 0.95), transparent 100%;
/* Defining the arrow position */
--arrow-position: 50%;
}

Right arrow
Radial gradient

Using a pseudo element

The background-clip method works fabulously, but it does not allow you to create an inner background that is transparent.

If you want the inner element to be translucent (to add a frosted-glass effect or simply let transparency shine through), you need to put the outer gradient on a pseudo-element. Then you apply a mask so the pseudo-element only colours the gradient.

I know this sounds really complex, but the whole idea has been captured in the paragraph above. If you want a step-by-step tutorial, Kevin Powell has one, and I highly recommend you check it out!

The long story short, the utility can look something like this.

@utility bezel-frost {
--frost: 16px;
position: relative;
border: var(--border-width) var(--border-style) transparent;
border-radius: var(--radius);
backdrop-filter: blur(var(--frost));
&::before {
content: '';
pointer-events: none;
position: absolute;
inset: calc(-1 * var(--b));
border-width: var(--border-width);
border-radius: inherit;
background: var(--outer-gradient, none);
mask:
linear-gradient(#000 0 0) content-box,
linear-gradient(#000 0 0);
mask-composite: exclude;
}
}

Then we can use bezel-frost to build a gradient frame with a frosted glass content area!

.card {
/* Use the utility */
@apply bezel-frost;
/* Define the gradients */
@apply gradient;
@apply outer-linear;
--gradient-angle: to bottom right;
--gradient: oklch(100% 0.3 250deg / 50%), transparent 100%;
--outer-stops: oklch(100% 0.3 250deg / 80%), transparent 100%;
}

You have to be mindful about contrast when doing this!

That’s it for this lesson!