CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Time Units


Time units in CSS specify a duration. They are crucial for defining how long animations and transitions should last or when they should start.

Example 1: s (seconds) in Transition Duration

/* Sets a smooth transition for the 'background-color' property over 0.5 seconds */
.my-element {
  background-color: blue;
  transition: background-color 0.5s ease-in-out; /* 0.5 seconds duration */
}

.my-element:hover {
  background-color: red;
}

Explanation This example demonstrates using s for transition-duration. The background color change from blue to red will take 0.5 seconds, creating a subtle animation effect. This enhances user interaction.


Example 2: ms (milliseconds) in Animation Duration

/* Defines a 'fade-in' animation that completes in 750 milliseconds */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-item {
  opacity: 0;
  animation: fade-in 750ms forwards; /* 750 milliseconds duration */
}

Explanation Here, ms defines the animation duration. The .fade-item will gradually become visible over 750 milliseconds, providing a smooth entrance effect. Milliseconds offer finer control for subtle timing.


Example 3: s for Animation Delay

/* Delays the 'slide-in' animation by 1 second before it starts */
@keyframes slide-in {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.delayed-item {
  animation: slide-in 0.8s ease-out 1s forwards; /* 1 second delay */
}

Explanation This illustrates s for animation-delay. The slide-in animation will wait for 1 second before executing, useful for orchestrating multiple animations. This ensures a staggered visual presentation.


Example 4: ms for Transition Delay

/* Delays the 'color' transition by 200 milliseconds */
.hover-effect {
  color: black;
  transition: color 0.3s ease-in-out 200ms; /* 200 milliseconds delay */
}

.hover-effect:hover {
  color: green;
}

Explanation In this code, ms is used for transition-delay. The color change will be delayed by 200 milliseconds after the hover event. This can create a slight pause for a more refined user experience.


Example 5: Combining s and ms for precise control

/* Applies a bounce animation with 0.6s duration, 0.1s delay, and 200ms iteration delay */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  60% { transform: translateY(-15px); }
}

.bouncing-element {
  animation: bounce 0.6s ease-out 0.1s infinite; /* 0.6s duration, 0.1s delay */
  /* Note: Animation iteration delay is not a direct CSS property, 
     but achieved through keyframe timing or multiple animations. 
     This example focuses on `s` and `ms` in duration/delay. */
}

Explanation While direct iteration delay isn't a single property, this demonstrates using s for duration and delay. Precision in timing with s and ms allows for complex and fluid animations, enhancing web interactivity.