Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Create a Color Change Box Using CSS Transition Timing Functions
📖 Scenario: You want to make a box on a webpage that changes color smoothly when you move your mouse over it. Different timing styles make the color change feel different, like slow at first or fast at the end.
🎯 Goal: Build a simple colored box that changes its background color smoothly using CSS transitions with different timing functions.
📋 What You'll Learn
Create a box with a fixed size and initial background color.
Add a CSS transition to the box for the background color property.
Use a CSS variable to store the transition timing function.
Change the box's background color on hover to a new color.
Apply the transition timing function variable to the transition property.
💡 Why This Matters
🌍 Real World
Smooth transitions make websites feel polished and easy to use. Timing functions control how animations speed up or slow down, improving user experience.
💼 Career
Web developers use CSS transitions and timing functions to create interactive and visually appealing interfaces that respond smoothly to user actions.
Progress0 / 4 steps
1
Create a box with initial style
Write CSS to create a class called .color-box that sets the width to 200px, height to 200px, and background color to #3498db.
CSS
Hint
Use width, height, and background-color properties inside the .color-box class.
2
Add a CSS variable for timing function
Inside the .color-box class, add a CSS variable called --timing and set it to ease-in-out.
CSS
Hint
CSS variables start with --. Set --timing inside the .color-box class.
3
Add transition using the timing function variable
Add a transition property to .color-box that changes background-color over 0.5s using the CSS variable var(--timing) for the timing function.
CSS
Hint
Use transition: background-color 0.5s var(--timing); to apply the timing function variable.
4
Change background color on hover
Add a :hover style for .color-box that changes the background color to #e74c3c.
CSS
Hint
Use .color-box:hover selector and set background-color to #e74c3c.
Practice
(1/5)
1. What does the CSS property transition-timing-function control?
easy
A. The speed curve of the transition animation
B. The color of the element during transition
C. The size of the element after transition
D. The delay before the transition starts
Solution
Step 1: Understand the property purpose
The transition-timing-function defines how the speed of the transition changes over time, like speeding up or slowing down.
Step 2: Compare options to definition
Only The speed curve of the transition animation describes controlling the speed curve of the animation, others describe unrelated properties.
Final Answer:
The speed curve of the transition animation -> Option A
Quick Check:
Timing function controls speed curve [OK]
Hint: Timing function = speed curve of animation [OK]
Common Mistakes:
Confusing timing function with delay
Thinking it changes color or size
Mixing with transition-duration
2. Which of the following is the correct syntax to apply a linear transition timing function in CSS?
easy
A. transition-timing-function = linear;
B. transition-timing-function: linear;
C. transition-timing-function: 'linear';
D. transition-timing-function: linear()
Solution
Step 1: Recall CSS property syntax
CSS properties use colon : to assign values without quotes for keywords.
Step 2: Check each option
transition-timing-function: linear; uses correct syntax: property, colon, value without quotes or parentheses. Others have invalid syntax.
Final Answer:
transition-timing-function: linear; -> Option B
Quick Check:
Correct CSS syntax uses colon and no quotes [OK]
Hint: CSS properties use colon and no quotes for keywords [OK]
Common Mistakes:
Using equals sign instead of colon
Adding quotes around keywords
Adding parentheses to keywords
3. Given the CSS below, what will be the visual effect of the transition timing function?
B. Incorrect property name, should be transition-timing
C. Value linear is invalid
D. Missing semicolon after transition-duration
Solution
Step 1: Check CSS property syntax
CSS properties require a colon : between property and value.
Step 2: Locate error in snippet
The line transition-timing-function linear; misses the colon after the property name.
Final Answer:
Missing colon after transition-timing-function -> Option A
Quick Check:
Property-value pairs need colon [OK]
Hint: CSS properties always need colon between name and value [OK]
Common Mistakes:
Omitting colon after property name
Confusing property names
Assuming semicolon is optional
5. You want a button's background color to change smoothly over 0.5 seconds, starting fast and slowing down at the end. Which transition-timing-function should you use?
hard
A. ease-in-out
B. ease-in
C. linear
D. ease-out
Solution
Step 1: Understand timing function meanings
ease-out means the animation starts fast and slows down at the end, exactly what is needed.
Step 2: Compare other options
ease-in is slow start, fast end; linear is constant speed; ease-in-out is slow start and end with fast middle.