r/webdevelopment • u/Sea-Blacksmith-5 • Nov 29 '24
Why Does CSS Even Exist? š§
Okay, hear me out. I know what CSS is supposed to doāstyling websites, making them look pretty, yada yada. But lately, Iāve been wondering... why does it exist in the first place?
HTML already does the basics (headings, paragraphs, links, etc.), and honestly, couldnāt styling have just been built into HTML? Like, instead of creating a whole separate language with its own weird quirks, why not extend HTML attributes to handle colors, fonts, and layouts directly?
CSS feels like an unnecessary middle layer that complicates things.
Writing stylesheets for one page can be a mess.
Classes, IDs, and inline styles sometimes clash, and specificity wars are the bane of my existence.
Donāt even get me started on browser inconsistencies.
What if we just scrapped CSS and came up with a simpler system? Something that combines content and styling without all the headaches. I canāt be the only one feeling this, right?
Is CSS just a necessary evil, or is there a better way weāre all ignoring? š¤ Let me know what you think.
TL;DR: Does CSS actually make sense, or is it just outdated design logic that weāre stuck with? Letās discuss.
19
u/averajoe77 Nov 29 '24
So, most of you are probably too young to remember this, but before css was a thing, styling was done in the html attributes.
Font, bgcolor, color,, width, height, were all html attributes. If you wanted a gradient you had to use an 1px wide gif image and repeat it across an element as a bg.
It made understanding how things were styled very difficult and of course it was very limited. Adding more html attributes meant longer parsing times for browsers and more cluttered html mark up. In order to make styling more robust and be able to evolve on its own apart from the html spec, making a styling language was a smart choice.
12
u/rastafaninplakeibol Nov 29 '24
It's different in ordet to isolate the structure of the page (HTML) from the styling. In this way you can change "theme" by just swapping a css file, if you had the style built in the html code you would have to rewrite half of the code. That's the logic
0
Nov 29 '24
[deleted]
6
u/mermaidslullaby Nov 29 '24
Basic HTML already has this. There's a reason that CSS was invented. It bloats the code, it makes it impossible to edit styling efficiƫntly and more.
0
u/katlaki Nov 29 '24
Like the above user said in a different context. Imagine you are having a baby girl. The hospital confirmed and the ultrasound confirms it too.
So you are excited and build a nursery and paint the walls of the nursery pink and various shades of pink as well as bought many baby stuffs in pink e.g milk bottles, bottle cleaner, dummies etc.
Come the delivery date, you are blessed with a baby boy. The hospital misdiagnosed your baby's gender.
In case of CSS, it is simply a swap of CSS so the milk bottles, dummies, walls, bottle cleaner will be blue.
Had everything been integrated in HTML, then you would have to buy everything, and make a new nursery.
Although, I believe the amount of CSS files I see in a website, I am not sure if a website really needs that amount of different CSS files.
4
Nov 29 '24
HTML was never meant to be anything other than semantic. It does nothing, never did. Browsers have built in styles, but HTML itself is just context...
here is an example : https://semantichtml.developersandbox.xyz/
2
1
u/stellisoft Nov 29 '24
Iām curious as to how desktop/ mobile apps are styled given that css is purely a web development tool. For me, these apps nearly always feel crisper and more responsive than their browser counterpartsā¦
1
u/averajoe77 Nov 29 '24
It depends how the mobile app is written. All the android tutorials I have done used xml and xslt to handle styling,along with some settings values that mimic css properties and values.
1
u/stellisoft Nov 29 '24
Absolutely and it's true to say that some of these apps do in fact use CSS. My question is why do these apps look/ feel better than their web equivalents or is that just my opinion!? My hunch is that what Sea-Blacksmith-5 is stating is correct and that the browser could and perhaps should take over more of the stying leaving you with the ability to tweak it in order to bring it in line with your branding. The key benefits in doing that in my mind are optimisation and compatibility. That said, you'd think there must be some case to be made for CSS given that hasn't and doesn't look to be happening..
1
u/averajoe77 Nov 29 '24
Again, if you are referring to native mobile apps, they most definitely do not use css, they use css like properties and values, but there is no cascade or inheritance of any kind. If you use things like react native, then you are using html and css and in that case yes.
Native apps are usually more responsive than non-native apps becuase native apps run on the device hardware directly and have access to the hardware apis. Apps that are non-native run a webview and do not have direct access to the native hardware but instead access it through the webview via non-native apis that then interact with the native apis and hardware. It basically adds a layer on top of the native layer, so they can feel a bit slower and less responsive.
1
u/stellisoft Nov 29 '24
I was meaning via tools like react native.
On your point about running on the hardware, that's exactly what I'm suggesting, having components built into the browser that can be programmed. I know these exist in the form of HTML5 components but they're clearly inadequate, hence the need for CSS and consequently 5 million different component libraries from which to choose from!
1
u/averajoe77 Nov 29 '24
I am not sure you understand what you are saying. The browser does have access to some hardware apis (like the graphics card), but that is not the same thing on mobile as a webview. Also you don't want the browser or a webview to have native hardware access. They are sandboxed environments for a good reason. Native apps can be tracked back to the developer that made them and can be shutdown and removed from the device if someone does something nefarious. Web apps cannot as they run on the web. You do not want a web app to have native access to the hardware, otherwise I could write a web app that looks like a social media app but is really crawling around your hard drive looking for your pron stash (or worse, writing files of a sexually illegal nature onto your hard drive) and using your video card to mine crypto currency in the background without you ever knowing it.
The way css is done, is done for reasons that you and OP clearly do not understand. I was there in the beninging when the web was the wild west. I started learning web development in 1997, and trust me when I say this... what we have now may be cumbersome and daunting to use for you or OP, but it is light years better than what we had. Adding css attributes to the html spec and markup is a terrible idea and is only going backwards in terms of the web platform. What we want is to move forward and make it better, not regress and go back to what we used to do.
I meaningful discussion should be had around the next version of the web platform. How can we evolve from static documents and JS to a truly robust native application experience on the front end with better data modeling and access on the back end.
1
u/stellisoft Nov 29 '24
I think you're inventing that I've said things I haven't and assuming I don't understand things I fully understand.
You say the browser has access to certain apis like the graphics card. Well yeah, that's exactly the api we're talking about are we not? Where has anyone mentioned accessing any other hardware?
Your last paragraph basically paraphrases the point I'm making. That evolution could and should have started ages ago. Possibly even 1997 back when you were gunslinging in the wild west. Sounds to me like you fell off your horse and hit your head a few times...
1
1
u/mapsedge Nov 29 '24
Forgive me, 'Blacksmith, but it sounds like you don't really understand CSS, or how CSS and HTML work together. I've been writing for the web since HTML 2, and it took me awhile to wrap my head around it, but once I did...I'm HUGELY grateful for CSS. Now that we have ability to nest CSS without using a pre-processor, I'm even happier. (Other commenters have explained why far better than I could.)
1
u/neodegenerio Dec 01 '24
You can already do styling directly html with inline CSS. Separate CSS file makes it more modular, manageable and reusable.
4
Nov 29 '24
[removed] ā view removed comment
2
u/Gonza-dev Nov 29 '24
Yeah youāre right nobody else mentioned class name reusability (I forgot too)
1
1
4
u/Positive-Photo8138 Nov 29 '24
I honestly love how HTML and CSS work together. I think the distinction between content and layout/design is kind of necessary and intuitive .. just think of all the things css is capable of doing .. all the different ways to display content .. if that were put into one single system alongside content wouldn't it be way too much?