Note opacity affects the entire element and all its children. For transparent backgrounds only, use rgba or hsla with alpha instead. An element with opacity less than 1 creates a new stacking context.
@keyframes name {
from {...}
to {...}}@keyframes name {0%{...}50%{...}100%{...}}
Example
@keyframes fadeSlideIn {
from {opacity:0;transform:translateY(20px);}
to {opacity:1;transform:translateY(0);}}.card{animation: fadeSlideIn 0.4s ease-out;}
Note Keyframe animations run independently from state changes unlike transitions which need a trigger. Define keyframes globally and apply them with the animation property. The animation runs once by default.
Frequently asked questions
How does HTML & CSS handle fade?
HTML & CSS covers this with 2 copy-ready snippets on this page. The "Opacity" snippet in HTML & CSS uses `opacity: 0 to 1;`.
Which code does the HTML & CSS example use?
The "Opacity" snippet uses `opacity: 0 to 1;`, from the Colors & Backgrounds section of the HTML & CSS cheat sheet.
What other HTML & CSS snippets are shown for "fade"?
Besides "Opacity", this page also shows "Keyframe Animations".
Is there anything to watch out for?
Yes. For "Opacity": opacity affects the entire element and all its children. For transparent backgrounds only, use rgba or hsla with alpha instead. An element with opacity less than 1 creates a new stacking context.