I need the text to have a black border.
I tried this,
<div className="font-bold text-2xl text-white outline-4">
Hello
</div>
But it doesn't seem put a border to the text.
I need the text to have a black border.
I tried this,
<div className="font-bold text-2xl text-white outline-4">
Hello
</div>
But it doesn't seem put a border to the text.
I found a custom tailwind drop shadow yields the best result:
drop-shadow-[0_1.2px_1.2px_rgba(0,0,0,0.8)]
Just adjust the pixel values and intensity, and use as standard tailwind attribute.
This even works on svgs.
Tailwind does not support it yet out of the box, you need to customize your CSS. Either use the experimental text-stroke property, which is not very well supported so I don't recommend it, maybe later, or:
Use text-shadow that works pretty well.
h1 {
color: white;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
}
I had this issue as well, but I did not feel that the existing answers gave me a solution that follows Tailwind's utility-first approach.
Instead of creating custom css for a specific element, instead we should create a new tailwind utility class for this purpose.
To do that we alter the main.css tailwind file that holds our configuration and use the @layer base selector.
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
.font-outline-2 {
-webkit-text-stroke: 2px black;
}
.font-outline-4 {
-webkit-text-stroke: 4px black;
}
}
This allows us to reference our new class anywhere in our project alongside default tailwind classes, and it additionally works with Tailwind state selectors.
<h1 class="text-2xl font-bold font-outline-2 hover:font-outline-4">
Works as expected
</h1>