Basics of web development

CSS Fonts

Easy
20 min

Using CSS fonts allows for modifying the appearance of text on web pages. This can include specifying the font name, size, style, and color. Here are a few examples of using CSS fonts:

Defining the Font Name

You can define the font name in CSS by using the font-family property. For example, if you want to use the Arial font, you can write the following rule:

body {
  font-family: Arial, sans-serif;
}

This rule sets Arial font for the text that is displayed in the body element.


Determining font size

You can define the font size in CSS using the font-size property. For example, if you want to set the font size to 14 pixels, you can write the following rule:

h1 {
  font-size: 14px;
}

Determining Font Style

You can define the font style in CSS by using the font-style property. For example, if you want to set the font to italic, you can write the following rule:

em {
  font-style: italic;
}

Setting the font color

You can define the font color in CSS by using the color property. For example, if you want to set the text color to blue, you can write the following rule:

p {
  color: blue;
}

This rule sets the text color to blue for all paragraph elements.

The use of CSS fonts gives you plenty of possibilities for formatting and styling text on web pages. It is important to note that although a font name can be specified in the website's code, the user's device must have the font installed in order for it to display correctly for the user.

Practice

Kokeile itse!

Valitettavasti Replit-palvelu on muuttnut lennosta eikä enää anna suorittaa näitä koodeja suoraan selaimessa. Voit klikata alla olevaa "Open in Replit" linkkiä ja avata koodin Replit-palvelussa. Meillä on työn alla etsiä Replitille korvaaja.

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.