Skip to content

4. Tipografía y Texto

La tipografía es uno de los aspectos más importantes del diseño web. Una buena tipografía mejora la legibilidad, la jerarquía visual y la experiencia del usuario.


🔤 Propiedad font-family y tipos de fuente

Section titled “🔤 Propiedad font-family y tipos de fuente”

La propiedad font-family define qué fuente se usará para mostrar el texto.

/* Sintaxis: font-family: fuente1, fuente2, tipo-genérico; */
.elemento {
font-family: Arial, Helvetica, sans-serif;
}
/* Sans-serif - Sin remates (modernas, limpias) */
.texto-sans {
font-family: Arial, Helvetica, sans-serif;
}
/* Fuentes sans-serif comunes */
font-family: Arial, sans-serif;
font-family: Helvetica, sans-serif;
font-family: Verdana, sans-serif;
font-family: 'Segoe UI', Tahoma, sans-serif;
font-family: 'Trebuchet MS', sans-serif;
font-family: 'Lucida Sans', sans-serif;

✅ Uso recomendado:

  • Interfaces de usuario
  • Texto en pantalla
  • Sitios web modernos
  • Contenido digital

Ejemplo: Este es un texto sans-serif (sin remates)

Stack de fuentes del sistema (System Font Stack)

Section titled “Stack de fuentes del sistema (System Font Stack)”

Usa las fuentes nativas del sistema operativo para mejor rendimiento.

/* Stack moderno multiplataforma */
body {
font-family:
-apple-system, /* macOS y iOS (San Francisco) */
BlinkMacSystemFont, /* macOS Chrome */
'Segoe UI', /* Windows */
Roboto, /* Android */
'Helvetica Neue', /* macOS anterior */
Arial, /* Fallback universal */
sans-serif; /* Genérico */
}
/* Stack para código */
code, pre {
font-family:
'SF Mono', /* macOS */
Monaco, /* macOS anterior */
Consolas, /* Windows */
'Liberation Mono', /* Linux */
'Courier New', /* Fallback */
monospace; /* Genérico */
}
/* ✅ Correcto: Comillas para nombres con espacios */
.elemento {
font-family: 'Times New Roman', Times, serif;
font-family: 'Segoe UI', Tahoma, sans-serif;
font-family: 'Comic Sans MS', cursive;
}
/* ❌ Incorrecto: Sin comillas */
.elemento {
font-family: Times New Roman, serif; /* Error de sintaxis */
}
/* ✅ Nombres sin espacios no necesitan comillas */
.elemento {
font-family: Arial, Helvetica, sans-serif;
font-family: Georgia, serif;
}

Define el tamaño del texto.

/* Diferentes formas de definir font-size */
.elemento {
font-size: 16px; /* Píxeles (fijo) */
font-size: 1rem; /* Relativo a <html> */
font-size: 1.2em; /* Relativo al padre */
font-size: 100%; /* Porcentaje del padre */
font-size: larger; /* Palabras clave */
}
/* Sistema de tamaños consistente */
:root {
font-size: 16px; /* Base */
}
.texto-xs { font-size: 0.75rem; } /* 12px */
.texto-sm { font-size: 0.875rem; } /* 14px */
.texto-base { font-size: 1rem; } /* 16px */
.texto-lg { font-size: 1.125rem; } /* 18px */
.texto-xl { font-size: 1.25rem; } /* 20px */
.texto-2xl { font-size: 1.5rem; } /* 24px */
.texto-3xl { font-size: 1.875rem; } /* 30px */
.texto-4xl { font-size: 2.25rem; } /* 36px */
.texto-5xl { font-size: 3rem; } /* 48px */
.texto-6xl { font-size: 3.75rem; } /* 60px */
.texto-7xl { font-size: 4.5rem; } /* 72px */

Define el grosor de los caracteres.

/* Valores numéricos (100-900) */
.elemento {
font-weight: 100; /* Thin */
font-weight: 200; /* Extra Light */
font-weight: 300; /* Light */
font-weight: 400; /* Normal (default) */
font-weight: 500; /* Medium */
font-weight: 600; /* Semi Bold */
font-weight: 700; /* Bold */
font-weight: 800; /* Extra Bold */
font-weight: 900; /* Black */
}
/* Palabras clave */
.elemento {
font-weight: normal; /* = 400 */
font-weight: bold; /* = 700 */
font-weight: lighter; /* Más ligero que el padre */
font-weight: bolder; /* Más grueso que el padre */
}
/* Jerarquía con pesos */
h1, h2 {
font-weight: 700; /* Bold para títulos principales */
}
h3, h4 {
font-weight: 600; /* Semi-bold para subtítulos */
}
p {
font-weight: 400; /* Normal para texto */
}
strong, b {
font-weight: 700; /* Bold para énfasis */
}
.texto-ligero {
font-weight: 300; /* Light para texto secundario */
}
.texto-destacado {
font-weight: 600; /* Semi-bold para destacar */
}

Define si el texto es normal, cursiva u oblicuo.

/* Valores de font-style */
.elemento {
font-style: normal; /* Normal (default) */
font-style: italic; /* Cursiva (itálica) */
font-style: oblique; /* Oblicua (inclinada) */
}
/* Cursiva para énfasis */
em, i {
font-style: italic;
}
/* Citas en cursiva */
blockquote {
font-style: italic;
border-left: 4px solid #ddd;
padding-left: 1rem;
color: #666;
}
/* Términos técnicos */
.termino {
font-style: italic;
color: #2c3e50;
}
/* Resetear cursiva */
.no-cursiva {
font-style: normal;
}

Combina múltiples propiedades de fuente en una sola línea.

/* Sintaxis: font: [style] [variant] [weight] size/line-height family; */
/* Forma larga */
.elemento {
font-style: italic;
font-weight: 700;
font-size: 16px;
line-height: 1.5;
font-family: Arial, sans-serif;
}
/* Forma corta (equivalente) */
.elemento {
font: italic 700 16px/1.5 Arial, sans-serif;
}
/* Título principal */
h1 {
font: bold 2.5rem/1.2 Georgia, serif;
}
/* Texto normal */
p {
font: normal 1rem/1.6 Arial, sans-serif;
}
/* Código */
code {
font: normal 0.875rem/1.4 'Courier New', monospace;
}
/* Texto destacado */
.destacado {
font: italic 600 1.125rem/1.5 'Segoe UI', sans-serif;
}

El espaciado correcto mejora dramáticamente la legibilidad.

Define el espacio vertical entre líneas de texto.

/* Diferentes formas de definir line-height */
.elemento {
line-height: 1.5; /* Sin unidad (recomendado) */
line-height: 24px; /* Píxeles (fijo) */
line-height: 1.5rem; /* Relativo */
line-height: 150%; /* Porcentaje */
line-height: normal; /* Default (~1.2) */
}
/* Guía de line-height según tipo de texto */
/* Títulos - Más compacto */
h1, h2, h3 {
line-height: 1.2; /* 120% del tamaño de fuente */
}
/* Texto normal - Legible */
p, body {
line-height: 1.6; /* 160% - Ideal para lectura */
}
/* Texto pequeño */
small, .texto-pequeno {
line-height: 1.5;
}
/* Código */
code, pre {
line-height: 1.4; /* Más compacto para código */
}
/* Botones y UI */
button, .boton {
line-height: 1; /* Sin espacio extra */
}

Controla el espacio entre caracteres (tracking/kerning).

/* Valores de letter-spacing */
.elemento {
letter-spacing: normal; /* Default (0) */
letter-spacing: 0.05em; /* Más espacio */
letter-spacing: 2px; /* Espacio fijo */
letter-spacing: -0.02em; /* Menos espacio (apretado) */
}
/* Títulos en mayúsculas - Más espaciado */
h1 {
text-transform: uppercase;
letter-spacing: 0.1em; /* Más legible en mayúsculas */
}
/* Logos y marcas */
.logo {
letter-spacing: 0.15em;
text-transform: uppercase;
font-weight: 700;
}
/* Texto normal - Sin cambios */
p {
letter-spacing: normal; /* 0 */
}
/* Texto compacto */
.compacto {
letter-spacing: -0.02em; /* Ligeramente más junto */
}
/* Botones */
.boton {
letter-spacing: 0.05em; /* Más espaciado y legible */
text-transform: uppercase;
}

Controla el espacio entre palabras.

/* Valores de word-spacing */
.elemento {
word-spacing: normal; /* Default */
word-spacing: 0.2em; /* Más espacio */
word-spacing: 5px; /* Espacio fijo */
word-spacing: -0.1em; /* Menos espacio */
}
/* Texto normal */
p {
word-spacing: normal;
}
/* Más espaciado entre palabras */
.espaciado {
word-spacing: 0.3em;
}
/* Menos espaciado */
.compacto {
word-spacing: -0.05em;
}
/* Títulos con espaciado */
h1 {
word-spacing: 0.1em;
letter-spacing: 0.05em;
}

Define cómo se alinea el texto horizontalmente.

/* Valores de text-align */
.elemento {
text-align: left; /* Izquierda (default en LTR) */
text-align: right; /* Derecha */
text-align: center; /* Centrado */
text-align: justify; /* Justificado */
text-align: start; /* Inicio (depende de dirección) */
text-align: end; /* Final (depende de dirección) */
}
/* Texto normal - Izquierda */
p {
text-align: left;
}
/* Títulos centrados */
h1, h2 {
text-align: center;
}
/* Texto justificado (periódicos, revistas) */
.articulo {
text-align: justify;
}
/* Alineación a la derecha (números, fechas) */
.precio, .fecha {
text-align: right;
}
/* Botones centrados */
.contenedor-boton {
text-align: center;
}

Añade líneas decorativas al texto.

/* Valores individuales */
.elemento {
text-decoration: none; /* Sin decoración */
text-decoration: underline; /* Subrayado */
text-decoration: overline; /* Línea superior */
text-decoration: line-through; /* Tachado */
}
/* Sintaxis completa */
.elemento {
text-decoration: underline solid red 2px;
/* línea estilo color grosor */
}
/* Enlaces - Quitar subrayado */
a {
text-decoration: none;
color: #007bff;
}
a:hover {
text-decoration: underline;
}
/* Texto tachado (precio anterior) */
.precio-anterior {
text-decoration: line-through;
color: #999;
}
/* Énfasis con subrayado */
.destacado {
text-decoration: underline;
text-decoration-color: #f39c12;
text-decoration-thickness: 2px;
}

text-transform - Transformación del texto

Section titled “text-transform - Transformación del texto”

Cambia las mayúsculas/minúsculas del texto.

/* Valores de text-transform */
.elemento {
text-transform: none; /* Sin cambios */
text-transform: uppercase; /* MAYÚSCULAS */
text-transform: lowercase; /* minúsculas */
text-transform: capitalize; /* Primera Letra De Cada Palabra */
}
/* Títulos en mayúsculas */
h1 {
text-transform: uppercase;
letter-spacing: 0.1em;
}
/* Botones en mayúsculas */
.boton {
text-transform: uppercase;
font-size: 0.875rem;
letter-spacing: 0.05em;
font-weight: 600;
}
/* Nombres propios capitalizados */
.nombre {
text-transform: capitalize;
}
/* Texto en minúsculas */
.email {
text-transform: lowercase;
}
/* Sin transformación */
.normal {
text-transform: none;
}
/* Sangría de primera línea */
p {
text-indent: 2em; /* Sangría de 2em */
}
/* Sangría negativa (hanging indent) */
.lista-custom {
text-indent: -1.5em;
padding-left: 1.5em;
}
/* Sin sangría */
.sin-sangria {
text-indent: 0;
}

Permite usar fuentes personalizadas que no están instaladas en el sistema del usuario.

/* Sintaxis básica de @font-face */
@font-face {
font-family: 'MiFuente';
src: url('fonts/mifuente.woff2') format('woff2'),
url('fonts/mifuente.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}
/* Usar la fuente */
body {
font-family: 'MiFuente', Arial, sans-serif;
}
/* Fuente regular */
@font-face {
font-family: 'Roboto';
src: url('fonts/Roboto-Regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
}
/* Fuente negrita */
@font-face {
font-family: 'Roboto';
src: url('fonts/Roboto-Bold.woff2') format('woff2');
font-weight: 700;
font-style: normal;
}
/* Fuente cursiva */
@font-face {
font-family: 'Roboto';
src: url('fonts/Roboto-Italic.woff2') format('woff2');
font-weight: 400;
font-style: italic;
}
/* Uso */
body {
font-family: 'Roboto', sans-serif;
}
strong {
font-weight: 700; /* Usa Roboto-Bold automáticamente */
}
em {
font-style: italic; /* Usa Roboto-Italic automáticamente */
}

Google Fonts ofrece cientos de fuentes gratuitas optimizadas.

  1. Selecciona fuentes en Google Fonts

    • Busca la fuente que te guste
    • Selecciona los pesos que necesitas
    • Copia el código de integración
  2. Método 1: Link en HTML Recomendado

    <!-- En el <head> de tu HTML -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
  3. Método 2: @import en CSS

    /* Al inicio de tu CSS */
    @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
  4. Usar la fuente

    body {
    font-family: 'Roboto', sans-serif;
    }
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Google Fonts</title>
<!-- Preconectar para mejor rendimiento -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<!-- Cargar fuentes -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
font-size: 16px;
line-height: 1.6;
}
h1, h2, h3 {
font-family: 'Poppins', sans-serif;
font-weight: 700;
}
.destacado {
font-family: 'Poppins', sans-serif;
font-weight: 600;
}
</style>
</head>
<body>
<h1>Título con Poppins</h1>
<p>Texto con Roboto</p>
<p class="destacado">Texto destacado con Poppins</p>
</body>
</html>
<!-- Precargar fuente crítica para mejor rendimiento -->
<link rel="preload"
href="fonts/mifuente.woff2"
as="font"
type="font/woff2"
crossorigin>

🐝