Web Lab: Why code seems to work even when it's written "wrong"

Hey folks,

I got a great question today through our support system today and figured this community could benefit from seeing the response as well. The question was why code in Web Lab still seems to work even when it’s written incorrectly. Here’s the long answer and also why you should be happy about this as a teacher.

When you visit a website what’s actually happening is your computer receives a bunch of HTML, CSS, and other content, and it turns all that code into a beautiful, interactive webpage. We call this process of turning code into a web page “rendering”. A web browser (e.g. IE, Chrome, Firefox) is the program on your computer that does the rendering. The HTML language is a universal standard for describing a web page, but each browser independently decides how it will render the different tags in the language. They might render the same tags slightly differently, or even decide not to handle certain tags at all. This is why sometimes when you move from one browser to the next the same website may look different, or even not work at all.

Browser designers also know people are prone to make errors, and so your browser will do its best to guess what you meant to do, even if you’re not writing perfect HTML. That means that sometimes if you don’t close a tag or you put it in the wrong place, the browser will try to guess what you meant to do in order to render the page.

Web Lab is just using whatever browser you’re on to render the web page. That means that if you put an <h1> tag inside the <head> and it still shows up in Web Lab, the same would be true for any other website you visit with that browser. The same goes for not closing your tags, or any other little mistake that it seems like Web Lab is ignoring. The browser is doing its best to render the page, and so may seem to ignore or not care about mistakes.

As a teacher you should know this is a actually a good thing. Right now Web Lab is a little bit forgiving and it might even feel like the rules are wishy-washy. On the plus side, though, your students are much more likely to get something on their web page. You should emphasize that as you make your way into Game Lab and App Lab later in the course those tools are much less forgiving. They should be practicing writing clean code now and as you’ll find, eventually all those errors will add up, making it impossible for the browser to guess any more what you want, or for you or anyone else to read it. In the meantime, the fact that browsers provide a little wiggle room is a nice way to transition into the detail-oriented type of thinking inherent to programming.

Hope that helps folks, and feel free to follow up with questions or other issues you notice in Web Lab and we’ll be happy to respond.