Last updated on

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 anyW3C 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 colorproperty, allowing for a graceful fallback to a different text color in browsers that do not supporttext-stroke.

<h1>A header with attitude.</h1>
body {
  padding: 0 0 0 3em;
  background: whitesmoke;
}

h1 {
  font-size: 4em;
  -webkit-text-stroke: 3px darkgrey;
  -webkit-text-fill-color: white;
  -webkit-animation: fill 0.5s infinite alternate;
}

@-webkit-keyframes fill {
  from { -webkit-text-fill-color: steelblue; }
  to { -webkit-text-fill-color: slategrey; }
}

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.

Browser Support

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

Leave a Reply

Your email address will not be published. Required fields are marked *