Toolypet
Voltar ao Blog
CSS

Guia Completo de CSS Animation e Transition 2026

As diferencas entre CSS transition e animation, como usa-los e otimizacao de desempenho. Guia pratico para criar interacoes UI fluidas.

Toolypet Team

Toolypet Team

Development Team

8 min de leitura

Guia Completo de CSS Animation e Transition 2026

Efeitos hover em botoes, spinners de carregamento, transicoes de pagina... Animacoes sao essenciais no desenvolvimento web moderno.

Aprenda a criar interacoes fluidas apenas com CSS, sem JavaScript.


Transition vs Animation

CaracteristicaTransitionAnimation
GatilhoRequer mudanca de estado (:hover, etc.)Pode auto-reproduzir
KeyframesApenas inicio-fim (2)Ilimitados
LoopNao possivelLoop infinito possivel
DirecaoApenas para frenteReverso, alternado possivel
UsoMudancas de estado simplesAnimacoes complexas

CSS Transition

Sintaxe basica

transition: property duration timing-function delay;
PropriedadeDescricaoPadrao
propertyPropriedade a transicionarall
durationDuracao0s
timing-functionCurva de aceleracaoease
delayAtraso inicial0s

Exemplos basicos

/* Propriedade unica */
.button {
  background: #3b82f6;
  transition: background 0.3s ease;
}

.button:hover {
  background: #2563eb;
}

/* Multiplas propriedades */
.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);
}

Funcoes de tempo

/* Funcoes incorporadas */
.ease { transition-timing-function: ease; }         /* Padrao */
.linear { transition-timing-function: linear; }     /* Velocidade 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

/* Bounce */
.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

Sintaxe basica

@keyframes nomeAnimacao {
  from { /* Estado inicial */ }
  to { /* Estado final */ }
}

/* Ou */
@keyframes nomeAnimacao {
  0% { /* Inicio */ }
  50% { /* Meio */ }
  100% { /* Fim */ }
}

.element {
  animation: nome duration timing-function delay iteration-count direction fill-mode;
}

Propriedades de Animation

PropriedadeValoresDescricao
animation-nameNome do keyframeObrigatorio
animation-durationTempoObrigatorio
animation-timing-functionTimingease
animation-delayTempo de atraso0s
animation-iteration-countRepeticoes1, infinite
animation-directionDirecaonormal, reverse, alternate
animation-fill-modeEstado finalnone, forwards, backwards, both
animation-play-stateEstado de reproducaorunning, paused

Exemplos praticos de animacao

1. Fade In

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.5s ease forwards;
}

/* Fade in de cima */
@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 carregamento

@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. Efeito pulso

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* Anel 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. Bounce

@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. Shake (Erro)

@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 com JavaScript */
/* element.classList.add('shake'); */

6. Efeito digitacao

@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. Carregamento 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 com Transform

Propriedades Transform

/* Transladar */
transform: translateX(100px);
transform: translateY(50px);
transform: translate(100px, 50px);

/* Rotacionar */
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);

Efeitos 3D

/* Definir perspectiva no pai */
.perspective-container {
  perspective: 1000px;
}

/* Flip de card */
.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);
}

Otimizacao de desempenho

Propriedades aceleradas por GPU

/* ✅ Acelerado por GPU (bom desempenho) */
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

/* Dica para alvos de animacao */
.animated {
  will-change: transform, opacity;
}

/* Apenas no hover */
.card:hover {
  will-change: transform;
}

/* Recomenda-se remover apos a animacao */

Evitando reflow

/* ❌ Padrao a evitar */
.bad {
  animation: move 1s infinite;
}
@keyframes move {
  to { left: 100px; } /* Causa reflow */
}

/* ✅ Padrao recomendado */
.good {
  animation: moveGood 1s infinite;
}
@keyframes moveGood {
  to { transform: translateX(100px); } /* Acelerado por GPU */
}

Acessibilidade

Respeitando preferencias de movimento reduzido

/* Quando o usuario prefere movimento reduzido */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Ou seletivamente */
@media (prefers-reduced-motion: reduce) {
  .animated {
    animation: none;
  }

  .transition {
    transition: none;
  }
}

Padroes UI praticos

Hover de botao

.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 dropdown

.dropdown {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
}

.menu:hover .dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

Abertura 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);
}

Aparecimento escalonado

.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: A transition nao funciona

R: Verificar:

  • A propriedade e animavel?
  • Transitions nao funcionam a partir de display: none
  • Os valores inicial e final estao explicitamente definidos?

P2: Como manter o estado apos o fim da animacao?

R: Use animation-fill-mode: forwards

.element {
  animation: fadeIn 1s ease forwards;
}

P3: O desempenho esta ruim

R:

  • Animar apenas transform e opacity
  • Usar will-change apropriadamente
  • Evitar animar muitos elementos

P4: Animacoes CSS ou JavaScript?

R:

  • Transicoes simples: CSS
  • Sequencias complexas: JavaScript (GSAP, etc.)
  • Resposta a entrada do usuario: JavaScript
  • Loops automaticos: CSS

Conclusao

Pontos-chave de animacao CSS:

  1. Transition: Responde a mudancas de estado
  2. Animation: Auto-reproducao, keyframes
  3. Transform: Acelerado por GPU, excelente desempenho
  4. Timing: ease, cubic-bezier
  5. Acessibilidade: Respeitar prefers-reduced-motion

Ferramentas relacionadas

FerramentaProposito
Gerador de AnimationGerar keyframes
Gerador de TransformEfeitos de transformacao
Gerador de FiltrosFiltros CSS
CSSanimationtransitionanimacoesUIinteracao

Sobre o Autor

Toolypet Team

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