One Feature From HTML, CSS & JavaScript You'll (Hopefully) Never Need To Use

·

2 min read

The source of every webpage is comprised of three components: HTML, CSS and JavaScript. You might hear that and think "well, not every webpage has CSS and JavaScript," and you'd be completely right - a proper webpage only needs HTML - but you'd be surprised at just how little HTML you actually need. Here, I'll go over one interesting tip for each of these three languages.

HTML: <head> and <body> tags are optional

Yes, you read that correctly. Two of the most fundamental tags many developers first learn when they first learned HTML are actually optional. And not only optional, but actually discouraged by Google. Both the HTML5 and HTML4 specification explicitly state that omitting the head and body tags are valid, although plenty of older browsers such as (you guessed it!) Internet Explorer will not render properly without the tags.

CSS: will-change property

Do you have the worst-ever, headache-inducing, animation-churning, color-changing, div-rotating, gradient-fading page? If you ever manage to write such a terrible webpage that you're having performance issues from changing CSS properties, this tag is perfect for you. You can use will-change to let the browser know which CSS properties will change later in the webpage's lifecycle, so the browser can internally make some optimizations.

JavaScript: Labeling loops

If you're a good web developer, you've likely punched a wall after debugging some infuriating JavaScript behavior. In your head, you even might've thought, "at least it can't get any worse." You clearly forgot about everyone's favorite eponymous law: Murphy's law. Well, Edward Murphy's famous phrase holds true for JavaScript as well. You can assign labels to loops in JavaScript. Look at this example from MDN:

let str = '';

loop1:
for (let i = 0; i < 5; i++) {
  if (i === 1) {
    continue loop1;
  }
  str = str + i;
}

console.log(str);

Thankfully, most JavaScript developers don't know about this "feature" of the language. And if one eponymous law wasn't enough for you today, don't forget the wise, fateful words of Jeff Atwood, "any application that can be written in JavaScript, will eventually be written in JavaScript." Hopefully this doesn't hold true.

Thank you for reading, and best of luck never needed to make use of any of these "features."