Adapting typography to consumer personal tastes with CSS


Bringing the consumer into the design procedure has been a thrilling time for customers, designers and builders. Customers can land for your revel in and seamlessly start eating content material, their personal tastes richly built-in into the design end result.

This weblog publish explores the usage of CSS media queries with a variable font to tailor the studying revel in even additional. Font grade and weight may also be custom designed with font-variation-settings, permitting microtuning given quite a lot of personal tastes and contexts, like a choice for darkish mode or top distinction. We will take those personal tastes and tailor a variable font for that consumer revel in.

  • Darkish mode will get a quite lowered gradation.
  • Top distinction will get a bolder font.
  • Low distinction will get a thinner font.
https://codepen.io/argyleink/pen/mdQrqvj

Apply alongside to grasp each and every portion of the CSS and variable font that permit this significant second!

Getting setup #

To lend a hand focal point at the CSS and font variation atmosphere values, but in addition give us one thing to learn and spot, here is the markup you’ll be able to use to preview the paintings:

<h1>Variable font weight in line with distinction choice&LT/h1>

<p>
Lorem ipsum dolor sit down amet consectetur adipisicing elit.
Officia, quod? Quidem, nemo aliquam, magnam rerum distinctio
itaque nisi nam, cupiditate dolorum advert sint. Soluta nemo
labore aliquid ex, dicta corporis.
&LT/p>

With out including any CSS, the font length is already adaptive to consumer personal tastes. Here is a video from any other demo appearing how atmosphere font-size in pixels will squash any consumer personal tastes, and why you will have to set your font length in rems:

Finally, to middle and beef up the demo, slightly CSS:

@layer demo.beef up {
frame {
show: grid;
place-content: middle;
padding: var(--size-5);
hole: var(--size-5);
}

h1 {
text-wrap: stability;
}
}

A screenshot preview of the demo so far, in both dark and light themes.

This demo setup permits you to start checking out and enforcing this neat typography UX function.

Loading the Roboto Flex variable font #

The adaptive technique depends upon a variable font with significant axes for personalisation, in particular you want GRAD and wght. The objective adaptive consumer personal tastes on this article are for coloration scheme and distinction, either one of which is able to tailor those axes to check the consumer’s desired choice.

Load the variable font the usage of the @font-face API of CSS:

@font-face {
font-family: "Roboto Flex";
src: url('https://belongings.codepen.io/2585/RobotoFlex') layout('truetype');
}

Subsequent, observe the font to a couple content material. The next CSS applies it to the entirety:

@layer demo.beef up {
frame {
font-family: Roboto Flex;
}
}

A screenshot preview of the demo so far, with the font now in Roboto Flex in both dark and light themes.

With the font loaded, you’ll be able to question for consumer personal tastes and adapt the variable font settings to check.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Back To Top
0
Would love your thoughts, please comment.x
()
x