CSS
Guia Completa de CSS Animation y Transition 2026
Las diferencias entre CSS transition y animation, como usarlos y optimizacion de rendimiento. Guia practica para crear interacciones UI fluidas.
Toolypet Team
Development Team
Guia Completa de CSS Animation y Transition 2026
Efectos hover en botones, spinners de carga, transiciones de pagina... Las animaciones son esenciales en el desarrollo web moderno.
Aprende a crear interacciones fluidas solo con CSS, sin JavaScript.
Transition vs Animation
| Caracteristica | Transition | Animation |
|---|---|---|
| Disparador | Requiere cambio de estado (:hover, etc.) | Puede auto-reproducirse |
| Keyframes | Solo inicio-fin (2) | Ilimitados |
| Bucle | No posible | Bucle infinito posible |
| Direccion | Solo hacia adelante | Reversa, alternada posible |
| Uso | Cambios de estado simples | Animaciones complejas |
CSS Transition
Sintaxis basica
transition: property duration timing-function delay;
| Propiedad | Descripcion | Por defecto |
|---|---|---|
property | Propiedad a transicionar | all |
duration | Duracion | 0s |
timing-function | Curva de aceleracion | ease |
delay | Retraso inicial | 0s |
Ejemplos basicos
/* Propiedad unica */
.button {
background: #3b82f6;
transition: background 0.3s ease;
}
.button:hover {
background: #2563eb;
}
/* Multiples propiedades */
.card {
transform: translateY(0);
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
Funciones de tiempo
/* Funciones incorporadas */
.ease { transition-timing-function: ease; } /* Por defecto */
.linear { transition-timing-function: linear; } /* Velocidad constante */
.ease-in { transition-timing-function: ease-in; } /* Inicio lento */
.ease-out { transition-timing-function: ease-out; } /* Final lento */
.ease-in-out { transition-timing-function: ease-in-out; }
/* Curva bezier personalizada */
.custom { transition-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55); }
/* Escalonado */
.steps { transition-timing-function: steps(4, end); }
Curvas Bezier populares
/* Rebote */
.bounce { transition: all 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); }
/* Suave */
.smooth { transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); }
/* Snap */
.snap { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
CSS Animation
Sintaxis basica
@keyframes nombreAnimacion {
from { /* Estado inicial */ }
to { /* Estado final */ }
}
/* O */
@keyframes nombreAnimacion {
0% { /* Inicio */ }
50% { /* Mitad */ }
100% { /* Fin */ }
}
.element {
animation: nombre duration timing-function delay iteration-count direction fill-mode;
}
Propiedades de Animation
| Propiedad | Valores | Descripcion |
|---|---|---|
animation-name | Nombre del keyframe | Requerido |
animation-duration | Tiempo | Requerido |
animation-timing-function | Timing | ease |
animation-delay | Tiempo de retraso | 0s |
animation-iteration-count | Repeticiones | 1, infinite |
animation-direction | Direccion | normal, reverse, alternate |
animation-fill-mode | Estado final | none, forwards, backwards, both |
animation-play-state | Estado de reproduccion | running, paused |
Ejemplos practicos de animacion
1. Fade In
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.fade-in {
animation: fadeIn 0.5s ease forwards;
}
/* Fade in desde arriba */
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.fade-in-down {
animation: fadeInDown 0.5s ease forwards;
}
2. Spinner de carga
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #e5e7eb;
border-top-color: #3b82f6;
border-radius: 50%;
animation: spin 1s linear infinite;
}
3. Efecto pulso
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.pulse {
animation: pulse 2s ease-in-out infinite;
}
/* Anillo pulsante */
@keyframes pulseRing {
0% {
transform: scale(0.8);
opacity: 1;
}
100% {
transform: scale(2);
opacity: 0;
}
}
.pulse-ring {
position: relative;
}
.pulse-ring::before {
content: '';
position: absolute;
inset: 0;
border: 2px solid #3b82f6;
border-radius: 50%;
animation: pulseRing 1.5s ease-out infinite;
}
4. Rebote
@keyframes bounce {
0%, 100% {
transform: translateY(0);
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
}
50% {
transform: translateY(-25%);
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
}
}
.bounce {
animation: bounce 1s infinite;
}
5. Agitar (Error)
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.shake {
animation: shake 0.5s ease;
}
/* Disparar con JavaScript */
/* element.classList.add('shake'); */
6. Efecto escritura
@keyframes typing {
from { width: 0; }
to { width: 100%; }
}
@keyframes blink {
50% { border-color: transparent; }
}
.typing {
overflow: hidden;
white-space: nowrap;
border-right: 3px solid;
width: 0;
animation:
typing 3s steps(30) forwards,
blink 0.7s step-end infinite;
}
7. Carga skeleton
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.skeleton {
background: linear-gradient(
90deg,
#f0f0f0 25%,
#e0e0e0 50%,
#f0f0f0 75%
);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
}
Usando con Transform
Propiedades Transform
/* Trasladar */
transform: translateX(100px);
transform: translateY(50px);
transform: translate(100px, 50px);
/* Rotar */
transform: rotate(45deg);
transform: rotateX(45deg); /* 3D */
transform: rotateY(45deg); /* 3D */
/* Escalar */
transform: scale(1.5);
transform: scaleX(2);
/* Inclinar */
transform: skew(10deg);
/* Combinado */
transform: translateX(100px) rotate(45deg) scale(1.2);
Efectos 3D
/* Establecer perspectiva en el padre */
.perspective-container {
perspective: 1000px;
}
/* Volteo de tarjeta */
.card-3d {
transform-style: preserve-3d;
transition: transform 0.6s;
}
.card-3d:hover {
transform: rotateY(180deg);
}
.card-front, .card-back {
backface-visibility: hidden;
}
.card-back {
transform: rotateY(180deg);
}
Optimizacion de rendimiento
Propiedades aceleradas por GPU
/* ✅ Acelerado por GPU (buen rendimiento) */
transform: translateX(100px);
transform: scale(1.1);
transform: rotate(45deg);
opacity: 0.5;
/* ❌ Computado por CPU (causa reflow) */
left: 100px;
width: 200px;
height: 200px;
margin: 10px;
will-change
/* Pista para objetivos de animacion */
.animated {
will-change: transform, opacity;
}
/* Solo en hover */
.card:hover {
will-change: transform;
}
/* Se recomienda eliminar despues de la animacion */
Evitando reflow
/* ❌ Patron a evitar */
.bad {
animation: move 1s infinite;
}
@keyframes move {
to { left: 100px; } /* Causa reflow */
}
/* ✅ Patron recomendado */
.good {
animation: moveGood 1s infinite;
}
@keyframes moveGood {
to { transform: translateX(100px); } /* Acelerado por GPU */
}
Accesibilidad
Respetando preferencias de movimiento reducido
/* Cuando el usuario prefiere movimiento reducido */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* O selectivamente */
@media (prefers-reduced-motion: reduce) {
.animated {
animation: none;
}
.transition {
transition: none;
}
}
Patrones UI practicos
Hover de boton
.button {
background: #3b82f6;
color: white;
padding: 12px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
}
.button:hover {
background: #2563eb;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}
.button:active {
transform: translateY(0);
}
Menu desplegable
.dropdown {
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.2s ease;
}
.menu:hover .dropdown {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
Apertura de modal
.modal-overlay {
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease;
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal {
transform: scale(0.9) translateY(20px);
transition: transform 0.3s ease;
}
.modal-overlay.active .modal {
transform: scale(1) translateY(0);
}
Aparicion escalonada
.item {
opacity: 0;
transform: translateY(20px);
animation: fadeInUp 0.5s ease forwards;
}
.item:nth-child(1) { animation-delay: 0.1s; }
.item:nth-child(2) { animation-delay: 0.2s; }
.item:nth-child(3) { animation-delay: 0.3s; }
@keyframes fadeInUp {
to {
opacity: 1;
transform: translateY(0);
}
}
FAQ
P1: La transition no funciona
R: Verificar:
- Es la propiedad animable?
- Las transiciones no funcionan desde
display: none - Estan definidos explicitamente los valores inicial y final?
P2: Como mantener el estado despues de que termine la animacion?
R: Usa animation-fill-mode: forwards
.element {
animation: fadeIn 1s ease forwards;
}
P3: El rendimiento es malo
R:
- Solo animar
transformyopacity - Usar
will-changeapropiadamente - Evitar animar demasiados elementos
P4: Animaciones CSS o JavaScript?
R:
- Transiciones simples: CSS
- Secuencias complejas: JavaScript (GSAP, etc.)
- Respuesta a entrada del usuario: JavaScript
- Bucles automaticos: CSS
Conclusion
Puntos clave de animacion CSS:
- Transition: Responde a cambios de estado
- Animation: Auto-reproduccion, keyframes
- Transform: Acelerado por GPU, excelente rendimiento
- Timing: ease, cubic-bezier
- Accesibilidad: Respetar prefers-reduced-motion
Herramientas relacionadas
| Herramienta | Proposito |
|---|---|
| Generador de Animation | Generar keyframes |
| Generador de Transform | Efectos de transformacion |
| Generador de Filtros | Filtros CSS |
CSSanimationtransitionanimacionesUIinteraccion
Sobre el Autor
Toolypet Team
Development Team
The Toolypet Team creates free, privacy-focused web tools for developers and designers. All tools run entirely in your browser with no data sent to servers.
Web DevelopmentCSS ToolsDeveloper ToolsSEOSecurity