font
Published Jul 28, 2021Updated May 15, 2024
Contribute to Docs
The font
property is a shorthand property that sets different properties for an elements font in a single declaration.
Syntax
font: <values>;
The font
property can have the following properties as <values>
:
Required values:
font-family
font-size
Optional values:
line-height
font-weight
font-stretch
font-style
font-variant
Note: Some edge cases to keep in mind:
font-style
,font-variant
, andfont-weight
must come beforefont-size
.line-height
must be declared afterfont-size
and only following a forward slash.
Example 1
Setting an h1
elements font to Georgia italic, size of 10px, and line height of 40px in a single declaration.
h1 {font: italic 10px/40px Georgia, sans-serif;}
The above would be the same as:
h1 {font-style: italic;font-size: 10px;line-height: 40px;font-family: Georgia, sans-serif;}
Example 2
Setting an h2
font with all seven properties in one declaration.
h2 {/* font-stretch | font-style | font-variant | font-weight | font-size | line-height | font-family */font: expanded italic small-caps bolder 20px/30px cursive;}
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn CSS on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Career path
Full-Stack Engineer
A full-stack engineer can get a project done from start to finish, back-end to front-end.Includes 51 CoursesWith Professional CertificationBeginner Friendly150 hours - Free course
Learn CSS
In this CSS tutorial, you’ll learn how to add CSS to visually transform HTML into eye-catching sites.Beginner Friendly6 hours