Web development

Keep core content usable without JavaScript

Render essential text and navigation in HTML, then add JavaScript for optional convenience. For an article directory, all article links can exist before a script adds filtering.

Worked example

HTML example · save as example.html and open in a browser

<ul id="articles"><li><a href="/articles/">Browse all guides</a></li></ul>
<button type="button" id="enhance" hidden>Optional action</button>
<script>
const button = document.querySelector('#enhance');
button.addEventListener('click', () => button.textContent = 'Action complete');
button.hidden = false;
</script>

How it works

The link is usable before any script runs. The optional control stays hidden until its behavior is attached, reducing the chance of presenting a dead button. This approach makes script errors less likely to erase the page’s primary value.

Limits and mistakes

Some applications legitimately require client-side interaction, but their failure states still need explanation. Do not hide essential instructions behind a script without a fallback. Test real disabled-script behavior rather than assuming server-rendered markup is sufficient.

Check the result

Disable JavaScript and reload. Confirm core text and links remain usable, then re-enable it and verify the enhancement works without duplicating or replacing important content.

Sources

Reference documentation for the behavior used in this guide: