Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Is it possible to add a black outline around each character in text?

Tags:

css

I would like to add a black outline around each character, so if the font id on the same color background as the foreground it is still readable.

Can this be done in CSS with or without browser specific css?

like image 405
Justin808 Avatar asked Jan 23 '11 08:01

Justin808


People also ask

How do you add a black outline to text in CSS?

Sometimes you need an outline around your text. A recent project required me to place white text on a multicolored image background, so giving that text a black outline was important for readability. Should be easy, right? Just declare text-outline: 1px black solid; , and we're done.

Can text have a border CSS?

In CSS, we may apply borders to a font by using the text-stroke property on a text. To access the feature, we must use the webkit prefix before the text-stroke attribute. However, it is only compatible with web-kit-based browsers such as Safari and Chrome.


2 Answers

You can simulate it with the CSS 2.1 text-shadow property:

p {     color: #fff;     text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000; } 

This is, of course, not supported in IE9 and below. See: http://www.jsfiddle.net/yijiang/UCjgg/ for a simple demo.

like image 123
Yi Jiang Avatar answered Sep 17 '22 13:09

Yi Jiang


There is an explicit -webkit way to add text outline, which is with -text-stroke. This is the experimental implementation of the equivalent standards track proposal (called text-outline in the CSS3 spec docs).

like image 41
Michael Mullany Avatar answered Sep 17 '22 13:09

Michael Mullany