Hacker News new | ask | show | jobs
by sisk 5029 days ago
From an accessibility standpoint, this is a bad idea. Not that long ago, you had to make considerations for clients without CSS support (e.g., text-based browsers or screen readers). Across the board, things have gotten significantly better but there is still the issue of a stylesheet not loading (and mixing markup and CSS isn't great so that shouldn't be considered a reasonable alternative).

If a renderer comes across a script tag it doesn't know how to parse (e.g., a script of type `text/template`), it doesn't do anything with it, however it remains the responsibility of the markup renderer and, therefore, you're not relying on something else (CSS or JavaScript) to hide it.

1 comments

Not really, if you add style="display:none" inline, or use the `hidden` attribute, it will be correctly ignored by all screen readers.

<script type="whatever"> is mostly used because it's completely ignored. It's safely hidden, difficult to be accidentally messed with, and doesn't take parsing/rendering time from the browser.

Right but, as mentioned, inline styling is mixing markup and styles so it's best avoided (plus you're still relying on CSS to hide the content).

Regarding the `hidden` attribute, there is no support for it in IE (at least up to and including 9).

I know a lot of people argue against mixing markup and styling. As one of those, and since you seem well informed, how do you feel about the various css frameworks like bootstrap where the class names are essentially style descriptions?