NostraDavid,
@NostraDavid@programming.dev avatar

Learning HTML syntax is the simple part. The tedious part is learning which tags already exist, and which tags goes in which other tag (and which attributes they may (not) contain).

For that, always, ALWAYS go to the official HTML spec: WHATWG HTML.

HTML has not been maintained by WC3 (though they still do maintain CSS) and has been a “living standard” since HTML5 (2009-ish, IIRC).

I’ve read through the entire spec (using TTS, because only reading is boring) and learned a TON, because writing React straight out of the gate, without learning the HTML fundamentals first is a HUUUUGE pain.

/rant

shnizmuffin,
@shnizmuffin@lemmy.inbutts.lol avatar

Web accessibility isn’t just about compliance; it’s about creating digital experiences that empower and include every user, regardless of their abilities.

Step 1: remove user agency.


<span style="color:#323232;"><html lang="en">
</span><span style="color:#323232;">  <head>
</span><span style="color:#323232;">    <base target="_blank" />
</span><span style="color:#323232;">  </head>
</span>

I get that it’s hard to come up with a good example of using <base>, but I wouldn’t show a user-hostile example before … cutting the element from Chapter 1 entirely. The only time I’ve ever used <base> was when I had to deploy multiple versions of a multi-page static site to a subdirectory for its staging environment, but to the public root for the production environment. Even then, the solution wasn’t, “use <base>,” it was, "sort shit out later with nginx."

Step 2: confuse the use case of anchors and buttons.


<span style="color:#323232;">  <body>
</span><span style="color:#323232;">    <ul>
</span><span style="color:#323232;">      <li><a class="native" href="add-book">Add Book</a></li>
</span><span style="color:#323232;">      <li><a class="native" href="view">View Bookshelf</a></li>
</span><span style="color:#323232;">    </ul>
</span><span style="color:#323232;">
</span><span style="color:#323232;">    <ul>
</span><span style="color:#323232;">      <li>
</span><span style="color:#323232;">        <a href="https://example.com/dont-use-real-urls">Misery</a>
</span><span style="color:#323232;">      </li>
</span><span style="color:#323232;">      <li>
</span><span style="color:#323232;">        <a href="https://example.com/especially-links-to-amazon-just-pick-a-real-bookstore">Carrie</a>
</span><span style="color:#323232;">      </li>
</span><span style="color:#323232;">    </ul>
</span><span style="color:#323232;">  </body>
</span>

I understand that it’s just an example but it’s never just an example. Use appropriate landmarks or break your snippets down to the point where it’s obvious that what you’re pointing out isn’t the whole thing. You don’t need <body> or <ul> or <li>, just split the snippet in two, like this:


<span style="color:#323232;"><</span><span style="color:#63a35c;">a </span><span style="color:#795da3;">href</span><span style="color:#323232;">=</span><span style="color:#183691;">"/my-favorite-books"</span><span style="color:#323232;">>My Favorite Books</</span><span style="color:#63a35c;">a</span><span style="color:#323232;">>
</span>

<span style="color:#323232;"><a href="https://example.com/some-book">Every Man For Himself and God Against All</a>
</span>

Step 3: Introduce Javascript to restore the native functionality you broke in step one.


<span style="color:#323232;">  <script>
</span><span style="color:#323232;">    document.addEventListener("click", (event) => {
</span><span style="color:#323232;">      if (event.target.classList.contains("native")) {
</span><span style="color:#323232;">        event.preventDefault();
</span><span style="color:#323232;">        window.location = event.target.href;
</span><span style="color:#323232;">      }
</span><span style="color:#323232;">    });
</span><span style="color:#323232;">  </script>
</span>

Don’t do that. I mean, don’t really do any of this example, but really don’t do this last part. Adding class=“native” is as cumbersome as adding target=“_blank”, while also being more brittle. [I edited out a considerable amount of swearing here.] I think this is just a symptom of a bad example gone way too far.

If the client insists on opening all external links in new tabs, get it in writing and then do this:

<base target=“_blank” />


<span style="font-weight:bold;color:#a71d5d;">let </span><span style="color:#323232;">external_links </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">document</span><span style="color:#323232;">.querySelectorAll(</span><span style="color:#183691;">'a[href^="http"]'</span><span style="color:#323232;">);
</span><span style="color:#323232;">external_links.forEach((external_link) </span><span style="font-weight:bold;color:#a71d5d;">=> </span><span style="color:#323232;">{
</span><span style="color:#323232;">  external_link.</span><span style="color:#0086b3;">setAttribute</span><span style="color:#323232;">(</span><span style="color:#183691;">'target'</span><span style="color:#323232;">, </span><span style="color:#183691;">'_blank'</span><span style="color:#323232;">);
</span><span style="color:#323232;">});
</span>

You can use querySelectorAll with a prefix attribute selector like ‘a[href^=“http”]’ instead of a typical class selector. This lets you grab all the anchors with hrefs that start with “http” without adding extra syntax where it doesn’t really belong. Once you’ve got your external links, iterate through that NodeList with forEach and tack on target=“_blank” using setAttribute. That way, you’re not re-implementing default behavior, you’re only mildly annoying users with HCI devices, and if JS gets blocked all your links suddenly behave predictably.

Even this is bad! Just don’t! It’s so easy to not!


Other notes

  • You should probably start by explaining what an element is, then what an attribute is, then what a value is. Vocabulary is extremely important.
  • When referencing elements, include the chevrons in the inline style. <meta> vs meta. If they have to guess, they’ll guess wrong. Suffix with “element” to really beat them over the head with it.
  • When referencing attributes, try to keep their values attached. class=“foreign”. If you can’t, suffix it with "attribute."
  • When referencing values, keep those quotes! “false”.
  • If it’s a book about HTML, don’t use JS. At all. Every time you reach for JS, stop. Like if you are about to write a self-invoking function to go and find invalid values of the rel attribute, for example, maybe don’t.
Cruxifux,

Man my neopets shop is gonna be so dope after I read this book

  • All
  • Subscribed
  • Moderated
  • Favorites
  • webdev@programming.dev
  • GTA5RPClips
  • DreamBathrooms
  • InstantRegret
  • ethstaker
  • magazineikmin
  • Youngstown
  • thenastyranch
  • mdbf
  • slotface
  • rosin
  • modclub
  • kavyap
  • cisconetworking
  • osvaldo12
  • JUstTest
  • khanakhh
  • cubers
  • Durango
  • everett
  • ngwrru68w68
  • tester
  • normalnudes
  • tacticalgear
  • anitta
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines