loading

Fonts - Basics| Hitchhikers Platform

What You’ll Learn

In this section, you will learn:

  • What are fonts and how are they used?
  • CSS Properties that control fonts

Introduction to Fonts

Fonts are an important part of a website’s branding. They control how the text on your Answers experience is rendered. Although Answers will default to system-available fonts, you can update the fonts on your experience through CSS to make it more in line with your brand’s fonts.

Fonts are considered assets, just like an image you display on your website might be. Not all operating systems automatically have all fonts downloaded, so we need a way to make sure a browser is able to access the fonts on your site, rather than using a font available on their computer system. We’ll walk through the ways you can load in these font assets in the following unit, but first, let’s walk through the standard properties of a font.

Remember, you can inspect the page to determine the fonts a section of a webpage is using! This will be helpful to play around with real-world examples.

Common Font Properties

Here are a few of the CSS properties you’ll be interacting with as you change your fonts.

Font Family

The font family attribute lets you define the font for a given element. The property can hold several fonts as ‘fall-backs’ if a browser isn’t able to render one of the preferred fonts. In the below example, if Arial is not available, the browser will use Helvetica. If neither are available, it’ll use sans-serif, a generic font.

--yxt-font-family: Arial, Helvetica, sans-serif;

You can see below the font-family we’re using on this very page! Try removing ‘Gilroy’ to see what happens to the text.

CopyCopied!
a { font-family: Gilroy,Helvetica,Arial,sans-serif; }

The Answers Library stores the default font family in a variable, which is then used across the entire Answers experience. You’ll learn how to override this font in the next unit.

--yxt-font-family: system-ui,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif !default;

Font Weight

This controls the heaviness, or boldness of the font. You can define the font-weight through keywords: normal, bold, bolder, or lighter.

CopyCopied!
a { font-weight: bold; &:hover { font-weight: normal; } }

You can also define font-weight using numbers - 100, 200, 300, 400, 500, 600, 700, 800, and 900. 400 is the same as ‘normal’, and 700 is the same as ‘bold’. Not all fonts will have each font-weight defined, but you can play around in the editor to see the effects it has.

CopyCopied!
a { font-weight: 400; &:hover { font-weight: 700; } }

Font Style

This can be used to italicize fonts. Play around with the properties below.

CopyCopied!
a { font-style: italic; &:hover { font-style: normal; } }

Font Face

The font face declaration isn’t a property in itself, but rather pulls all the properties of a font together. We define the font-face for every variation of a font we want to use.

The properties you’ll set are below:

Property Description
font-family The name of the font
src The URL where the font can be downloaded by the browser.
font-weight This records the weight of the font you’re importing
font-style This determines if the text is italicized or not

For the below example, we define Roboto Mono for different font weights (regular and bold) and italics.

@font-face
{
  font-family: "Roboto Mono";
  src: url('../../assets/fonts/robotomono-bold-webfont.woff') format("woff");
  font-weight: $font-weight-bold;
  font-style: normal;
}
 
@font-face
{
  font-family: "Roboto Mono";
  src: url('../../assets/fonts/robotomono-regular-webfont.woff') format("woff");
  font-weight: $font-weight-normal;
  font-style: normal;
}
 
@font-face
{
  font-family: "Roboto Mono";
  src: url('../../assets/fonts/robotomono-italic-webfont.woff') format("woff");
  font-weight: $font-weight-normal;
  font-style: italic;
}
 

For more on font-face declarations, visit this resource: https://www.pagecloud.com/blog/how-to-add-custom-fonts-to-any-website.

unit Quiz
+20 points
Daily Quiz Streak Daily Quiz Streak: 0
Quiz Accuracy Streak Quiz Accuracy Streak: 0
    Error Success Question 1 of 3

    What is the primary font used on this Hitchhiker website?

    Error Success Question 2 of 3

    Which are valid ways to define the font to be bold?

    Error Success Question 3 of 3

    What does a font-face allow you to do?

    High five! ✋

    You've already completed this quiz, so you can't earn more points.You completed this quiz in 1 attempt and earned 0 points! Feel free to review your answers and move on when you're ready.
1st attempt
0 incorrect
Splash Loading