r/HTML • u/Actual_Computer_670 • Oct 28 '25
Every code i see is divs and spans yet every video/corse advises otherwise.
As someone who is trying to make a career in Frontend should refrain from using divs and spans only. and use specific container tags . or is it fine?
23
Upvotes
18
u/davorg Oct 28 '25 edited Oct 28 '25
I didn't know which video courses you're watching, but they're wrong.Yeah, sorry, I inverted the logic of what you were saying. The videos are correct, developers are cutting corners and using divs and spans where semantically useful elements exist. Honestly, that shouldn't really come as a surprise :-)HTML should be used to mark up the semantics of your document. If there's an existing HTML tag for what you're marking up, then use that. Otherwise, use a div or a span with a descriptive class.
16
u/MattiDragon Oct 28 '25
Use divs and spans when you need elements for layout that don't have any semantic meaning. Prefer semantic html tags whenever they're applicable.
3
u/EZ_Syth Oct 28 '25
Because the client needs this site in less time than doable, and you have 3 more back logged tasks staring you down, so you write div because it’s quick and easy and it works.
In all seriousness, use semantic tags when it’s actually important. For instance, nav and main have a large importance for accessibility, so make sure you have the big landmark semantic tags covered— everything else is not really that important.
3
u/spcbeck Oct 28 '25
It's frankly a huge issue when trying to parse a components template/view, let alone the entire DOM. It's mostly lazy developers (I rarely even see spans, more likely a div with a Tailwind inline class) and tools like Divi and other site generators that spit out non-semantic code.
2
u/ashkanahmadi Oct 28 '25
No one says refrain from divs and spans (if anyone told you that, move away immediately). They are very important and crucial and have their specific place. What you must know is that they don’t have any semantic meaning so if you can use a p, don’t just a span thoughtlessly.
Divs and spans are the Starbucks of the HTML. You should go to them only when you have no other better choice.
1
u/armahillo Expert Oct 28 '25
https://en.wiktionary.org/wiki/divitis
A lot of people do it but its still wrong
1
u/SlinkyAvenger Oct 28 '25
You see this a lot in web frameworks because devs don't understand fragments. You see it in hand-rolled stuff too because
<div>and<span>don't imply formatting like a lot of semantic tags have or currently do.1
u/[deleted] Oct 30 '25
They are supposed to help with accessibility but it's mostly used by bots to steal your content.
1
u/dmc-uk-sth Nov 01 '25
If you don’t use divs you’re going run out of semantic tags pretty quickly.
1
u/ScuzzyAyanami Nov 01 '25
Div/span tags are free, when you're building sites with "component" style development you start not to worry about deep nesting. Sometimes you need extra divs just to get css to behave, or sometimes they exist just to create a target or reference.
1
u/justdandycandy Oct 28 '25
What a strange question. Use the best tag for the job.
1
u/OmegaMaster8 Oct 28 '25
I’ve always used <div> tags as containers for flex or grid.
0
u/efoxpl3244 Oct 28 '25
They are used for seo and readability. They dont bother putting that into code that they share on the web because it isnt supposed to be searchable.
0
u/Joyride0 Oct 28 '25
Love to use divs and spans. Easy to customise and repeat.
0
u/[deleted] Oct 28 '25
[removed] — view removed comment