Do you find it tedious to keep track of several font files for various weights and styles? Creating distinct files for ordinary, bold, italic, and other font variations can be challenging for web designers. This complicates the creative process and clogs their workflow. How about combining all these variants into one file?
That's where variable fonts come in. Variable fonts are a groundbreaking advancement in OpenType font technology that allows one font file to contain multiple variations, such as regular, bold, and italic. This implies that designers just need to work with one file to access all the various weights, styles, and widths they require. This invention makes it simple to constantly and easily modify characteristics like weight, width, and tilt, which streamlines the design process and fosters creative freedom.
Using the Kyiv Sans font as an example, this article will look at the relevance of different fonts in CSS and demonstrate how important qualities like weight and even non-standard font variations like MIDL
. Using these tools, we will learn how to produce dynamic and aesthetically stunning typography in CSS.
Introduction to Variable Fonts
Variable font technological architecture lets designers and developers instantly control these typographic characteristics using CSS, thus permitting exact changes to fit the particular requirements of a project. This improves web performance by greatly lowering load times and replacing many static font files with a single variable font file.
With their degree of flexibility and accuracy formerly unheard of with conventional static font files, variable fonts constitute a major development in typographic technology. Unlike traditional fonts, which demand separate files for every style and weight, variable fonts capture several styles within one, scalable file. This is accomplished with the OpenType font style, which permits constant variation along one or more axes—such as weight, width, and optical size.
Benefits of Variable Fonts in CSS
We'll walk you through how to create dynamic and aesthetically pleasing CSS typography using these tools. Let's examine a few examples:
Efficiency: By combining several font styles into a single file, variable fonts minimize HTTP requests, speeding up page loads and overall efficiency.
Flexibility: Designers may precisely modify typography to fit different design contexts and user preferences because of their fine-grained control over properties like wght
and custom properties like MIDL
and CONT
.
Smooth Transitions: Variable fonts allow for dynamic changes to font styles, avoiding abrupt switches between discrete font files. As a result, transitions between font styles are smooth and fluid.
Responsive Typography: Variable fonts enable responsive typography by allowing adjustments based on viewport
size or other user-defined parameters, ensuring optimal legibility and aesthetic appeal across devices.
Dynamic Typography: Variable fonts provide real-time changes depending on user interaction or environmental conditions, therefore supporting dynamic, improving user involvement, and generating immersive experiences.
Accessibility: A wider range of typographic options allows text customization and modification to ensure legibility and readability across various devices and user preferences.
Aesthetics: On the web, variable fonts inspire creative design ideas and challenge typographic boundaries, opening up new opportunities for typographic expression and experimentation.
Scalability: Variable fonts are perfect for responsive design and guarantee that text is clear and legible at any size or resolution since they are scalable without quality loss.
Introduction to the concept of responsive and dynamic typography using variable fonts
Modern web design allows designers to create more flexible and captivating typographic experiences using responsive and dynamic typography with changing fonts, let us dissect the ideas:
Variables in Fonts: Variable fonts are a single font file with several variants of a typeface
, including wght
and special properties MIDL
and CONT
. Variable fonts give more freedom and efficiency in typography design than conventional fonts, which demand distinct files for every style and enable fluid transitions between these variants.
Responsive Typography: Designing text to fit easily into many screen sizes, resolutions, and viewing environments is known as responsive typography. From big desktop computers to cellphones and everything in between, this guarantees the best readability and aesthetics across many devices. Dynamic font size, line spacing, and other typographic changes help responsive typography improve the user experience and accessibility.
Dynamic Typography: Dynamic typography enhances responsive typography by incorporating interaction and animation into typographic design. JavaScript and CSS (Cascading Style Sheets) help designers develop typefaces that suit content changes, user interactions, or scrolling behavior. Dynamic typography uses components like wght
, MIDL
, and CONT
to generate visual attractiveness and interactivity, guiding users' attention and catching them.
Designers create rich, versatile, and immersive online typographic experiences by combining dynamic and flexible typography methods with varying fonts. Whether it's dynamically changing typeface in response to user activity, animating text elements to highlight important information, or adjusting font weight and size based on screen dimensions, this approach offers many chances for creativity and invention in digital design.
The various font properties of Kyiv Sans
allow designers to create intriguing and flawless typographic transitions. This enhances the interaction and user-friendliness of web materials by increasing their aesthetic appeal and utility.
Understanding Variable Font Properties
Various typefaces offer a range of new characteristics that are absent in traditional static fonts. Knowing these characteristics is necessary to use the full potential of changeable typefaces. These are some basic ones:
Weight (wght
): By varying their wght
along a continuous axis, variable typefaces enable seamless transitions between several thickness levels. Designers can indicate a range of weights within a single font file, from light to ultra-bold and, all points in between.
Middle Layer Effect (MIDL
): This custom axis lets designers change a middle layer effect within the typeface
. This can give the text a distinctive visual style, as well as an extra degree of design freedom and inventiveness.
Contrast (CONT): Another custom axis is CONT
, which lets the font's contrast be changed. By dynamically altering the contrast depending on design requirements, this can help maximize the readability and visual attractiveness of the text.
Understanding and applying these qualities will help designers produce visually striking typefaces. With its varied font characteristics, Kyiv Sans
presents special customizing choices that improve the usability and appearance of web typography.
Overview of additional axes and variations available in variable fonts
Beyond the conventional weight, width, and optical size modifications, variable fonts provide a broad spectrum of personalizing choices. Below is a summary of the axes and variants that might be available:
Several registered axes that variable font designers may use are defined by the OpenType specification:
Width (
wdth
): This axis controls the horizontal expansion or condensation of the font, enabling designers to modify the width of characters. By adjusting this axis, designers can create fonts that appear narrower or wider without altering the overall height, allowing for a flexible range of condensed to extended styles.Slant (
slnt
): This axis allows designers to apply an italic-like slant to the characters without altering the letterforms’ structure. The slant axis typically mimics the effect of traditional italics but retains the upright letterforms, making it useful for creating stylistic variations.Italic (
ital
): The italic axis switches between upright and italic versions of a typeface. Unlike the slant axis, which only tilts the characters, the italic axis involves a complete redesign of the characters to reflect the cursive nature of true italics, providing a more authentic italic style.Optical Size (
opsz
): This axis adjusts the font’s design to optimize readability at different sizes. For example, smaller sizes may feature thicker strokes and more open counters for better legibility, while larger sizes can be more refined and delicate. This axis is particularly useful for responsive typography across various media.Grade (
GRAD
): The grade axis allows subtle adjustments to the font’s stroke weight without affecting the overall spacing. It is useful for improving readability in different print or screen environments, where a slight increase or decrease in weight can enhance contrast and clarity.Contrast (
CNTR
): This axis modifies the contrast between thick and thin strokes within a font. By adjusting the contrast, designers can create fonts with varying levels of emphasis and visual impact, from low-contrast, humanist styles to high-contrast, modern designs.X-height (
xhgt
): This axis adjusts the height of lowercase letters in relation to the font’s capital letters. Increasing the x-height can improve legibility at small sizes or create a more modern appearance while decreasing it can evoke a more traditional or formal feel.
Apart from the registered axes, variable font creators may specify their own custom axes. Regarding Kyiv Sans
: these comprise:
Middle Layer Effect (
MIDL
): This custom axis gives designers more design versatility and allows them to change a specific middle layer effect inside the typeface, thereby adding original style aspects.Contrast (
CONT
): This custom axis helps to control the contrast between thick and thin strokes in the letterforms. Designers can dynamically change this characteristic to achieve a variety of degrees of typographic expressiveness, from subdued contrasts to more obvious variances.
Aside from the registered axes, the option to construct new axes allows font designers to achieve a high degree of customization and sophisticated control over a font’s appearance and traits. Custom axes like MIDL
and CONT
, for instance, enable designers to tailor the font’s special qualities, resulting in flexible and expressive typography. These customizations, combined with variable font registration, offer numerous ways to create diverse typographic effects. For example, the Middle Layer Effect (MIDL
) axis lets designers alter a unique middle layer within the typeface, adding distinctive visual qualities that enhance artistic freedom. The Contrast (CONT
) axis, on the other hand, controls the variation between thick and thin strokes, allowing for dynamic adjustments that range from subtle to pronounced contrasts. By interacting with axes like Weight and Middle Layer Effect, designers can create text with varying thicknesses and unique styles, achieving precise control over the typeface’s appearance. Similarly, combining variations in Weight and Contrast enables the creation of text with different degrees of boldness and stroke contrast, balancing visual impact with readability. These examples demonstrate the unmatched freedom that both registered and custom axes provide, empowering designers to align typefaces with their specific aesthetic preferences and design objectives.
Implementing Variable Fonts in CSS
Now that you're enthralled with the possibilities of changeable fonts, let's investigate how to apply them in CSS-based web projects. CSS offers the means to properly use these adaptable typefaces' capabilities. Define the font first with @font-face
, which lets you provide the varying font file and its characteristics. Once the font is set, you can dynamically change the font's axes using different CSS attributes, thus maximizing the possibilities provided by varying fonts.
Obtaining the font
First, we must download the variable font we want for our project.
A few websites on the internet allow us to access varying font files. Some of the most frequently used font websites are as follows:
For this example, we’ll go to Vfonts.com to download our Kyiv Sans
variable font. The ttf
or woff2
file format works fine, but we'll be using a ttf
in this demonstration. If you need to convert your font file from ttf
to woff2
, then head to everythingfonts.com:
The screenshot above shows what you'll see when you arrive at Vfont.
We divide the project into the following steps:
Navigate to vfont: Visit the website where variable font resources are available.
Select Kyiv* Type: Choose the Kyiv* Type font, which will redirect you to Behance.net where the font is hosted.
Access the Download Link: On the Behance page, scroll all the way down to find a link to download the font.
Download from Google Drive: Click on the download link, which will take you to a Google Drive folder. Download the font file from there.
Unzip the File: After downloading, unzip the file to access its contents.
-
Review Font Options: The unzipped folder contains several options to choose from.
- Icons
- No variable
- Variable
-
Select the variable font: Focus on the files that include the variable font.
- Serif
- Tilting
- Sans
Use the Sans Font: Set up and use the Sans version of the font. Note that the Sans font weight file is 360 KB, which is equivalent to using eight non-variable font files.
Evaluate the trade-off: Consider if the use of variable fonts is worthwhile for your project. If you only need regular, bold, and italic styles, it might not be necessary to use variable fonts. However, if you require advanced control over variations, variable fonts can be very beneficial.
Note: These files above are in TTF
format.
Now we're going to head to VSCode, where we'll be using a vanilla vite
project.
To begin working on the project, you must install the necessary packages. You have to follow the steps below:
Open a new
terminal
.-
Run the command
npm create vite@latest
Name your project.
Name your package.
Select a
Vanilla
framework.Select the JavaScript variant.
Running
npm install
will help you negotiate into the project and install the necessary modules.-
After setting up the dependencies, use the following command to launch the application:
npm run dev
Visit
http://localhost:your-port-number
to access the running program on your browser.
Once we complete our project, we will have a wealth of mock code that we can modify to build our intended application. The downloaded variable font should be dropped into a font
folder, which will be dropped in the public
folder. We’ll be replacing all the unnecessary mock code in style.css
, main.js
, and index.html
.
The index.html
code should look something like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Variable font</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
</body>
</html>
From the code above, we're setting up a simple HTML wrapper for our project where the JavaScript will render content in the <div id="app"></div>
element.
The main.js
code should look something like this:
import "./style.css";
document.querySelector("#app").innerHTML = `
<div>
<h1 class="variable-font">
I am<br>
Variable font<br>
and I'm awesome
</h1>
</div>
`;
This is where we use document.querySelector()
to add content to the element we insert our content into using the id: #
And the style.css
code should look something like this:
body {
font-family: 'Kyiv Sans';
}
@font-face {
font-family: 'Kyiv Sans';
src: url('/font/KyivTypeSans-VarGX.ttf');
font-weight: 0 1000;
font-display: swap;
}
h1 {
color: #bd0c0c;
height: 100vh;
display: grid;
place-content: center;
margin: 0;
text-align: center;
}
.variable-font {
font-family: 'Kyiv Sans';
font-size: 5rem;
line-height: 1.1;
font-weight: 100;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
Now, let's explain what's going on in the code above:
Setting the Default Font for the Body:
body {
font-family: 'Kyiv Sans';
}
- Purpose: This sets the default font for the entire document to 'Kyiv Sans'.
- Impact: All text elements within the body will inherit this font unless overridden by more specific styles.
Defining the Custom Font:
@font-face {
font-family: 'Kyiv Sans';
src: url('/font/KyivTypeSans-VarGX.ttf');
font-weight: 0 1000;
font-display: swap;
}
-
Purpose: The
@font-face
rule allows you to define a custom font. - Font Name: The font is named 'Kyiv Sans'.
-
Source: The font file is located at
/font/KyivTypeSans-VarGX.ttf
. - Font Weight Range: This font supports a range of weights from 0 to 1000, making it a variable font.
-
Font Display:
swap
ensures that text is displayed immediately using a fallback font until the custom font loads.
Styling the <h1>
Element:
h1 {
color: #bd0c0c;
height: 100vh;
display: grid;
place-content: center;
margin: 0;
text-align: center;
}
-
Color: Sets the text color to
#bd0c0c
, a shade of red. -
Height: The height is set to
100vh
, making the<h1>
element span the full height of the viewport. -
Display:
grid
is used for layout, allowing the use of grid properties. -
Centering Content:
place-content: center
centers the content both vertically and horizontally. -
Margin: Margin is set to
0
to remove any default spacing around the<h1>
. - Text Alignment: The text is centered horizontally.
Styling the .variable-font
Class:
.variable-font {
font-family: 'Kyiv Sans';
font-size: 5rem;
line-height: 1.1;
font-weight: 100;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
- Font Family: Uses 'Kyiv Sans' for the text.
-
Font Size: Sets the font size to
5rem
(relative to the root element’s font size). -
Line Height:
1.1
ensures a slight spacing between lines. -
Font Weight: Initially set to
100
. -
Font Variation Settings: Utilizes custom variation settings for the variable font:
-
'wght'
controls the weight (initially 100). -
'CONT'
and'MIDL'
are custom axes for this font, initially set to 250 and 0, respectively.
-
- Transition: Smoothly transitions the font variation settings over 500 milliseconds.
Adding Hover Effect for .variable-font
:
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
-
Font Weight on Hover: Changes to
1000
when the element is hovered over. -
Font Variation Settings on Hover: Updates the variation settings to:
-
'wght'
to1000
-
'CONT'
remains250
-
'MIDL'
changes to-1000
-
- Effect: Creates a dynamic and interactive visual effect when the user hovers over the text, highlighting the flexibility of the variable font.
At the end of it we'll have our Result looking somewhat like this;
Creating Responsive Typography with Variable Fonts
By allowing designers to achieve perfect adaptation across many devices and screen sizes, responsive typography with varied fonts transforms online design. Unmatched versatility comes from variable fonts, which allow constant changes in font attributes including weight, width, and contrast within a single font file. Designers can dynamically change these font attributes to improve readability and aesthetic appeal using CSS and media queries, ensuring that text looks best on any device, from desktop monitors to cellphones. Because a single variable font can replace several stationary font files, it reduces the need for extensive font loading and improves website performance. This flexibility not only improves the user experience but also streamlines the design process. Without responsive typography—which becomes more appealing, efficient, and accessible with different fonts—modern web design cannot exist.
Media Queries: The Masters of Screen Size Adaptation
Media queries are a cornerstone of responsive web design, acting as the masters of screen size adaptation. Based on the features of the user's device—such as screen width, height, resolution, and orientation—they let designers apply particular CSS styles. Media searches help designers make sure a website looks and operates as best it can across a variety of devices, from laptops and desktop monitors to smartphones and tablets.
Media queries' power resides in their capacity to produce flexible and fluid layouts that fit various screen sizes. Media queries let a designer change font sizes, alter grid layouts, and even hide or show certain items based on the viewport
measurements. This ensures that the material maintains its aesthetic appeal and accessibility, regardless of the device in use.
Media queries define breakpoints—specific places at which the layout adjusts to fit varying screen sizes. Targeting different devices, these breakpoints are set using min-width
, max-width
, and other CSS characteristics. For example, a media query might specify the use of a mobile-friendly layout for screen widths of 768 pixels or less and a different layout for larger displays.
Incorporating media searches into web design improves accessibility and user experience. On all platforms, media queries assist in developing inclusive digital experiences by guaranteeing that text is readable, navigation is intuitive, and material is well organized. Any web designer hoping to create responsive, adaptable, and user-friendly websites must first learn media queries in the era of varied device use.
Here's an example:
body {
font-family: 'Kyiv Sans';
}
@font-face {
font-family: 'Kyiv Sans';
src: url('/font/KyivTypeSans-VarGX.ttf');
font-weight: 0 1000;
font-display: swap;
}
h1 {
color: #bd0c0c;
height: 100vh;
display: grid;
place-content: center;
margin: 0;
text-align: center;
}
.variable-font {
font-family: 'Kyiv Sans';
font-size: 5rem;
line-height: 1.1;
font-weight: 100;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
/* Media Queries */
/* Small screens */
@media (max-width: 600px) {
.variable-font {
font-size: 3rem;
font-variation-settings:
'wght' 100, 'CONT' 150, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 900;
font-variation-settings:
'wght' 900, 'CONT' 150, 'MIDL' -900;
}
h1 {
font-size: 2rem;
}
}
/* Medium screens */
@media (min-width: 601px) and (max-width: 1200px) {
.variable-font {
font-size: 4rem;
font-variation-settings:
'wght' 100, 'CONT' 200, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 950;
font-variation-settings:
'wght' 950, 'CONT' 200, 'MIDL' -950;
}
h1 {
font-size: 3rem;
}
}
/* Large screens */
@media (min-width: 1201px) {
.variable-font {
font-size: 5rem;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
h1 {
font-size: 4rem;
}
}
In this example, we used media queries to adjust the font-variation-settings
and weight of our font based on screen size. For devices with a maximum width of 600px
, the font size is reduced to 3rem
. The weight and other variations are adjusted accordingly for :hover
effects, For devices with a width between 601px
and 1200px
, the font size is set to 4rem
, with adjusted weight and variations. For devices with a width of 1201px
and above, the font size is 5rem
, maintaining the original settings.
These media queries ensure that the font adapts to different screen sizes, improving readability and the user experience across various devices.
The image above shows the display for Small screens
The image above shows the display for Medium screens
The image above shows the display for Large screens
Viewport Units: Making Layouts Fluid
Viewport units are a powerful tool in modern web design, enabling the creation of fluid and responsive layouts that adapt seamlessly to different screen sizes. Viewport units include vw
(viewport width) and vh
(viewport height), which are relative to the dimensions of the browser's viewport. One vw
equals 1% of the viewport's width, and one vh
equals 1% of the viewport's height. These units help designers guarantee that elements scale according to the size of the user's screen, therefore producing a more dynamic and adaptable design. Setting the font size, padding, or margins in viewport units, for example, lets text and objects resize automatically, therefore preserving a consistent look on several devices. This adaptability enhances the user experience by ensuring content remains readable and aesthetically pleasing, regardless of the site's display on a large desktop monitor or a small mobile screen. Viewport units let designers create adaptable layouts that move easily to fit the always-changing terrain of digital gadgets.
Here's an example of how to use vw
to adjust font size based on viewport width:
body {
font-family: 'Kyiv Sans';
}
@font-face {
font-family: 'Kyiv Sans';
src: url('/font/KyivTypeSans-VarGX.ttf');
font-weight: 0 1000;
font-display: swap;
}
h1 {
color: #bd0c0c;
height: 100vh;
display: grid;
place-content: center;
margin: 0;
text-align: center;
}
.variable-font {
font-family: 'Kyiv Sans';
font-size: 5vw;
/* Using viewport width for font size */
line-height: 1.1;
font-weight: 100;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
/* Media Queries */
/* Small screens */
@media (max-width: 600px) {
.variable-font {
font-size: 8vw;
/* Larger font size for small screens */
font-variation-settings:
'wght' 100, 'CONT' 150, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 900;
font-variation-settings:
'wght' 900, 'CONT' 150, 'MIDL' -900;
}
h1 {
font-size: 6vw;
/* Adjust h1 size for small screens */
}
}
/* Medium screens */
@media (min-width: 601px) and (max-width: 1200px) {
.variable-font {
font-size: 6vw;
/* Adjust font size for medium screens */
font-variation-settings:
'wght' 100, 'CONT' 200, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 950;
font-variation-settings:
'wght' 950, 'CONT' 200, 'MIDL' -950;
}
h1 {
font-size: 5vw;
/* Adjust h1 size for medium screens */
}
}
/* Large screens */
@media (min-width: 1201px) {
.variable-font {
font-size: 5vw;
/* Adjust font size for large screens */
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
}
.variable-font:hover {
font-weight: 1000;
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
h1 {
font-size: 4vw;
/* Adjust h1 size for large screens */
}
}
In this example, from the code above, the font-size property of .variable-font
is set using viewport width vw
units, making the text size responsive to the viewport's width.
We can combine media searches and viewport units with varying font characteristics to create truly responsive typography that elegantly fits every device or screen size. This enables us to provide an outstanding user experience, independent of the method of access someone chooses for our website.
Advanced Typographic Effects with Variable Fonts
Variable fonts enable designers to create highly customized and dynamic text styles by opening up a new field of complex typographic effects. Designers can now create seamless transitions and unusual visual effects that were previously difficult with stationary fonts by continuously adjusting characteristics such as weight, width, and custom axes. The weight, contrast, and midline dynamically can be changed by adjusting the font, offering complex control over the text look. This adaptability is very strong in responsive design, in which typefaces can easily adjust to various screen sizes and orientations. Moreover, interactive animations allow text to respond to user actions such as hovering or clicking, producing intriguing and immersive encounters. Viewport units, combined with varying font characteristics, ensure that typography remains fluid and scalable, improving readability and appearance on all kinds of devices. Using these sophisticated features, designers can create visually striking digital material by stretching the possibilities of conventional typography. Let's explore some fascinating methods for stretching the bounds of online typography:
Fluid Typography
Fluid typography is a design method whereby text scales dynamically with the viewport's size, therefore offering a smooth and responsive reading experience across many devices. Viewport units, media searches, and changeable fonts let fluid typography ensure that text stays intelligible and visually balanced, independent of screen size. This method eliminates the need for fixed font sizes and allows for seamless changes, thereby improving readability and appearance in a way that fits very different display conditions.
Here's an example:
/* Base font styles */
body {
font-family: 'Kyiv Sans', sans-serif;
line-height: 1.5;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
/* Fluid Typography for Heading and Body Text */
h1 {
font-size: calc(2rem + 2vw);
/* Fluid font size that scales with viewport width */
margin: 0;
text-align: center;
color: #bd0c0c;
}
h2 {
font-size: calc(1.5rem + 1.5vw);
/* subheadings Fluid font size */
margin: 1rem 0;
color: #555;
}
p {
font-size: calc(1rem + 0.5vw);
/* paragraphs Fluid font size */
margin: 0 0 1rem 0;
line-height: 1.6;
}
/* Fluid Typography for Variable Fonts */
.variable-font {
font-family: 'Kyiv Sans';
font-size: calc(1rem + 1vw);
/* Fluid font size */
font-variation-settings:
'wght' 400, 'CONT' 200, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
.variable-font:hover {
font-variation-settings:
'wght' 700, 'CONT' 250, 'MIDL' -100;
}
How it works:
calc() Function: This function generates a fluid scaling effect by combining relative units vw
, with fixed values rem
. font-size
, for instance, calc(2rem + 2vw)
reacts to the viewport width and assures a base size.
Fluid Typography for Various Elements: Many elements such as h1
, h2
, and p
guarantee text scaled suitably across devices using fluid typeography. The calc()
function provides a base size with a scaling factor that changes with the viewport width.
Variable Fonts: By combining fluid typography with changeable fonts, you can achieve dynamic changes in text attributes depending on viewport size.
This method guarantees that text stays aesthetically pleasing and readable across a large spectrum of devices and screen sizes.
By animating text, kinetic typography gives it life and generates interesting and dynamic visual effects that enthrall viewers. This method adds motion and interaction by changing text attributes using JavaScript and CSS animations. Using a :hover
effect to animate the font weight in our example with the variable font, we demonstrated kinetic typography—that is, seamlessly from lighter to bolder weights. This not only emphasizes the content but also shows how, with fluid, real-time changes, varying fonts may improve user interactions. Kinetic typography allows designers to improve the visual attractiveness and usability of their text, enhancing its fundamental role in an interactive and interesting digital environment.
Example: Animating Weight on Hover
.variable-font {
font-family: 'Kyiv Sans';
font-size: 5rem;
line-height: 1.1;
font-weight: 100;
font-variation-settings:
'wght' 100, 'CONT' 250, 'MIDL' 0;
transition: font-variation-settings 500ms;
}
.variable-font:hover {
font-weight: 1000;
/* Animate the weight from light to bold on hover */
font-variation-settings:
'wght' 1000, 'CONT' 250, 'MIDL' -1000;
}
Here, we use a smooth transition to animate the weight of the .variable-font
element from regular 100 to bold 1000 on :hover
, creating a subtle yet impactful effect.
These are only a handful of the imaginative opportunities that different fonts offer. From dynamic animations to fluid layouts, there is ample opportunity for distinctive and intriguing typefaces. With a little inventiveness and CSS understanding, we can challenge web design norms and produce rather remarkable user experiences.
Conclusion
Variable fonts—best demonstrated by Kyiv Sans
transform typography on the web by grouping several font styles into a single file. By lowering the number of HTTP queries, this invention simplifies processes, increases design flexibility, and boosts performance. Designers can fully utilize changeable fonts in CSS to produce responsive, dynamic typefaces that fit perfectly with various screen sizes and user interactions.
Designers can create visually appealing and easily accessible typographic experiences using attributes such as weight, middle layer effects, and contrast, as well as responsive approaches such as media queries and viewport units. Variable fonts are a necessary tool for contemporary web design since their fluidity enables new directions for artistic expression.
Resources
- Check out the live preview hosted on Netlify
- View Source code
Top comments (1)
Comprehensive guide! Thanks a lot!!