PROWAREtech








CSS: Add Stroke to Text - How to Outline Text
How to outline text by adding stroke using only CSS; compatible with all browsers including IE11.
The following block of CSS code is compatible with all browsers including Internet Explorer 11.
Because this is not a true stroke, the font family must be carefully chosen.
Stroked Text:
h1 {
color: white;
font-family: sans-serif;
letter-spacing: 2px;
text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black;
}
The following code creates a better stroke with newer browsers, like Chrome, Firefox and Edge, but falls back to support older browsers like IE11.
Stroked Text:
h1 {
color: white;
font-family: sans-serif;
letter-spacing: 2px;
text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black;
}
@supports (-webkit-text-stroke-width: 1px) {
h1 {
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: black;
text-shadow: none;
}
}
Here is an entire HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stroke</title>
<style>
h1 {
color: white;
font-family: sans-serif;
letter-spacing: 2px;
text-shadow: -1px -1px 0 black, 1px -1px 0 black, -1px 1px 0 black, 1px 1px 0 black;
}
@supports (-webkit-text-stroke-width: 1px) {
h1 {
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: black;
text-shadow: none;
}
}
</style>
</head>
<body>
<h1>Acme XXX, Inc</h1>
</body>
</html>
Comment