How do you wrap long words in CSS?

How do you wrap long words in CSS?


How do you wrap long words in CSS?

Horizontal text overflow has always been difficult to manage on the web. The default visible overflow is designed to make sure content remains accessible no matter the size of a containing box, but it’s not our only option. We can now use overflow-wrap to control how words break – and combine that with hyphens to make wrapped text more readable. The solutions aren’t perfect yet, but Miriam Suzanne will walk you through the options we have, and how to use them.

- MDN Overflow-Wrap: https://developer.mozilla.org/en-US/d
- MDN Hyphens: https://developer.mozilla.org/en-US/d
- CodePen Demo: https://codepen.io/mirisuzanne/pen/GR

#webdesign #CSS #graphicdesign


Content

0 -> a common problem in CSS is how to handle
7.74 -> text overflow it's represented in the
10.95 -> popular CSS is awesome meme where we've
14.519 -> set the width of the box to be smaller
17.22 -> than the width of our widest word and so
20.34 -> that word is overflowing the box so
22.8 -> there are various ways to solve this we
24.57 -> can set overflow to hidden we can set
27.75 -> text overflow to ellipsis something like
31.949 -> that but another thing that we can do is
34.26 -> use this property overflow wrap and
36.78 -> we're going to set it here to break word
40.219 -> and you can see that now the word
42.78 -> awesome is breaking as many times as it
45.539 -> needs to in order to fit into the box
49.98 -> that's the proper way to break words so
52.98 -> there's actually several different
54.989 -> values that we can use for overflow wrap
58.19 -> by default overflow wrap is normal we
61.92 -> can set it to break word like we did we
63.6 -> can also set it to anywhere which is a
65.97 -> new value that has a little bit less
67.71 -> support is a little bit more aggressive
71.04 -> right now it looks like break word and
73.71 -> anywhere are doing basically the same
75.21 -> thing but they really change is how men
77.34 -> content is calculated so if we set the
80.909 -> width of each of these boxes these
82.86 -> paragraphs to min content you can see
85.92 -> that the one that has overflow wrap set
88.71 -> to anywhere is now breaking everywhere
92.07 -> that it can which is after one or two
95.189 -> letters so that it can get as small as
98.4 -> possible so the difference between break
100.799 -> word and anywhere is just how small the
103.74 -> box would be by default at its minimum
106.979 -> this is really similar to the word break
109.32 -> property although this is the proper one
111.84 -> to use for solving overflow issues the
115.35 -> word break property is really
118.38 -> specifically built to handle specific
120.899 -> languages that have slightly different
123.81 -> rules about word breaking so in most
127.079 -> cases you're going to want to use
128.22 -> overflow wrap you can also then add
131.039 -> hyphens let's just do that
136.49 -> and we can either set hyphens to manual
140.15 -> which will look for places that we've
142.91 -> built in hyphens like I did here in the
145.16 -> middle of antidisestablishmentarianism I
147.83 -> just added this and shy and that shy -
153.35 -> will only appear when we set hyphens to
155.6 -> manual I can also set hyphens to auto so
160.07 -> hyphens Auto is going to try to auto
162.29 -> generate hyphens based on the language
164.59 -> based on the dictionary provided in the
168.17 -> browser or in the operating system and
170.84 -> that support is going to be different
172.28 -> per language and per browser but that's
174.98 -> only going to work if I explicitly set
177.53 -> the language which I should normally do
181.19 -> on the HTML element here just for
184.16 -> demonstration purposes I'm doing it on
185.9 -> main you can see how they're added and
188.24 -> removed based on the presence of the
190.7 -> language hopefully that's useful have
193.22 -> fun setting text
195.47 -> [Music]
205.61 -> you

Source: https://www.youtube.com/watch?v=UOKQ6gw21NA