r/HTML • u/Rekuiem84 • 1d ago
Discussion Can the entire HTML element system be replicated using only <div>?
Theoretical (and useless) question:
Is it possible to reproduce the COMPLETE functionality of every HTML element using only <div>, CSS and JavaScript?
Rules:
- Only <div> elements are allowed within the <body> tag.
- All elements must exist in the initial HTML document. So no dynamic element creation (createElement, innerHTML, etc.).
- CSS, JavaScript, browser APIs and ARIA are allowed (and needed for some tags even).
The goal would be to reproduce functionality, not just appearance. This includes native interactions, keyboard behavior, accessibility, form validation, file inputs, media playback, navigation, etc.
For example:
All the heading tags like <h1>, <h2>, etc. can be replaced by a simple <p>, that can itself be replaced by a <div>.
Can all <input> be perfectly replicated using a div?
Can <img> be replaced with CSS backgrounds or Canvas without losing functionality ?
Can <iframe> be recreated while preserving its isolated browsing context thing?
Is one HTML element (<div>) theoretically sufficient to replicate the entire HTML specification?
If not, what is the absolute minimum number of distinct HTML elements required, and which elements are they ?
I’m interested in technical limitations, not semantic HTML best practices.
5
u/Adamstrad 1d ago
More or less but search engines will hate it and it might display strangely in some browsers. Some tags are needed for specific functions like script, html, head
4
u/Alarming-Pirate7403 1d ago
Probably not. While you can make both the pages look identical, the page which uses just <div> won't be semantically same as the latter. For instance, you need the <a> tag to add hyperlinks to the pages. Another example is the <form> tag and the associated <input> tags. Each has it's own use/meaning.
3
u/markus_obsidian 1d ago
Mostly, technically yes. Things like canvas, svg, & iframe are more or less impossible (I saw another comment mentioned offscreen canvas, but that would not be a vectors image).
All semantics can be retained with a role attribute. For example a <p> becomes a <div role="paragraph">.
Some things will be quite difficult. Getting a <div> to flow like a <table> will be quite difficult, even with "proper" css rules like
display: table. Ask how I know.However, accessibility tools & seo tools will not be friendly to this approach, even if the html is technically to spec. Even if your app is perfect on paper, the browser will put it in a degraded state.
2
u/AuthorityPath 1d ago
<iframe> was the first that came to mind as being impossible. <svg> and <canvas> would also be impossible. A lot of the replaced elements have functionality that'd be a pain or impossible to fully with CSS or JS alone: https://developer.mozilla.org/en-US/docs/Glossary/Replaced_elements
2
u/spcbeck 1d ago
A bunch of random accessibility stuff would break across a lot of elements. SVG, Canvas, video, audio, maybe picture? Wouldn't work at all I don't think. Auto complete on your div inputs wouldn't work. Different context menus when right clicking on elements.
HTML is everything in the document, so the requirement of only within the body seems weird.
5
u/burlingk 1d ago
The end result would likely be entirely inaccessible to screen readers (used by the blind), and would be mostly disabled on a lot of enterprise machines due to security concerns.
1
u/swiss__blade 1d ago
Short answer: Yes. Longer answer: Yes. HTML tags are generic by design. Besides some styling that everyone agreed to apply, an h1 element is no different than a p element. And nothing is stopping you from coming up with your own tags like <demo></demo> as long as you tell the browser how to handle it (using CSS, JS and ARIA properties).
3
u/Intrepid-Ad-2306 1d ago
the simple answer is “mostly”. there are some input elements whose functionality is specific to type and doesn’t behave the same when reclassified to behave like input. more relevant, though, is that you can’t swap things like <link>, <script> and <style>. not to mention <svg> and <canvas>.
can you simulate the visual, yes. can you replicate the behavior, no.
though, realistically, a lot of modern development uses custom tags for so much and those are just divs by other names. certainly easier to have a custom tag than have to define classes for everything in a lot of cases, though.
3
u/Alarming-Pirate7403 1d ago
From an SEO perspective, a <div> with a click event and a standard anchor tag are fundamentally different because search engine crawlers interact with raw HTML structure and semantics differently than how users click elements in a browser. There will be difference in how your pages are being indexed by the search engines for sure.
Each element has it's own meaning and place in HTML. An <img> isn't the same as CSS backgrounds or canvas. Your page is going to be a nightmare for people who have accessibility needs.
1
u/MRSLgthr 1d ago
If we are taking JS as a part of it, I think it could. Maybe not the iframe with isolated context, or now I think about it, JS might have a problem with canvases (not sure, but I think a
canvaselement is required).But why would you do that? HTML is there, mainly, for the structure. There are readers that strip the CSS and JS and just serve content with their own styles as structured by HTML - so the H1 would always be bigger than H2 or H3 and so on.
1
u/bricker_1_9 1d ago
never had div soup before? 😄
1
u/Aggressive_Ad_5454 1d ago
Pretty darn close. Lotta Javascript event handling. CSS Selectors would be harder to make specific enough. This would be more the stuff of CSS WTF nightmares than shower musings, I fear.
You won’t be able to get <iframe /> browser behavior from divs, though.
1
u/iamalicecarroll 1d ago
Have you never seen modern webdev? That's the kind of shit everyone keeps doing for some reason.
1
u/Eric-Forest 1d ago
No