I like to decouple data from its visual presentation whenever I can. So, if I get “basketball Game”, “basketBall game”, or “BASKETBALL GAME” from an API, and I want it displayed sentence-style as “Basketball game” without any scripting, how do I do that?
You might try this:
h1 {
text-transform: capitalize;
}
However, this turns “basketball game” into “Basketball Game” with a capitalized “G”. This violates Microsoft’s sentence-capitalization style, and it’s not what I want. Here’s how you transform any capitalization to sentence-style.
/* All letters lowercased */
h1 {
text-transform: lowercase;
}
/* First letter uppercased */
h1::first-letter {
text-transform: uppercase;
}
This gives us “Basketball game” no matter what capitalization we receive.