InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS properties

  • CSS3 flexbox
  • all
  • animation
  • background-color
  • background-image
  • border
  • border-color
  • border-radius
  • border-style
  • border-width
  • bottom
  • box-shadow
  • box-sizing
  • calc function
  • clip
  • color
  • color value currentColor
  • color values
  • cursor
  • float
  • font
  • font-family
  • font-size
  • font-style
  • font-variant
  • font-weight
  • generated content
  • left
  • letter-spacing
  • line-height
  • list-style
  • list-style-image
  • list-style-position
  • list-style-type
  • margin
  • max-height
  • max-width
  • min-height
  • min-width
  • opacity
  • outline
  • outline-color
  • outline-style
  • outline-width
  • overflow
  • padding
  • pointer-events
  • position
  • resize
  • right
  • text-align
  • text-decoration
  • text-indent
  • text-overflow
  • text-shadow
  • text-transform
  • top
  • transform
  • transition
  • transition-delay
  • transition-duration
  • transition-property
  • transition-timing-function
  • visibility
  • white-space
  • word-break
  • word-spacing
  • word-wrap/overflow-wrap
  • z-index
 
  • Home
  • > Tutorials
  • > CSS
  • > CSS properties

CSS font shorthand property

on Apr 18, 2016

The CSS font property is a shorthand property for setting font-style, font-variant, font-weight, font-size, line-height and font-family.

CSS property font

CSS version: CSS 2.1
Value: [ [ font-style || font-variant || font-weight ]? font-size [/line-height]? font-family ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
Initial: see individual properties
Applies to: all elements
Inherited: yes

font values

Few points to note:

  1. First three values are optional (font-style, font-variant, font-weight). If not specified, these take normal value.
  2. line-height is also optional
  3. font-family can have multiple comma separated values to have fall back fonts families. In case first font-family is not available, next one is taken and so on.

Some font shorthand values:

p { font: 12px/14px sans-serif; }
p { font: 80% sans-serif; }
p { font: normal small-caps bold 12px/14px sans-serif; }
Valid values for system predefined fonts. Note that system fonts may only be set as a whole.
captionThe font used for captioned controls (e.g., buttons, drop-downs, etc.).
iconThe font used to label icons
menuThe font used in menus (e.g., dropdown menus and menu lists).
message-boxThe font used in dialog boxes.
small-captionThe font used for labeling small controls.
status-barThe font used in window status bars.

font shorthand example

In the following code, CSS property font can be changed to the following values
  • 12px/14px sans-serif
  • 12px/18px sans-serif
  • 80% sans-serif
  • 100% sans-serif
  • normal small-caps bold 12px/14px sans-serif
  • caption
  • icon
  • menu
  • message-box
  • small-caption
  • status-bar
<style type="text/css">
div {
  width: 100px;
  font: 12px/14px sans-serif;
}
</style>
<div>This is sample text to test font shorthand property</div>
font refresh done
try it online

Related

  • CSS font-style
  • CSS font-variant
  • CSS font-weight
  • CSS font-size
  • CSS font-family

Specification

  • W3C CSS 2.1 font specification

Suggested posts:

  1. CSS font-size
  2. CSS pointer-events – disable click on an element
  3. CSS font-style
  4. How to install and run Chrome PageSpeed insights for measuring site performance
  5. CSS font-variant
  6. CSS font-weight
  7. Logo creation high level checklist
  8. CSS universal selector
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged CSS, CSS properties, Tutorials, Web Development
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress