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

Ease In Out Timing Function


The ease-in-out timing function defines a transition that starts slowly, accelerates through the middle, and then decelerates towards the end. This creates a smooth and natural-feeling animation for elements appearing and disappearing or changing states. It is often used to create sophisticated and polished user interface effects.


Example 1: Opacity Transition

/* This div will fade in and out smoothly */
.fade-box {
  width: 100px;
  height: 100px;
  background-color: #3498db;
  opacity: 0.1;
  /* Specifies the transition effect */
  transition: opacity 2s ease-in-out;
}

/* On hover, the box becomes fully visible */
.fade-box:hover {
  opacity: 1;
}

Explanation

This code block defines a div that has a low opacity by default. When a user hovers over it, the opacity transitions to 1 over two seconds. The ease-in-out function ensures this fading effect starts gradually, speeds up, and then slows down as it becomes fully opaque.


Example 2: Width Change

/* A simple button that expands on hover */
.expand-button {
  width: 150px;
  height: 50px;
  background-color: #2ecc71;
  color: white;
  text-align: center;
  line-height: 50px;
  /* Defines the transition for the width property */
  transition: width 1.5s ease-in-out;
}

/* The button's width increases when hovered */
.expand-button:hover {
  width: 250px;
}

Explanation

Here, a button's width is set to transition when a user hovers over it. The ease-in-out value causes the button to expand and retract with a smooth, controlled acceleration and deceleration, providing a fluid user experience.


Example 3: Rotation Transformation

/* An icon that rotates on hover */
.rotate-icon {
  font-size: 50px;
  color: #e74c3c;
  /* Sets the transition for the transform property */
  transition: transform 1s ease-in-out;
}

/* Rotates the icon 360 degrees on hover */
.rotate-icon:hover {
  transform: rotate(360deg);
}

Explanation

This example applies a rotation effect to an icon. The ease-in-out timing function makes the rotation start slowly, spin faster, and then gently come to a stop, avoiding an abrupt or mechanical-looking motion.


Example 4: Color Change

/* A background that changes color smoothly */
.color-shift {
  width: 100%;
  height: 100px;
  background-color: #9b59b6;
  /* Applies the transition to the background-color property */
  transition: background-color 3s ease-in-out;
}

/* Changes the background color on hover */
.color-shift:hover {
  background-color: #1abc9c;
}

Explanation

This CSS demonstrates a background color change. With ease-in-out, the color shift doesn't happen at a constant speed; instead, it provides a more organic transition between the two colors over three seconds.


Example 5: Font Size Growth

/* Text that grows in size on hover */
.text-grow {
  font-size: 18px;
  font-family: Arial, sans-serif;
  /* Defines the transition for the font-size property */
  transition: font-size 1.2s ease-in-out;
}

/* Increases the font size on hover */
.text-grow:hover {
  font-size: 28px;
}

Explanation

In this final example, the font size of a text element animates on hover. The ease-in-out function creates a pleasing effect where the text seems to smoothly "breathe" or grow and then shrink back with a gentle easing at both ends of the transition.