text-stroke

text-stroke is an experimental property that provides text decoration options similar to those found in Adobe Illustrator or other vector drawing applications. It is not currently included in any W3C or WHATWG specification. As of June 2013, it is only implemented behind a -webkit vendor prefix, though future versions of Firefox and Internet Explorer may support the property (likely under their own prefixes).

mark {
    -webkit-text-stroke: 2px red;
}

The text-stroke property is actually shorthand for two other properties:

  1. text-stroke-width, which takes unit value (1px, 0.125em, 4in, etcetera) and describes the thickness of the stroke effect.
  2. text-stroke-color, which takes a color value (hex, rgb/rgba, hsl/hsla, etcetera).

text-stroke also has a companion property, text-fill-color, which will override the color property, allowing for a graceful fallback to a different text color in browsers that do not support text-stroke.

Check out this Pen!

Points of Interest

  • The stroke drawn by text-stroke is aligned to the center of the text shape (as is the default in Adobe Illustrator), and there is currently no option to set the alignment to the inside or outside of the shape. Unfortunately this makes it much less usable, as no matter what now the stroke interferes with the shape of the letter destroying the original type designers intent. A setting would be ideal, but if we had to pick one, outside stroke would have been much more useful.
  • in Webkit, text-stroke is animatable with CSS Transitions and Animations – but only the stroke color, not the stroke width.
  • A more browser-compatible (and arguably robust) stand-in for the text-stroke effect is using text-shadow, which is outlined in this CSS-Tricks article.

Other Resources

Browser Support

Chrome Safari Firefox Opera IE Android iOS
-webkit- -webkit- 21 15+ 10 Complicated -webkit-

A note on browser support: The table above is a summary of overall browser support for text-stroke – the truth is much more complicated (for example, Android supported the property in versions 2.1-2.3, then removed support in 3.0, before restoring support in 4.0). For the full browser support table, visit caniuse.com/text-stroke.

Comments

  1. User Avatar
    dsv
    Permalink to comment#

    TEST

  2. User Avatar
    sahin erbay
    Permalink to comment#

    nice tricks thanks

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag