CSS Transitions: Free HTML & CSS Tutorial
Master Smooth CSS Transitions for Professional Web Animations
CSS Transition Fundamentals
Transition Property
Defines which CSS properties should animate when changed. Can target specific properties like color, opacity, or use 'all' for comprehensive coverage.
Transition Duration
Controls how long the animation takes to complete. Can be specified in seconds (s) or milliseconds (ms) for precise timing control.
Timing Functions
Determines the speed curve of the transition. Options include linear, ease-in, ease-out, and custom cubic-bezier functions for advanced control.
Notice how hover effects immediately snap to their final state. This exercise transforms abrupt changes into smooth, professional transitions that enhance user experience.
Setup Process
Close Current Files
Close all open files in your code editor to avoid confusion between different project folders.
Open Transitions Folder
Navigate to Desktop > Class Files > Advanced HTML CSS Class > Transitions and open in your editor.
Preview Initial State
Open index.html and preview in browser to see the abrupt hover changes we'll be smoothing out.
Transitions are declared in the base element rule, not the hover rule. The browser needs to know what to do before it starts transitioning.
Time Units Comparison
| Feature | Seconds | Milliseconds |
|---|---|---|
| 2 seconds | 2s | 2000ms |
| Half second | 0.5s | 500ms |
| Quick transition | 0.3s | 300ms |
Chrome and Safari incorrectly fire transitions on page load. This JavaScript solution temporarily disables transitions during initial load.
Transition Flicker Fix
Add Disable Style
Insert CSS that disables all transitions with !important in the document head.
Apply Preload Class
Add class='preload' to the body tag to activate the transition-disabling CSS.
Remove After Load
JavaScript removes the preload class after page load, re-enabling transitions for user interactions.
All Keyword Usage
By positioning labels at the bottom initially, mobile users can always see the descriptions, while desktop users get the enhanced hover animation.
Overlay Animation Setup
Position at Bottom
Use calc(100% - 4rem) to position overlay showing only one line of text at the bottom of images.
Expand on Hover
Move top position to 0 on hover, expanding the overlay to cover the full image height.
Add Center Padding
Include vertical centering padding only in the hover state when overlay is full height.
Built-in Easing Options
Linear
Constant speed throughout the animation. Creates a robotic, mechanical feel that's rarely ideal for user interfaces.
Ease-in
Starts slow and accelerates toward the end. Good for elements moving off-screen or disappearing from view.
Ease-out
Starts fast and decelerates toward the end. Ideal for elements appearing or moving into final position.
Select and copy the generated transition value from the output panel:

Replace the current transition with the custom cubic-bezier values:
.category.description {
Code Omitted To Save Space
transition: all 300ms cubic-bezier(0.190,1,000,0.220,1,000);
}Hover over the artwork images to experience the improved interaction quality. The animation now has character and sophistication that elevates the entire interface.
Robert Penner's easing functions have become the de facto standard across animation platforms, from Flash to jQuery, GSAP, and modern CSS implementations.
Adding focus selectors to hover effects ensures keyboard navigation users get the same visual feedback as mouse users, improving overall accessibility.
Accessibility Enhancement Checklist
Ensures keyboard users get the same visual feedback as mouse users
Verify that focus states are clearly visible and functional
Creates uniform experience regardless of interaction method
Key Takeaways
