What is the best way to wrap text intentionality

This might seem like a dumb question but I always feel like I'm doing this wrong. If I have a h1 for example and I want to wrap it over 2 lines for design purposes is the best way to use a br tag or max-width? I feel like both of those solutions aren't great so if there's a better way to do this please let me know 🙂
35 Replies
ἔρως
ἔρως3mo ago
what's the text?
alec
alecOP3mo ago
You want me to post a screenshot?
b1mind
b1mind3mo ago
demo is best but would help I will use <br> for things like that but #depends
ἔρως
ἔρως3mo ago
no, just the text and how you intend to split it and if the "split" text will have a different style or not
alec
alecOP3mo ago
from the design file
No description
ἔρως
ἔρως3mo ago
yeah, i would throw a <br> in there or, better yet: a <wbr> unless the "split" is a must
alec
alecOP3mo ago
Yeah also because at mobile devices that text stays the same in terms of how many words are on each line, Although lets say it was different at smaller screen sizes what would you do?
b1mind
b1mind3mo ago
clamp probably Just make the h1 smoler xD unless you want to have it be one word per line
alec
alecOP3mo ago
hmm ok thx I use clamp normally but sometimes I can't get the right amount of words on each line and it can be annoying lol
b1mind
b1mind3mo ago
No description
No description
b1mind
b1mind3mo ago
Like it should still wrap fine but if you want to keep the design the same for mobile being two words per break then ya either clamp or just change the fontsize in a media query
ἔρως
ἔρως3mo ago
in the worst case scenario, use an svg
b1mind
b1mind3mo ago
noooooo not for a h1 xD
ἔρως
ἔρως3mo ago
you can
b1mind
b1mind3mo ago
well #depends
ἔρως
ἔρως3mo ago
it's valid and the text is supposed to be readable
b1mind
b1mind3mo ago
it is but you would need to still use aria yes?
ἔρως
ἔρως3mo ago
very likely
b1mind
b1mind3mo ago
<text> does not read out faik
ἔρως
ἔρως3mo ago
don't know if browsers are too happy about it
b1mind
b1mind3mo ago
Its SEO friendly but not a11y which erks me
alec
alecOP3mo ago
?? People do that?
ἔρως
ἔρως3mo ago
but since it is a design element and not a title, maybe .......
b1mind
b1mind3mo ago
op said h1 for design elements yes because SVG scales really well
ἔρως
ἔρως3mo ago
sometimes, because you can't (yet) make a text take the entire width of the element without adding weird space between the letters
alec
alecOP3mo ago
yeah but not for a h1 lol unless?
ἔρως
ἔρως3mo ago
if you justify the text, it will look l i k e t h i s and that's unreadable
b1mind
b1mind3mo ago
yea I typically wouldn't for that design its just font so
ἔρως
ἔρως3mo ago
you can, but it's the bottom of the barrel of the options when you're trully extremely desperate for any solution for this, not a good idea
alec
alecOP3mo ago
thx for the help 🫡
ἔρως
ἔρως3mo ago
you're welcome
alec
alecOP3mo ago
I should probably ask this too. When it comes to wrapping body text and getting the right amount of words on each line what's the best strategy there? Because normally I'd just use a max-width but idk?
ἔρως
ἔρως3mo ago
honestly, i wouldn't do anything
alec
alecOP3mo ago
you just let it wrap natually?
ἔρως
ἔρως3mo ago
maybe check text-wrap-style, to change how the wrapping behaves but otherwise, yes depending on the design

Did you find this page helpful?