Write HTML Like It's 1999
bradleytaunt.com
bradleytaunt.com
You wouldn't believe how much effort people with poor vision have to go to, to consume the modern web.
You can't even take simple things for granted like being able to zoom. So many websites pollute their page with pointless navigation elements that block most of the content when the page is zoomed.
Or say pages that try to be elegant, centering everything with some margin. Sure, it looks "great" if no one zooms it. If you do, you wind up consuming the content in three or four word chunks...
Or even worse: Elements that have hardcoded minimum widths. When you zoom, nothing reflows and you wind up having tons of content "off screen."
At best, this is annoying because you have to constantly scroll horizontally.
At worst, you're screwed because for some bizarre reason, scroll bars never appear.
I'll wrap my rant up here but I'll leave this:
Do you really want the web to be like reality, where the needs of a few are so often ignored simply because of some trait?
"Oh, there are so few of them, why bother..." "Oh, they don't matter because <whatever>"
Sound familiar? I'm sure you can fill in the blanks.
The web gives us a unique opportunity to improve on the real world in so, so many ways.
Don't waste it.
I'd like to throttle the first person who ever decided that if the window width would not 'comfortably' accommodate their vision of the page, certain elements would just DISAPPEAR. Like GONE. When you have to zoom out to make hidden elements (not just hanging off the edge, as in never drawn) appear... someone has been naughty.
/S
Everything worked just fine until I was on the page where I was supposed to press the 'Confirm' button for the factory reset. It just wasn't anywhere and I was wondering what I was missing. So I started to dig into the framesets and finally found a frame where the code looked like there was that button.
Took me a while to find out how to press it (simply opening the frame in a separate window didn't work because there was some JS magic involved). The solution was to zoom out. So much fun when a task that was supposed to take 15 minutes takes 2 hours because someone built an over-the-top web-interface.
I thew a head banging spittle-fit when laptops no longer carried RS232 ports. Then my boss handed me a 'modern' laptop without an Ethernet port. The theme seems to be, let the things evolve forward with LSI/VLSI/ChipsetBuiltins until the port costs a mere 19 cents... then drop it... to save 19 cents.
Then see what happens when you view it at 400%.
Then find yourself some software that mimics various visual impediments and give it a shot.
I am also not in the US, so I can't tell my boss to spend disproportionate amount of dev time on something that doesn't make money.
If you really want to write HTML like it’s from 1999, read this blast from the past: https://www.w3.org/TR/2018/SPSD-html32-20180315/ Remember image maps? That’s real <nav> (which is HTML5 a decade later, iirc)
But to address the point of the article, you can use JS or backend code to enhance accessibility, such as by disabling focus on parts of a page when it should be disabled, or setting h1-h6 tag levels dynamically based on nested heading tags. If your aim is accessibility, this list may be useful: https://developers.google.com/web/fundamentals/accessibility...
However, layoutwise HTML is at the moment much like it had been in 1999: The basic structure with banner, nav, main, footer is much like the standard frameset, if there had only been role/landmark-markup for frames, and CSS-grid in its basic form is much like table-layout (less those Daliesque "poles" for positioning). Where there had been those fancy CMS templates with modular components, there are now frameworks… (However, JS is "a bit" more powerful and has grown out of `document.write()`.)
That said,landmarks and aria-markup are really a great deal when it comes to accessibility and are probably the most underrated additions to HTML.
Wasn't innerHTML still settable back then?
There was an interesting bug with `document.write()` in early versions of Netscape Navigator: If you wrote to table cell (td) or row (tr) code containing any embedding elements (like images or form elements) and there was adjacent whitespace around the script tags, the embedding elements (images) would show up twice. This was one of the more obscure bugs in the browser, which likely prohibited a broader use of `document.write()` with dynamic layouts etc at the time. However, if you knew the quirks, you could load data objects in an invisible frame and render/update regions (frames or later layers) much like today.
What was initially setable: Beginning with NS 2.0 (JavaScript1.0) the state of form elements and window locations. Later (NS 3.0, 1996) also href and src attributes of images and anchors (links), the document title, and you could navigate the history, or call print() and find(), as well as manipulate a few other things, like keyboard focus. Of course there were event handlers, but they were quite specific for a few elements. (E.g., onclick or onmouseover were available for links and images only.) More complex interaction (including playing sound!) was possible via a proprietary Netscape Java/JS-bridge, called "LiveConnect".
Instead, we used tables inside tables insides tables inside iframes to structure our navigations. CSS was still some mystic magic that only a few wizards knew how to use effectively. And in many cases, the result was actually less semantic than what we see nowadays.
So the arguments seem a bit odd, although I support the spirit of the message.
FTFY
It's a fairly common phrase (originating from a Prince song I think) that you can take to mean "like a throwback to a more authentic and possibly prior era." In this case the era is prior the explosion of frameworks and div soup.
Which strangely in this case is not necessarily prior but in parallel, as you said. This is English, it doesn't have to be precise like programming. You can use it for effect.
Which is perfectly fine advice if you aren't doing anything really novel. You probably don't need a custom library for dropdowns or forms or whatever else and would gain performance, accessibility, and stability by hooking into the native versions instead.
The one part I disagree with is necessarily using <table> in place of divs with CSS Grid. The latter is native and is a perfectly legitimate replacement, with some added benefits like responsiveness.
Also the title is a bit of a misnomer, because lots of the HTML features that allow you to forego JavaScript are pretty recent:
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Fo...
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/da...
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/In...
Salient point right here. Being served a blank white page (when JS is disabled) can deter a person from ever visiting a site again. Some peope out there want to vet a site before allowing it to run arbitrary code on their machine.
That's a bit of an exaggeration. JavaScript is strongly sandboxed and has a pretty good permissions system. The only malicious things it can really do are 1) based on cookies or 2) crypto mining.
Personally I think it's unreasonable to expect today's sites to work without JavaScript completely. The real benefits of using it sparingly are:
- Pages load faster
- Pages are more responsive
- Applications are less stateful and call out to systems that have a larger number of eyes on them, making them less fragile and lowering maintenance complexity
Minimalism is a virtue in any programming context
Also the poster said that webpages shouldn't be blank without having, not that they should be fully functional. I think it's reasonable to expect some function without javascript.
4) True, although it's my understanding that the exploits are hard to implement, doubly-so from an abstracted layer like JavaScript.
> trickery, manipulation...like trying to embed a frame from Facebook and steal user credentials or so on
This falls under "cookies-based", and I'm pretty sure no JavaScript is necessary for these kinds of attacks.
And a crappy end user experience. Why do I need to execute code just to read a static, read-only text article?
We now live in a post-Spectre world. I don't think a sandbox means all it meant in 2017.
Web apps on the other hand, probably do need them. I use newsblur and definitely enjoy the shortcuts.
I suppose the soundness depends on how you read the word "table". For actual tabular data, <table> is probably the right choice for accessibility reasons. It's also why it's usually a bad idea to abuse tables for grid layouts in other cases.
> It's also why it's usually a bad idea to abuse tables for grid layouts in other cases.
This isn't so much about semantics, it's about the way it kills responsiveness
Good advice. Definitely sounds like captain obvious but it’s also something I think needs to be said.
I have never wanted anything other than this behaviour, so I pretty much always include it when starting on a fresh project.
<div style="padding: 8px; border: 1px solid black"> Block 1 </div>
<div style="padding: 8px;"> Block 2 </div>
javascript:(function(){Array.from(document.body.getElementsByTagName('*'), e => e.style.outline = '2px dotted orangered');})(); var node = document.createElement('style');
node.innerHTML = '* { outline: 2px dotted orangered; };
document.body.appendChild(node); document.head.appendChild(document.createElement('style')).textContent = '* { outline: 2px dotted orangered' [].forEach.call(document.querySelectorAll("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
https://gist.github.com/addyosmani/fd3999ea7fce242756b1Semantic HTML only came back in the 2000s. Remember CSS Zen garden? Write HTML once and style it differently to achieve completely different looks. Even then, you had huge amount of CSS bugs. Like the voice-family hack or the
* > html
selector. Reading up on standards mode and quirks mode.Some web designers just really want full control, even if that makes for a shoddy user experience.
In other words, our first concern is making things easy to change. The semantic web (at least some of it) just isn’t there yet.
I’ll finish by saying, that there are certain semantic elements that are safe to use. In that case, by all means.
If you are a front-end dev it's of course a no-brainer to keep up.
God I'm old.
1999 - Cool and Clever
2005 - Horrible
2010 - Horrible but sometimes necessary
2015 - Awesome
Huh, what happened?
You can place another service's elements on a page that look like they're actually part of the page layout while the JS running them can freely communicate with the service's backend without having to bother with cross domain problems.
Think of all the support/chat widgets you see on modern-day pages, they're all iframes.
And obviously: tracking all the things!
Or just use Firefox. The built in CSS-designer/debugger has a button to do just this on demand.
Browser-suggestions aside, I really agree with the sentiment of this article. That’s how I like to build sites and solutions when not forced to use some other framework or approach.
Anyway, agree with what’s being said here. K.I.S.S.
I think he’s advocating for semantic HTML, not 90s HTML
The idea isn't to pretend it's 1999 and only use stuff that works in netscape4/IE5, but to build pages in the same way as then. <nav> adds something useful - it helps screen readers out, but costs nothing.
I’ve found a pretty simple starting point for
testing the bones of a website by using the
following single line of CSS:
* {
border: 2px dotted black;
}
Another nice way to find obsolete elements is to simply type this in the console: $$('*:only-child')
Elements with only one child usually can be optimized away. For example here on HN, it shows that every <code> element is wrapped in a <pre> element. I would think the same could be achieved by just setting the right styles on the <code> element.A poem might be a good example of something else you'd want to preformat.
Also, <pre> is a block element, while <code> is not.
The real issue is that there's something to be said about suggesting to write <pre class="code"> and <pre class="poem"> etc., or for that matter <pre type="whatever"> or simply <div class="whatever">. The real wtf here is that <code> has a special status in html while <poem> and other things that might want to be preformatted don't have their own tag. And that <pre> merely is a special type of <div> with some styling (which suits code just fine, but not poems) attached to it.
Funny I feel the other way. Twitter is rolling html flypaper with people stuck to it. You can hear their muffled voices and see their wiggling legs as they go past. Pages static'd with comments are forever, like web.archive.org forever.
Edit: Radio buttons are not hard to style[1]. Just use `appearance: none`[2] and style them as you wish with custom background colors and svg masks and whatnot.
---
1. https://codepen.io/anon/pen/qGeJWL
2. https://developer.mozilla.org/en-US/docs/Web/CSS/appearance
Also for styling, visually hiding the <input type="radio"> and using a custom radio-like icon with its associated <label> can be a decent option. Use a CSS selector like this to "check" an icon with the label: #radio1:checked + label::before
But in 2019 I think it is safe to style the radio element directly along with vendor prefixed `appearance: none;` possibly inside an `@supports` rule so that IE users will fall back to the native style while users of modern browsers get a custom style.
Using semantic HTML also helps search engine crawlers and other automated software understand the structure of your pages.
Browsers don't care. You may not care either. But people with disabilities attempting to make sense of your website do, very much so.
There's absolutely no reason __not__ to use semantic HTML, and many reasons to do so.
That doesn't mean you can't write accessible web applications without semantic HTML, but it does mean you have to spend time adding the accessibility after the fact.
* Set the correct aria attributes and roles for assistive technologies.
* Make the correct elements focusable, and order the focus correctly between elements, and add a specific style when then element is in focus.
* Capture the focus when appropriate but still allow focus to the URL bar.
* Set the correct key event handlers for keyboard navigation, submit events and triggers, validation events, etc. for assistive technologies, etc.
* Be prepared to warn users that your site will not work without javascript or in reader modes or in text based browsers, as well as make your site somewhat inaccessible for bots and crawlers.
And I’m sure I’m forgetting something. Point is, it is possible, but really hard.
> Don’t forget that there is always someone new into the world of design and development. Hopefully this post steers others towards keeping HTML code semantic and clean.
Perhaps it's time to start linking to old A List Apart articles?
- Sensible Forms: A Form Usability Checklist https://alistapart.com/article/sensibleforms/
- High Accessibility Is Effective Search Engine Optimization https://alistapart.com/article/accessibilityseo/
- A Brief History of Markup https://alistapart.com/article/a-brief-history-of-markup/
But even from this year:
- Conversations with Robots: Voice, Smart Agents & the Case for Structured Content https://alistapart.com/article/conversations-with-robots/
More precisely, they render the same in common visual user agents.
It turns out the semantics can be distinct for other kinds of user agents. Accessibility is one context that matters. Intermediate UAs like search engines are another. Maybe voice browsing is going to take off with virtual assistants.
To get an illustration, one could browse WWW in such a browser (w3m, links, lynx, netsurf, etc), or even in FF with customizations, and/or browse web.archive.org (particularly websites from a decade or two ago) using a mainstream browser: basic HTML pages tend to be nice and accessible, while the ones using graphics, CSS (possibly optimized for 1024x768 or a similar resolution), and Flash/Java/JS/etc are usually a pain to get information from. I think most of the contemporary websites would produce a similar impression in another decade.
Another example where semantic markup matters is conversion into other formats.
Obviously there are some benefits for screen readers and search engines, but these uses should be explicitly checked for as part of a QA process instead of relying on some vague standard of semanticness.
When an alternate display method comes out and wants my semantic html, I will add it to my QA workflow and make sure that it looks good instead of relying on some vague standard of semanticness from one of many bloggers.
Sure it's mostly black text on white backgrounds with only minor typesetting differences between elements but as a means to present information it has worked since the mid 1400s...
The more page authors use html 'properly', the more incentive there will be to improve systems like reader view.
This comment made me realize how relative everything is. It seems it was yesterday, when you would open Mosaic and slowly discover completely different worlds, one after another, and you'd never think of complaining HTML was aesthetically unpleasant...
It's for software reading the page and making use of the extra information, e.g. a screen reader being able to tell a user that there's a navigation element on the site and being able to jump there. Reader modes knowing what the main article on the page is. ...
(EDIT: I see you edited that point in, so yes, that's the main one, and IMHO a good enough one)
If you don't follow semantic html at all I don't see how QA can safe you, except for QA telling you to fix that <div> by replacing it with a <button> (or <div role="button">, or <a> or whatever you prefer).
At one point there was a kind of hope that semantic tags would make web content easily machine-parseable, unlocking a bunch of meaningful content reuse somehow that better semantics would make possible. (Big data, ML and all that.)
The two canonical examples being that lists were important so software could extract meaning from list items, and not using tables for layout so software could trust tables actually had meaningfully tabular data.
But... that never really happened, it's not clear it ever will, and it doesn't benefit the content author directly anyways, so... yeah.
(Like you say, screen readers are the main thing, so use the tags and attributes that are important to screen readers, like buttons and alt text... but that's a very specific subset. A screen reader certainly doesn't care if you use a <div> or an <li> or a <td>.)
Edit: I stand corrected on my example, for <td> specifically I forgot <table> lets screen readers navigate vertically and also read column/row labels.
In which current screen readers is that statement true? (I'm fairly sure the answer is "none", but ...)
It absolutely does. Try firing up a screen reader before you make such comments spreading misinformation.
For example, it's maddening to see people now making tables out of flexbox grids and such. In a screen reader you can navigate a <table> in two dimensions (rows and columns). The flexbox variety completely breaks navigating up/down columns.
You see this in all professions and without exception, from the exercise industry, to trades like plumbing, to healthcare and everything inbetween. Most of it is bullshit, process-based job security theater. Most major guilds just end up developing higher level cartel-like certification protections to keep them economically secured from competition.
I look at 'div soup' HTML and shudder. The authors of it have not got a clue. They also make it hard for people who do write proper HTML with the correct tags, styling the elements and keeping the separation of concerns to do anything with it.
It is about organising your content, if everything is in div tags you might as well just upload JPGs of your web pages, with different ones for desktop and mobile.
Another game changer is CSS grid. You no longer need wrapper divs to do very basic tasks such as centering content. In fact content with horrible divs everywhere is a nightmare to style up with CSS grid.
An example of this is a basic form. With just the form elements and labels you can get it looking sweet in next to no time with CSS grid.
However, if some zombie has put lots of spans and divs around the form elements and done the labels wrong then you have to choose either to rebuild the backend thing that churns out the form or just style it up lame block layout style.
Pseudo selectors are also cool, there is no need to have silly 'i' elements and spans to put that asterisk after 'required'.
Some people like to keep it simple, doing HTML properly, others want to pootle along with their divs and class attributes. I know what will look good in ten years time and what will look outdated.
HTML5 introduced many features but the main course was the semantic elements. You can and you should write web pages with these elements and also be thinking in terms of them.
You may scorn the accessibility aspect but accessibility is easy if you use the right elements. Why would you not want to have it? There is also the mindset that goes with it - the web is for everyone, not just rich, white, English speaking males with perfect eyesight.
The article is spot on and extremely well said. Styling elements rather than make believe classes is particularly well said.
I would say that people who create div soup HTML should be banned from the internets, the work practices of overly complicating everything has been going on for too long.
I don't even regard div soup web pages as proper web pages, it is like comparing beige deep-fried processed food with freshly prepared from ingredients food.
That was not so uncommon in 1999 :-(
Seriously, it's 2019 and some developers still don't get the value of semantic markup while this has been beaten to death for at least 20 years. this profession is cluttered with too many tourists. I even talk with devs bragging about the lack of care for markup.
Google don't care about HTML as they are way too clever for that. If I had more time I would like to see how they would rank two identical pages, one done properly and one that was a JPG image with a dangleberry of JSON-LD tacked on. I bet they latter would fare better!
After you've written the application? That makes absolutely no sense, unless you enjoy renaming lots of elements.
> instead of relying on some vague standard of semanticness
It's not vague, there is an actual international standard... WCAG!
Things like marking up addresses, phone numbers - as examples - means that a search engine can log a website as associated with a particular address, a browser can link to enable a number displayed to be called direct.
If for example there was a microformat (or other semantic markup) for opening times then SE/social sites could read and display (and update) that info without owners having to go on 20 sites if they change opening times.
Of course it can also help infer which parts of a page are advertising, or impressum, and not render that.
A plugin could offer to work on tables, or import them to a spreadsheet.
Lots of scope for advanced automations.
Yes, nowadays we hook into React components themselves, or even if not we can use those frameworks to strongly simplify writing selectors, because testing libraries have some magic built into them to use the component hierarchy directly...
... but depending on the amount of legacy and old in the app (and there will be legacy, and old stuff), and how strongly E2E you want to go (like "survive adding stuff from our team in that other city"), a "nav ul li[id='something']" will work ok for the developer maintaining the code, even if it is not the shortest possible selector; whereas a "div[...] div[...] div div + div" will catch up with you, even if you think you abstracted it away.
So while I don't disagree with what they're saying, the title is a bit of a misnomer.
>[Don't] create tables built out of custom div elements
Tables aren't responsive. Those fancy div tables are used because they work better on mobile. With a splash of JS (or overly-clever CSS) you can also introduce interactivity, tabbed layouts, etc.
Unless dealing with a very small amount of tabular data, it's really hard to recommend tables anymore.
Otherwise, yeah, fair advice. Nothing really too controversial in there.
Not really. The concept existed and was well known in many developer circles (e.g. List Apart Issue 268 from 2008 http://alistapart.com/issue/268/).
This article is from 2008, but I think it would be quite challenging to find something similar from 1999.
Oh yeah? Then what does Bootsttrap's table-responsive class do? The <table> tag can collapse just like any grid/flexbox mess.
From a cursory glance, it slaps a horizontal scrollbar on them.
First of all the post is arguing for more semantic HTML and says nothing about using semantic HTML5 tags over <div>? AFAIK semantic tags didn’t even exist before HTML5 which is definitely not the 90s.
I also find using the <table> element generally be bad practice. There are much better/easier ways to build responsive tables using grid or flexbox than dealing with <tr>/<thead>/<td> everywhere.
Try using that monstrosity in a screen reader. You completely break vertical/column navigation. Hardly better.
Otherwise, one must explicitly use HTML to specify lists which is more laboriousa nd not as neat because of mixed content. In the end it works either way ¯\_(ツ)_/¯.
That makes sense. I initially was confused because unordered lists themselves are very easy in Markdown, and indeed will generate <ol>s.
Separately from how you want things to look (CSS), you shouldn't be putting content into `<table>` elements that aren't the sort of thing you'd put into a spreadsheet. That's not using HTML well. Keep in mind you can still use the table layout with other tags via CSS. Always wrap your content in the most-fitting tag HTML has, then worry about the layout after :D
https://developer.mozilla.org/en-US/docs/Web/CSS/outline#Bor...
Funny enough, only changing the body's background color to "lightgrey" and the font face to "serif" makes it look exactly like that.