CSS Transitions for Smooth State Changes

Applies CSS transitions to create smooth property changes on hover, focus, and state toggles with custom timing and easing functions.

CssForm Validation

Code

snippet
/* Basic hover transition */
.button {
  background: #3498db;
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  transition: background 0.3s ease, transform 0.2s ease;
}

.button:hover {
  background: #2980b9;
  transform: translateY(-2px);
}

.button:active {
  transform: translateY(0);
}

/* Color transition */
.link {
  color: #333;
  transition: color 0.2s ease;
}

.link:hover {
  color: #007bff;
}

/* Expand on hover */
.card {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.3s ease;
}

.card:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* Smooth dropdown */
.dropdown {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-in-out, opacity 0.3s ease;
  opacity: 0;
}

.dropdown.open {
  max-height: 500px;
  opacity: 1;
}

/* Multi-property transition */
.panel {
  transition: all 0.3s ease;
}

.panel.collapsed {
  height: 0;
  padding: 0;
  opacity: 0;
  margin: 0;
}

/* Transition with delay */
.toast {
  transition: transform 0.3s ease 0.1s,
              opacity 0.3s ease;
}

/* Focus ring transition */
input {
  transition: box-shadow 0.2s ease;
}

input:focus {
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
}