Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Last active April 13, 2024 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlebron/542eb5416730903661a91c8026b6ebb0 to your computer and use it in GitHub Desktop.
Save shaunlebron/542eb5416730903661a91c8026b6ebb0 to your computer and use it in GitHub Desktop.
CSS typography

CSS Typography

We can do typographic things in CSS that we couldn’t before.

Hanging Indent

text-indent: 2em hanging; /* Safari and Firefox only */
This is a sentence that   |
   will be indented after |
   the first line when    |
   wrapped to multiple    |
   lines.                 |

or:

text-indent: 2em hanging each-line;  /* Safari and Firefox only */
A stanza can have multiple |
   lines.<br>              |
The second line should be  |
   indented as the first.  |

Drop Cap

::first-letter {
  initial-letter: 2; /* not supported by Firefox */
}

Hanging Punctuation

hanging-punctuation: first; /* Safari only */
“This is a quote where the first quotation mark
 will hang outside to allow the leftmost words to align.”

Orphans

orphans: 2; /* not supported by Firefox */

before:

Don’t let the last line of a |
paragraph have just a single |
word.

after:

Don’t let the last line of a |
paragraph have just a        |
single word.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment