External Publication
Visit Post

Antidatalossconfigurationism

Donnie D'Amato July 8, 2025
Source
I’m in the middle of deep thought about what a text component looks like. There’s the easy stuff like having the ability to choose the appropriate semantic element. There’s the less obvious stuff, like adding a flag for screenreader only content. But then there’s something that we tend to overlook, how to manage overflow content. Data loss It’s not uncommon for someone to choose the solution of clipping the content, maybe in the form of an ellipsis. We even have more options coming about when those ellipsis appear. The problem with approaches that include is that the content is no longer clearly accessible. This goes against a core principle of mine: if you place it on the page, that means it is important. There should be no condition that obstructs that element in any way. Otherwise that can introduce data loss. Adding ellipsis is not an inclusive solution to large blocks of text. Instead, we’ll need to ensure the text remains readable while balancing the expectations of the layout. Properties There’s several CSS properties that are directly related to the way text flows on a webpage. We’ll go over each of the properties below but first a few definitions: Whitespace refers to characters that provide space between other characters. Segment breaks are characters that cause text to break onto new lines (eg., line feed). Hard breaks (aka: forced line break) will always cause the text to break onto a new line, even if it is not necessary to do so. Soft breaks will cause text to break to a new line only if necessary. Where these can occur are called soft wrap opportunities. Line box describes the inline formatted box, typically used to contain text. The size of this box depends on the content and the available size of its ancestors. CJK is short for Chinese/Japanese/Korean used to describe text that has a different ruleset for when strings are allowed to break. This property has been around for a while, but recently it has been altered to host separate properties. Overall, this property and its related new properties are meant to handle how whitespace characters effect the surrounding text. First, the property has the following possible values: says that all whitespace should be collapsed. How whitespace is collapsed follows several algorithmic steps. says whitespace and segment break characters are perserved. This is commonly seen as the default in the HTML element style. says only preserve segment breaks, whitespace characters are collapsed. does the opposite of by allowing segment breaks to be collapsed and perserve whitespace as written in source. is the most unique of the values with a more specific set of rules for how whitespace is perserved. Remember that is only one part of the property. The other part is which only has two values, and . As you might expect, you’ll primarly want to have and this is the default. When considering the keyword options provided by the original property, it’s not immediately clear how they align to these values: is . is . is . is . There is no keyword analog under to get behavior. At the time of this writing, this is only available in Firefox. To make things more confusing, is also a shorthand. We already saw one of the properties which determines if the text is allowed to wrap or not. The newer part to this is which has added many of the fancy algorithmic ways that text can wrap based on the number of characters. Here are the values for this property: wraps the text in the most performant way and ignores the number of characters. This is the default. attempts to wrap in away that keeps the number of characters roughly equal amongst the lines of text. This is best used for headlines. is similar to balance but favors layout over speed. This is best used for paragraphs of text. is meant to be applied in areas where the user is editing content and wrapping should be kept to a minimum during this time. Harry Roberts posted some benchmarks on using the newer values. The setup was a page with 10,000 elements which, by default, have orphans. Here’s what he found: Baseline – 1,186ms : 1,224ms (38ms/3.2% longer) : 1,310ms (124ms/10.5% longer) He said that impact on was almost zero, while is more noticeable. The reality is that you most likely won’t have 10,000 paragraphs on your page. The properties so far are only configuring how the whitespace characters behave in a block of text. None of these properties will affect the strings of characters that typically behave as words. The following properties are meant to target when these strings are meant to break and avoid poor layout artifacts. The property helps tell the browser when it should insert line breaks in otherwise unbreakable strings of text to prevent overflowing. This is an alias of the property. Originally, this only allowed two values the default which keeps strings in tact and which will break words sometimes. When a word is meant to break depends on the width of the container and where soft breaks can exist. This is usually very helpful for places where a long URL is written that needs to be broken to maintain a reasonable text layout. The newer value option is which is typically less desirable as soft wrap characters are also used to determine how big the line box should be. This will allow the box to be much smaller instead of trying to fill the box as is normally expected. Continuing with the theme of confusingly similar CSS properties, is a property that determines what happens when a string would overflow outside of its container. To make things worse, one of the values here is an override to . We’ll start with that one: is identical to and takes priority over any other value provided to . says to use normal line break rules which may also break between CJK characters. will cause a break to occur at the place where overflow would occur. same as except CJK characters will also not break. same as but analysizes the language to avoid breaking natural phrases. A question you might have, what’s the difference between all of these properties? They all look like they handle the same sort of consideration for breaking strings of text. The CSSWG has an excellent breakdown of the differences: The property allows choosing various levels of “strictness” for line breaking restrictions. The property controls what types of letters are glommed together to form unbreakable “words”, causing CJK characters to behave like non-CJK text or vice versa. The property controls whether automatic hyphenation is allowed to break words in scripts that hyphenate. The property allows the user-agent to take a break anywhere in otherwise-unbreakable strings that would otherwise overflow. On top of the other properties that we didn’t cover, there’s a lot more detail within that page about how line breaks are expected to work. I’ve made a little playground to see how the properties would affect text samples combined from MDN examples: See the Pen Antidatalossconfigurationism by Donnie D’Amato (@fauxserious) on CodePen. Recommendations Based on all of this, here’s how I’d try making an API for a text component when it comes to avoiding data loss. Here’s my considerations: Create a flag with the following values: (default) if the tag name used expects a certain value, use that style. For example, for shorter text and for longer text. is the same as . is the same as . Create a flag with the following values: (default) sets on text by default. This will allow the presence of long URL to break nicely when within the text. Josh Comeau includes this in his CSS reset. is the same as . is the same as . Here’s what the CSS might look like: I’m using the keyword value for over the shorthand because it’s easier to update this value instead of unsetting it to reapply in some cases. This allows us to leverage the default of for most elements. The elements I’ve chosen to receive are based on their expected content. Elements that expect shorter amounts of content receive while elements that expect longer amounts use . Note that these are targeting elements that would normally have content as their direct children. While you could put on sectioning content for it to cascade, it’s more performant to be more specific. If you were paying attention, you’ll notice that there’s a lot of property values that we went over which are missing from the API. The reason is that they’re probably not going to be useful in day-to-day web development. This isn’t meant to be a CSS reset, this is an opinionated setup for what I believe would be a text component that allows for some customizability while keeping the options limited. This includes my own rule-breaking for use of in this case to call out that hiding overflow on text is a bad practice. Makes me want to set on all my elements too.

Discussion in the ATmosphere

Loading comments...