155

What does the slash mean here:

font: 100%/120%;
2
  • 6
    font-size does not accept the slash. The correct property is font. Commented May 22, 2012 at 12:22
  • how about these? background: "rgba(0, 0, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box" Commented Nov 18, 2012 at 7:17

2 Answers 2

215

This actually sets two properties and is equivalent to:

font-size: 100%;
line-height: 120%;

To quote the official documentation:

The syntax of this property is based on a traditional typographical shorthand notation to set multiple properties related to fonts.

As David M said in the comments, it mirrors the typesetting tradition of specifying typeface sizes as “x pt on y pt” to denote the glyph size on line height.

But the example in your question is actually wrong and would be ignored by the browser: you can only combine these two properties in the font shorthand notation, and you must specify at least both the font size and family. Simply writing font: 100%/120%; is therefore not enough; you could add a generic family name to make it valid though, e.g.:

font: 100%/120% serif;
Sign up to request clarification or add additional context in comments.

5 Comments

It's to mirror old typesetting syntax, where you'd have font set as, for instance "10pt on 12pt", or "10pt/12pt".
I actually use this quite a bit. The designer I work with always refers to sizing as, for example, "14 over 22". I put it in by accident one day and was surprised/content when it worked.
a quickie: does this format also not require the font-family to be specified? My browsers are ignoring this property: font: 12px/16px; but accepting this: font: 12px/16px sans-serif; This behaviour is also documented here
@Harsh Yes, a family (along with a size) is minimally required for the font shorthand property as you can see in the official definition.
thanks for the clarification. Perhaps you can update the answer (or the question) as it is slightly misleading in that a casual reader can assume that only a SIZE/LINE_HEIGHT declaration would work.
15

Konrad got this one, but there are a lot of CSS shorthand properties like this that you can use to shorten your style sheets. Some of them look a little cryptic if you're not aware of them.

1 Comment

Most shorthands address related style properties, though (e.g. border-*). David has given a good explanation in the comments to my answer. As to shorthands being cryptic: certainly true, but so damn useful and quite easy to learn.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.