How to Use Custom Fonts in CSS

CSS @font-face registers a downloadable or local font resource under a family name.

Overview

CSS @font-face registers a downloadable or local font resource under a family name.

Practical approach

Define a font-family name, a permitted font source, and appropriate weight and style descriptors. Reference the family in a CSS font-family stack with a readable fallback. WOFF2 is a common web delivery format.

What to check

Verify web embedding rights, test the network response and character coverage, and avoid unnecessary downloads. Use font-display behavior appropriate to the layout.

Example CSS

@font-face {
  font-family: "Example";
  src: url("/fonts/example.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
body { font-family: "Example", system-ui, sans-serif; }

The file path is illustrative; replace it with your licensed font resource.

References

Reference: MDN @font-face reference.

Related tools and reading

Explore related tools and references