Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSS Variable Fonts Animation
#1
Description:

You can create smooth font size transitions using CSS transitions and variable fonts.

Example:

<!DOCTYPE html>
<html>
<head>
  <title>CSS Variable Fonts Animation Example</title>
  <style>
    .variable-font-text {
      font-family: 'Inter Variable', sans-serif;
      font-size: var(--font-size, 16px);
      transition: font-size 0.3s ease;
    }
    button {
      font-size: 20px;
      padding: 10px;
    }
  </style>
</head>
<body>
  <p class="variable-font-text">Variable Fonts are Awesome!</p>
  <button onclick="increaseFontSize()">Increase Font Size</button>
  <script>
    function increaseFontSize() {
      const element = document.querySelector('.variable-font-text');
      const computedStyle = window.getComputedStyle(element);
      const currentFontSize = parseFloat(computedStyle.getPropertyValue('font-size'));
      element.style.setProperty('--font-size', `${currentFontSize + 4}px`);
    }
  </script>
</body>
</html>

Explanation:

In this example, the .variable-font-text paragraph uses the 'Inter Variable' font family, which is a variable font. The font-size property is set using a CSS variable (--font-size). When the button is clicked, the increaseFontSize() JavaScript function increases the font size by 4 pixels, creating a smooth transition due to the transition property. Variable fonts allow for more dynamic control over typography, and with CSS variables, you can create fluid font size animations.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  CSS Grid Masonry Layout Qomplainerz 0 320 07-26-2023, 07:54 PM
Last Post: Qomplainerz
  CSS Custom Scrollbar Styles (Webkit and Firefox) Qomplainerz 0 276 07-26-2023, 07:52 PM
Last Post: Qomplainerz
  CSS Box Decoration Break Qomplainerz 0 238 07-26-2023, 07:49 PM
Last Post: Qomplainerz
  CSS Conic Gradients for Circular Progress Bar Qomplainerz 0 242 07-26-2023, 07:48 PM
Last Post: Qomplainerz
  CSS Grid Subgrid Qomplainerz 0 249 07-26-2023, 07:46 PM
Last Post: Qomplainerz
  CSS Scrollbar Styling Qomplainerz 0 237 07-26-2023, 07:43 PM
Last Post: Qomplainerz
  CSS Grid Auto-fit and Minmax Qomplainerz 0 238 07-26-2023, 07:41 PM
Last Post: Qomplainerz
  CSS clip path Qomplainerz 0 250 07-26-2023, 07:38 PM
Last Post: Qomplainerz
  CSS Feature Queries Qomplainerz 0 213 07-26-2023, 07:05 PM
Last Post: Qomplainerz
  CSS Custom properties (Variables) Qomplainerz 0 185 07-26-2023, 07:04 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)