Twitter’s div Soup and Uglyfied CSS, Explained

When I came up in web development (2005-2010 were formative years for me), one of the first lessons I learned was to have a clean foundation of HTML. “What Beautiful HTML Code Looks Like” is actually one of the most …


The post Twitter’s div Soup and Uglyfied CSS, Explained appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

When I came up in web development (2005-2010 were formative years for me), one of the first lessons I learned was to have a clean foundation of HTML. “What Beautiful HTML Code Looks Like” is actually one of the most popular posts on this very site. The image in that post made its way to popular pages on subreddits every once in a while.

Now, while I still generally write HTML like that by default when working on sites like this one, I also work on projects that don’t have HTML output like that at all. I don’t work on Twitter, but here’s what you might see when opening up DevTools and inspecting the DOM there:

DevTools looking at the DOM on twitter.com: tons of divs with obfuscated class names.

Nobody would accuse that of being “clean” HTML. In fact, it’s not hard to imagine criticism being thrown at it. Why all the divs! divitis!! Is that seriously a <div role="button"> c’mon now. Those are awful class names! Robot barf!

What’s probably closer to the truth is that it doesn’t actually matter that much. It’s not that semantics don’t matter. It’s not that accessibility doesn’t matter. It’s not that performance doesn’t matter. It’s that this output actually does things fairly well, or at least as well as they intend to do them.

Giuseppe Gurgone gets into the details.

React Native for Web provides cross platform primitives that normalize inconsistencies and allow to build web applications that are, among other things, touch friendly.

To the eyes of somebody who’s not familiar with the framework, the HTML produced by React Native for Web might look utterly ugly and full of bad practices.

That DOM actually does produce an accessibility tree that is expected and usable. The <div>s with roles are to overcome certain cross-platform styling limitations. Those classes are from a styling framework that helps with scoping CSS. It looks wacky, but it’s all for a reason.

That’s not to say all is the only criticism. You could argue that robotic class names don’t allow for user stylesheets that may assist with accessibility. You could argue the superfluous divs make for an unnecessarily heavy DOM. You could argue that shipping robot barf makes the web less learnable, particularly without sourcemaps.

There are things to talk about, but just seeing a bunch of divs with weird class names doesn’t mean it’s bad code. And it’s not limited to React Native either, loads of frameworks have their own special twists in what they actually ship to browsers, and it’s almost always in service of making the site work better in some fashion, not to serve in teaching or readability.

Direct Link to ArticlePermalink


The post Twitter’s div Soup and Uglyfied CSS, Explained appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-09-22T21:09:12+00:00) Twitter’s div Soup and Uglyfied CSS, Explained. Retrieved from https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/

MLA
" » Twitter’s div Soup and Uglyfied CSS, Explained." Chris Coyier | Sciencx - Wednesday September 22, 2021, https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/
HARVARD
Chris Coyier | Sciencx Wednesday September 22, 2021 » Twitter’s div Soup and Uglyfied CSS, Explained., viewed ,<https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/>
VANCOUVER
Chris Coyier | Sciencx - » Twitter’s div Soup and Uglyfied CSS, Explained. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/
CHICAGO
" » Twitter’s div Soup and Uglyfied CSS, Explained." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/
IEEE
" » Twitter’s div Soup and Uglyfied CSS, Explained." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/. [Accessed: ]
rf:citation
» Twitter’s div Soup and Uglyfied CSS, Explained | Chris Coyier | Sciencx | https://www.scien.cx/2021/09/22/twitters-div-soup-and-uglyfied-css-explained/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.