How can I draw vertical text with CSS cross-browser?
To swiftly create cross-browser vertical text using CSS, resort to the writing-mode
property. Apply writing-mode: vertical-lr;
to your text for vertical orientation. Review this concise example:
Insert it in your HTML:
This CSS rule transforms text vertically, guaranteeing wide browser support.
Expanding the writing-mode
horizons
The writing-mode
property is mighty handy, but occasionally we need to rotate text for a specific visual effect or layout. Here's how:
To extend support to older versions of Internet Explorer (yeah, remember them!):
Check compatibility using the trustworthy caniuse.com, and don't neglect vendor prefixes for all your browser needs:
Precision and compatibility
Text orientation tweaks
Sometimes you simply need to rotate a single word or letter, and for that inline elements make the perfect partners:
SVG for exact positioning
When your design calls for pixel-perfect placement, it's time to break out the big guns: SVG text:
SVG offers text-anchor
and alignment-baseline
attributes for that much-desired precise control over text alignment and rotation.
Affection for old IE versions
Yes, we did mention those old fellows earlier! For Internet Explorer versions 6-8, conditional comments and the filter
property work wonders:
Advanced techniques on text rotation
Using writing-mode
for layout flow
Toggle writing-mode: vertical-lr;
or writing-mode: vertical-rl;
for orthogonal flows. Pairing this with text-orientation: upright;
ensures your characters stay upright during their vertical journey.
Positioning after rotation
Rotated pieces of text might need a little nudge to behave. Use absolute positioning or flexbox to adjust the location:
Catering mobile browsers
Don't forget your mobile audience! Different input methods and screen orientations call for responsive design tactics. Flexbox and grid can help create adapting layouts for vertical text elements.
Was this article helpful?