Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

Browsers read HTML comments?

I thought comments were just comments that got ignored. But this lecture: https://teamtreehouse.com/library/cross-browser-testing is saying that browsers actually read the contents of comments and interpret the programmatically. I don’t really follow how this works. Why wouldn’t a browser just ignore the comments and look at the link regardless?

<!β€”[if gte IE 9]>
    <link href=β€œβ€¦β€>
<![endif]β€”>

2 Answers

andren
andren
28,558 Points

That is an example of a Conditional comment. It is a system created by Microsoft for Internet Explorer. Specifically it was supported by Internet Explorer from version 5 to 9

Microsoft wanted to implement a system that allowed developers to change the HTML (and potentially CSS and JavaScript) that was interpreted by IE based on the version of the browser and the OS it was running on. This was wanted because changes between IE versions could require that you had to change what code was included or hidden in order to have the different browser versions render your page properly. It also allowed you to add code specifically for non-IE browsers that would be ignored by IE.

The fact that it looks like a standard comment is intentional, that was done so that other browser would not be affected by the code added specifically to deal with the different IE versions.

So to sum up, it is technically speaking a normal comment, and it will be ignored by most browsers. But old version of IE will specifically look for them and treat them like code.

Hey Brendan! Im pretty confident that they dont get read by the browser. This is what i have been told all along atleast, ofcouse the intepreter has to look at the text in order to evaluate that its a comment, but i think thats about it.

However when you make a comment in html it should look like this:

<!--This is a comment. Comments are not displayed in the browser-->

Notice that you need 2 "-", but you only put 1. That might of been the issue. Hope this helps!