Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Stroke (-webkit-text-stroke) css Problem

I am working on a personal project with NextJs and TailwindCSS.

upon finishing the project I used a private navigator to see my progress, but it seems that the stroke is not working as it should, I encounter this in all browsers except Chrome.

Here is what i get :

enter image description here

Here is the desired behavior :

enter image description here

Code:

<div className="outline-title text-white pb-2 text-5xl font-bold text-center mb-12 mt-8">
      Values &amp; Process
</div>

Css:

.outline-title {
  color: rgba(0, 0, 0, 0);
  -webkit-text-stroke: 2px black;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

Can someone explain or help to fix this.

Browser compatibility: enter image description here

like image 430
agoumi Avatar asked Sep 20 '21 11:09

agoumi


People also ask

What is WebKit text-stroke?

The -webkit-text-stroke CSS property specifies the width and color of strokes for text characters. This is a shorthand property for the longhand properties -webkit-text-stroke-width and -webkit-text-stroke-color .

Can I use WebKit text-stroke color?

WebKit now supports stroking of text via CSS. In existing Web pages today, the glyphs that are drawn for text are always filled with a single color, specified by the color CSS property. Sometimes authors may want to stroke the edges of the glyphs with one color, and fill with a different color.

What is the color of stroke in CSS?

The stroke property can accept any CSS color value. Named colors — orange Hex colors — #FF9E2C RGB and RGBa colors — rgb(255, 158, 44) and rgba(255, 158, 44, .5) HSL and HSLa colors — hsl(32, 100%, 59%) and hsla(32, 100%, 59%, .5)

What is CSS outline text stroke?

The CSS outline text stroke is by a pro-Codepen user, Viljami Salminen, and It is written using CSS and HTML. The font size and color are large and quickly grab the attention of all the people who come across it. Therefore, it is a great choice for advertisement boards or posters.

How do I use the stroke property in CSS?

The stroke property in CSS is for adding a border to SVG shapes. This will override a presentation attribute <path stroke="#fff" ... /> This will not override an inline style e.g. <path style="stroke: #fff;" ... /> The stroke property can accept any CSS color value. RGB and RGBa colors — rgb (255, 158, 44) and rgba (255, 158, 44, .5)

Is it possible to make a text stroke in Photoshop?

I'm used to Photoshop. I meant a text stroke as in a text outline, not a strikethrough. Sorry, haha. Hmm, I guess you can use Jinu's link and achieve the effect. There is other way to make your text strike using text-decoration:line-through and apply that at your css.


Video Answer


3 Answers

TL:DR
the text-shadow as proposed by @Satheesh Kumar is still the most reliable solution.

As @diopside: pointed out this rendering behaviour is related to variable fonts.
The reason for these inner outlines is based on the structure of some variable fonts.

'Traditional' fonts (so before variable fonts) – only contained an outline shape and maybe a counter shape e.g the cut out inner 'hole' of a lowercase e glyph.

Otherwise you would have encountered undesired even/odd issues resulting in excluded shapes caused by overlapping path areas.

Applying this construction method, you will never see any overlap of shapes. You could imagine them as rather 'merged down' compound paths. Counter shapes like the aforementioned hole were based on simple rules like a counterclockwise path directions – btw. you might still encounter this concept in svg-clipping paths - not perfectly rendering in some browsers).

enter image description here

Variable fonts however allow a segemented/overlapping construction of glyphs/characters to facilitate the interpolation between different font weights and widths.

Obviously webkit-text-stroke outlines the exact bézier anatomy of a glyph/character resulting in undesired outlines for every glyph component.

This is not per se an issue of variable fonts, since weight and width interpolations has been used in type design for at least 25 years. So this quirky rendering issue depends on the used font – a lot of classic/older fonts compiled to the newer variable font format will still rely on the old school aproach (avoiding any overlap).

like image 174
herrstrietzel Avatar answered Oct 19 '22 20:10

herrstrietzel


Due to browser compatibility -webkit-text-stroke will not support in a few browsers. You can achieve the outline effect by using shadow.

Hope this works!

.outline-title {
font-family: sans-serif;
   color: white;
   text-shadow:
       1px 1px 0 #000,
     -1px -1px 0 #000,  
      1px -1px 0 #000,
      -1px 1px 0 #000,
       1px 1px 0 #000;
      font-size: 50px;
}
<div class="outline-title text-white pb-2 text-5xl font-bold text-center mb-12 mt-8">
      Values &amp; Process
</div>

---- UPDATE ---

-webkit-text-stroke | MDN Web Docs

like image 4
Satheesh Kumar Avatar answered Oct 19 '22 20:10

Satheesh Kumar


Its a known issue when using variable-width fonts in certain browsers. As to the why, I have no idea

https://github.com/rsms/inter/issues/292#issuecomment-674993644

like image 2
diopside Avatar answered Oct 19 '22 19:10

diopside