- 12 min read
- CSS,
Recommendations,
Salvage
I’m hoping you had been in a local to yelp time getting conscious of the suggestions we worn to make tooltips in Share 1 of this rapid two-parter. Collectively, we had been in a local to make a flexible tooltip pattern that supports pretty a pair of instructions, positioning, and coloration with out collectively with any complexity in anyway to the HTML.
We leveraged the CSS border-image property in step with one other article I wrote while applying suave clip-path tricks to maintain watch over the tooltip’s tail. In case you haven’t checked out that article or the first section of this sequence, please create on story of we’re leaping straight into things as of late, and the context could be helpful.
To this level, we’ve appeared at tooltip shapes with triangular tails with the probability to have rounded corners and gradient coloration. Sure, we had been in a local to create a mode of things but there are a lot of pretty a pair of — and more attention-grabbing — shapes we can carry out. That’s what we’re doing listed here. We can take care of circumstances the set a tooltip could per chance also have a border and pretty a pair of tail shapes, soundless with the smallest amount of markup and most amount of flexibility.
Sooner than we initiating up, I want to remind you that I’ve created a mountainous sequence of 100 tooltip shapes. I said in Share 1 that we would carry out all of them in these two articles. We lined about half of them in Share 1, so let’s wrap things up here in Share 2.
The HTML
Identical as sooner than!
Your text content goes here
That’s the merit of what we’re making: We can make many, many pretty a pair of tooltips out of the same single HTML component with out altering a thing.
In conjunction with a border to the tooltips we made in Share 1 is sophisticated. We want the border to wrap around both the necessary component and the tail in a continuous model so that the mixed form is seamless. Let’s initiating up with the first straightforward form we created in Share 1 the expend of only two CSS properties:
.tooltip {
/* tail dimensions */
--b: 2em; /* base */
--h: 1em; /* height*/
/* tail position */
--p: 50%;
border-image: fill 0 // var(--h)
conic-gradient(#CC333F 0 0);
clip-path:
polygon(0 100%, 0 0,100% 0, 100% 100%,
min(100%, var(--p) + var(--b) / 2) 100%,
var(--p) calc(100% + var(--h)),
max(0%, var(--p) - var(--b) / 2) 100%);
}
Here’s the demo. You should per chance be in a local to expend the vary slider to search how flexible it’s a long way to replace the tail space by updating the --p variable.
Survey the Pen [Fixing the overflow issue](https://codepen.io/smashingmag/pen/mdoLRVr) by Temani Afif.
The border property is no longer an risk here as a long way as collectively with borders to our tooltip. It won’t work. As a replace, now we favor to expend a pseudo-component that successfully traces the form of the necessary component, then makes it smaller.
Let’s initiating up with the next code:
.tooltip {
/* tail dimensions */
--b: 2em; /* base */
--h: 1em; /* height*/
/* tail position */
--p: 50%;
border-image: fill 0 // var(--h)
conic-gradient(#5e412f 0 0); /* the border color */
clip-path:
polygon(0 100%, 0 0, 100% 0, 100% 100%,
min(100%, var(--p) + var(--b) / 2) 100%,
var(--p) calc(100% + var(--h)),
max(0%, var(--p) - var(--b) / 2) 100%);
position: relative;
z-index: 0;
}
.tooltip:before {
content: "";
position: absolute;
inset: 8px; /* border thickness */
border-image: fill 0 // var(--h)
conic-gradient(#CC333F 0 0); /* background color */
clip-path: inherit;
}
The pseudo-component uses the same border-image and clip-path property values as the necessary component. The inset property decreases its dimension from there.
Survey the Pen [Adding border to the tooltip](https://codepen.io/smashingmag/pen/yLwjqQw) by Temani Afif.
I’d disclose this appears to be like mountainous on the initiating witness. But things gain funky after we initiating up adjusting the tail space. This is since the 2 clip-path shapes are no longer aligned for the reason that pseudo-component is overlaying a smaller bid than the necessary component. We favor to preserve the left and moral values equal to 0 in expose to repair this:
inset: 8px 0;
And let’s adjust the border-image to diminish the scale of the colored bid from the perimeters:
border-image: fill 0 / 0 8px / var(--h) 0
conic-gradient(#CC333F 0 0); /* background color */
Sure, it’s the border-image trickery from sooner than! So, In case you haven’t already, please read my article about border-image to search how we arrived here.
Now things are taking a witness very moral:
Survey the Pen [Fixing the clip-path alignment](https://codepen.io/smashingmag/pen/mdoLGEx) by Temani Afif.
The two clip-path shapes are nicely aligned. The tooltip is virtually ideal. I disclose “virtually” on story of there could be a little enviornment with the border’s thickness. The thickness all the blueprint thru the tail form is a exiguous smaller than the one all the blueprint thru the component. In case you play with the tail dimensions, you’ll glimpse the inconsistency.

This doubtlessly is no longer that a mountainous deal in most circumstances. A pair of pixels aren’t a obvious visible enviornment, but that it’s also possible to deem whether or no longer it meets your wants. Me? I’m a perfectionist, so let’s are trying to repair this minor component even supposing the code will gain a exiguous more advanced.
We favor to create some math that requires trigonometric capabilities. Namely, now we favor to replace a pair of of the variables on story of we can no longer gain what we favor with the most up-to-date setup. In desire to the expend of the snide variable for the tail’s dimensions, I will maintain in mind an perspective. The 2nd variable that controls the high will live unchanged.

The relationship between the snide (--b) and the perspective (--a) is equal to B = 2*H*tan(A/2). We can expend this to update our existing code:
.tooltip {
/* tail dimensions */
--a: 90deg; /* angle */
--h: 1em; /* height */
--p: 50%; /* position */
--t: 5px; /* border thickness */
border-image: fill 0 // var(--h)
conic-gradient(#5e412f 0 0); /* the border color */
clip-path:
polygon(0 100%, 0 0, 100% 0, 100% 100%,
min(100%, var(--p) + var(--h) * tan(var(--a) / 2)) 100%,
var(--p) calc(100% + var(--h)),
max(0%, var(--p) - var(--h) * tan(var(--a) / 2)) 100%);
position: relative;
z-index: 0;
}
.tooltip:before {
content: "";
position: absolute;
inset: var(--t) 0;
border-image: fill 0 / 0 var(--t) / var(--h) 0
conic-gradient(#CC333F 0 0); /* the background color */
clip-path: inherit;
}
Nothing drastic has modified. We supplied a new variable to maintain watch over the border thickness (--t) and up to this level the clip-path property with the brand new variables that present an explanation for the tail’s dimensions.
Now, the total work could be accomplished on the pseudo-component’s clip-path property. This could per chance now no longer inherit the necessary component’s price, but it with out a doubt does desire a new price to gain the coolest border thickness all the blueprint thru the tail. I want to handbook clear of getting deep into the advanced math within the back of all of this, so here is the implementation:
clip-path:
polygon(0 100%, 0 0, 100% 0, 100% 100%,
min(100% - var(--t), var(--p) + var(--h)*tan(var(--a)/2) - var(--t)*tan(45deg - var(--a) / 4)) 100%,
var(--p) calc(100% + var(--h) + var(--t)*(1 - 1/sin(var(--a)/2))),
max(var(--t), var(--p) - var(--h)*tan(var(--a)/2) + var(--t)*tan(45deg - var(--a)/4)) 100%);
It appears to be like advanced on story of it’s a long way! You don’t indubitably favor to realise the formulas since all you will like to create is adjust a pair of variables to maintain watch over all the pieces.
Now, in a roundabout blueprint, our tooltip is ideal. Here is an interactive demo the set that it’s also possible to adjust the gap and the thickness. Don’t neglect to also play with the dimension of the tail as properly.
Survey the Pen [Tooltip with border and solid color](https://codepen.io/smashingmag/pen/zYbjeop) by Temani Afif.
Gradients And Rounded Corners
We learned in Share 1 that working with gradients the expend of this kind is stunning mountainous on story of we’re already supplying a gradient on the border-image property. All now we favor to create is contain the necessary component and tail with a real gradient in desire to a solid coloration.

Let’s pass on to the rounded corners. We can merely expend the code we created within the previous article. We replica the form the expend of a pseudo-component and blueprint a pair of adjustments for ideal alignment and a qualified border thickness.

The reason I’m no longer going into details for this one is to blueprint the level that you just don’t favor to be conscious the total many expend circumstances and code snippets by coronary heart. The blueprint is to realise the true ideas we’re the expend of to create the tooltips, esteem working with border-image, clip-path(), gradients, and math capabilities.
I’m capable of’t even be conscious most of the code I write after it’s accomplished, but it with out a doubt’s no enviornment since all I indubitably favor to create is copy and paste then adjust a pair of variables to gain the form I want. That’s the back of leveraging unusual CSS parts — they take care of most of the work for us.
I’d favor to create yet yet any other yelp with you, this time making a tooltip and not utilizing a contain but soundless with a tubby border all the blueprint thru the total form. To this level, we’ve been in a local to reuse most of the code we build collectively in Share 1, but we’re going to want new tricks to drag this one off.
The blueprint is to place a transparent background while affirming the border. We’ll initiating up with out rounded corners for the 2nd.

Survey how we’re going to be working with gradients once more? I could per chance also have worn a single coloration to blueprint a solid, single-coloration border, but I build a laborious conclude in there to picture the postulate. We’ll be in a local to make a long way more adaptations, attributable to this exiguous component, esteem the expend of more than one colours, pretty a pair of coloration stops, and even pretty a pair of sorts of gradients.
You’ll glimpse that the code appears to be like pretty straightforward:
.tooltip {
/* tail dimension */
--a: 90deg; /* angle */
--h: 1em; /* height */
--p: 50%; /* tail position */
--b: 7px; /* border thickness */
position: relative;
}
.tooltip:before {
content: "";
position: absolute;
inset: 0 0 calc(-1*var(--h));
clip-path: polygon( ... ); /* etc. */
background: linear-gradient(45deg, #cc333f 50%, #79bd9a 0); /* colors */
}
We’re the expend of pseudo component once more, this time with a clip-path to place the form. From there, we situation a linear-gradient() on the background.
I said the code “appears to be like” very straightforward. Structurally, optimistic. But I purposely build a placeholder clip-path price on story of that’s the sophisticated section. We wished to expend a 16-level polygon and math formulas, which if truth be told gave me mountainous complications.
That’s why I flip to my on-line generator in most circumstances. Finally, what’s the level of all americans spending hours trying to suss out which formulas to expend if math isn’t your thing? Would possibly per chance per chance well well as properly expend the instruments which could per chance be on hand to you! But picture how a lot higher it feels to expend these instruments when you understand the ideas which could per chance be working below the hood.
OK, let’s type out rounded corners:

For this one, we are going to rely on no longer one, but two pseudo-capabilities, :before and :after. One will make the rounded form, and the pretty a pair of will back as the tail.

The above figure illustrates the job for rising the rounded section with the :before pseudo-component. We first initiating up with a straightforward rectangular form that’s stuffed with a conic gradient containing three colours. Then, we masks the form so that the internal bid is transparent. After that, we expend a clip-path to cleave out a little section of the underside edge to yelp bid for the tail we’ll blueprint with the :after pseudo-component.
/* the main element */
.tooltip {
/* tail dimension */
--a: 90deg; /* angle */
--h: 1em; /* height */
--p: 50%; /* tail position */
--b: 7px; /* border thickness */
--r: 1.2em; /* the radius */
position: relative;
z-index: 0;
}
/* both pseudo-elements */
.tooltip:before,
.tooltip:after {
content: "";
background: conic-gradient(#4ECDC4 33%, #FA2A00 0 66%, #cf9d38 0); /* the coloration */
inset: 0;
position: absolute;
z-index: -1;
}
/* the rounded rectangle */
.tooltip:before {
background-size: 100% calc(100% + var(--h));
clip-path: polygon( ... );
mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
mask-composite: exclude;
padding: var(--b);
}
/* the tail */
.tooltip:after {
content: "";
position: absolute;
bottom: calc(-1 * var(--h));
clip-path: polygon( ... );
}
Over once more, the structure is no longer all that advanced and the clip-path price is the sophisticated section. As I said earlier, there’s indubitably no favor to gain deep into an clarification on it when we can expend the capabilities from an on-line generator to gain the true form we favor.
The new portion that is supplied in this code is the mask property. It uses the same methodology we lined in yet one other 4nds article I wrote. Please read that for the tubby context of how mask and mask-composite work collectively to magnificent the transparent bid. That’s the first section of your homework after finishing this article.
Stress-free Tail Shapes
We’ve lined stunning extraordinary each regarded as one of the most tooltips on hand in my sequence. The one ones now we have no longer particularly touched expend a mode of pretty a pair of shapes for the tooltip’s tail.
All of the tooltips we created in this sequence worn a straightforward triangle-shaped tail, which is a veteran tooltip pattern. Sure, we learned replace its dimensions and space, but what if we favor a lovely a pair of form of tooltip? Doubtless we favor one thing fancier or one thing that appears to be like more esteem a speech or belief bubble.

If the rounded corners within the final portion are the first section of your homework, then the next section is to establish out making these tail adaptations your self the expend of what now we have learned collectively in these two articles. You should per chance be in a local to continually salvage the code over at my sequence for reference and hints. And, leave a comment here when that it’s also possible to have any further questions — I’m gratified to back!
Conclusion
I’m hoping you enjoyed this exiguous sequence on story of I obvious had a blast writing it. I imply, look on the general things we finished in a lovely quick amount of bid: straightforward rectangular tooltips, rounded corners, pretty a pair of tail positions, solid and gradient backgrounds, a bunch of border alternatives, and in a roundabout blueprint, personalized shapes for the tail.
I doubtlessly went too a long way with what number of varieties of tooltips we could per chance also blueprint — there are 100 in total when you depend them up! However it goes to picture moral what number of potentialities there are, even when we’re continually the expend of the same single component within the HTML.
And, it’s mountainous apply to maintain in mind the general pretty a pair of expend circumstances and eventualities that it’s also possible to streak into when you desire a tooltip component. Protect these to your back pocket for when you want them, and expend my sequence as a reference, for inspiration, or as a initiating level to your have work!
Extra Reading On 4ndsMag
- “CSS Responsive Multi-Line Ribbon Shapes (Share 1),” Temani Afif
- “Art Course For The Web Using CSS Shapes,” Andrew Clarke
- “Take A Recent Explore At CSS Shapes,” Rachel Andrew
- “How To Animate Along A Course In CSS,” Preethi Sam
(gg, yk)