Adding Developer Notes with HTML Comments2:04 with Guil Hernandez
Developers use comments in their code to make parts of it easier to understand. HTML lets you write comments in the code that are ignored by the browser.
Developers use comments in their code to make parts of it easier to understand. 0:00 HTML lets you write comments in the code that are ignored by the browser. 0:05 So if you're revisiting your code after several months, 0:08 comments can help you remember what different parts of your code do. 0:11 Or if another developer is viewing your code for the first time, 0:15 it will help them to quickly understand how your code works. 0:18 So comment tags in HTML begin with a less than symbol followed by an exclamation 0:20 mark and two dashes and they end with two dashes and a greater than sign. 0:27 And everything between the opening and 0:32 closing characters is ignored by the browsers. 0:35 Comments are frequently used to indicate where sections of a page start and end. 0:38 So, for example, here I can write that this is the start of the wrapper div. 0:44 Then I'll scroll all the way to the closing div tag and 0:52 add a comment that says, end wrapper div. 0:57 Now when you see the code change to a light grey color, 1:04 that means that it's commented out. 1:08 And as you can see, the browser does not display the start wrapper div and 1:10 end wrapper div text written inside the comment tags. 1:15 Now Workspaces and most text editors have a shortcut for 1:21 quickly creating or removing comments. 1:25 You place your cursor wherever you want to include a comment then 1:28 press Command + / on a Mac or Ctrl + / on Windows. 1:33 And that will create a comment tag for you. 1:37 Now if you need to select and comment out large chunks of HTML, you can do that 1:40 by selecting the code and pressing Command or Ctrl + /. 1:45 And then to remove the comments you can, once again, select the code and 1:51 press Command or Ctrl + /. 1:55 You can use comments in all kinds of different ways. 1:58 Just be sure to keep them short and meaningful. 2:00
You need to sign up for Treehouse in order to download course files.Sign up