Propiedad text-stroke

La propiedad text-stroke establece el color y el grosor del contorno de los caracteres de texto o su trazo. Como valor, la propiedad debe establecer el grosor del trazo y, separado por un espacio, el color del trazo.

Sintaxis

cssselector {
  text-stroke: grosor-del-trazo y su-color;
}

Ejemplo básico

Contorno de texto simple:

html<div class="stroked-text">
  Lorem ipsum dolor sit amet
</div>
css.stroked-text {
  font-size: 48px;
  font-weight: bold;
  -webkit-text-stroke: 2px red;
  text-stroke: 2px red;
}

Результат:

Solo contorno

Ahora hagamos que el color del texto coincida con el color de fondo (en nuestro caso, blanco). Como resultado, solo quedará el contorno:

html<div class="stroked-text">
  Lorem ipsum dolor sit amet
</div>
css.stroked-text {
  font-size: 48px;
  font-weight: bold;
  color: white;
  -webkit-text-stroke: 2px black;
  text-stroke: 2px black;
}

Результат:

Contorno con gradiente

Hagamos un contorno degradado usando la propiedad background-clip:

html<div class="gradient-stroke">
  Lorem ipsum dolor sit amet
</div>
css.gradient-stroke {
  font-size: 42px;
  font-weight: bold;
  background: linear-gradient(to right, #ff8a00, #e52e71);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px #333;
  text-stroke: 1px #333;
}

Результат:

Contorno múltiple

Efecto de doble contorno usando text-shadow:

html<div class="double-stroke">
  Lorem ipsum dolor sit amet
</div>
css.double-stroke {
  font-size: 40px;
  color: white;
  -webkit-text-stroke: 3px #000;
  text-stroke: 3px #000;
  text-shadow: 
    0 0 5px #000,
    0 0 10px #000;
}

Результат:

Contorno animado

Añadamos una animación que cambie el contorno:

html<div class="animated-stroke">
  Lorem ipsum dolor sit amet
</div>
css.animated-stroke {
  font-size: 38px;
  color: white;
  -webkit-text-stroke: 1px #ff0000;
  text-stroke: 1px #ff0000;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
  50% { -webkit-text-stroke: 3px #ff0000; text-stroke: 3px #ff0000; }
  100% { -webkit-text-stroke: 1px #ff0000; text-stroke: 1px #ff0000; }
}

Результат:

Ver también