Return to Video

HTML comments

  • 0:00 - 0:03
    Everything that we've put
    in our webpages so far
  • 0:03 - 0:06
    has been either
    content displayed by the browser,
  • 0:06 - 0:08
    or tags to tell the browser
    how to display it.
  • 0:09 - 0:12
    Sometimes though, we just want to put
    information in our webpages
  • 0:12 - 0:15
    for other humans to read,
    and for the browser to ignore.
  • 0:16 - 0:19
    To do that, we write
    an opening angle-bracket,
  • 0:19 - 0:22
    an exclamation mark,
    two dashes,
  • 0:22 - 0:25
    and some text inside here,
  • 0:25 - 0:29
    and then two dashes
    and a closing angle-bracket.
  • 0:29 - 0:31
    We call this a comment.
  • 0:31 - 0:34
    And it's something that we do
    in all sorts of programming languages,
  • 0:34 - 0:37
    because we often want to do things
    that are just for humans.
  • 0:37 - 0:39
    That's the thing about programs:
  • 0:39 - 0:41
    they're not just
    for computers to look at,
  • 0:41 - 0:43
    they're also for
    other humans to look at.
  • 0:43 - 0:47
    Because we often work together
    on things and learn from each other.
  • 0:47 - 0:49
    Okay, what do we use comments for,
  • 0:49 - 0:52
    besides just saying "hello"
    to our fellow humans?
  • 0:52 - 0:55
    Well, we might use them for
    letting people know
  • 0:55 - 0:58
    where content came from,
    in case they want to update it.
  • 0:58 - 1:05
    I'll say, "This paragraph is based on
    the Wikipedia article,"
  • 1:05 - 1:08
    and I should probably
    give a link to that, too, but...
  • 1:08 - 1:16
    And, "This paragraph is based on
    Pamela's personal opinion,"
  • 1:16 - 1:19
    a very well trusted source.
  • 1:19 - 1:24
    Then maybe we'd even, say,
    give a link inside the comments,
  • 1:24 - 1:30
    and say, "These lyrics were from here."
  • 1:30 - 1:34
    And that helps people know
    how I got the content of this page.
  • 1:34 - 1:37
    Do you notice something
    about these comments?
  • 1:37 - 1:38
    They are all green.
  • 1:39 - 1:42
    That's because we're using a code editor
    with syntax highlighting,
  • 1:42 - 1:44
    and it uses colors to help us
    see what's what,
  • 1:44 - 1:48
    and comments are pretty much
    always colored green, by convention.
  • 1:48 - 1:52
    We could also use comments to
    "comment out" parts of our HTML.
  • 1:52 - 1:57
    Like if we want to experiment with
    taking something away from our webpage.
  • 1:57 - 2:00
    We just surround it with a comment.
  • 2:00 - 2:02
    ♪ (humming) ♪
  • 2:02 - 2:05
    Now, the browser
    no longer sees that HTML,
  • 2:05 - 2:08
    because browsers ignore
    everything in comments,
  • 2:08 - 2:11
    and that part is gone from the page.
  • 2:11 - 2:15
    If I decide that I actually liked it,
    I can comment it back in
  • 2:15 - 2:18
    by removing those comments
    on both sides...
  • 2:18 - 2:19
    and now it's back!
  • 2:19 - 2:22
    Remember, comments are for humans.
  • 2:22 - 2:26
    At least, the kind of humans that
    like to look at webpage code.
  • 2:26 - 2:29
    Which is pretty much
    all of us now, right?
Title:
HTML comments
Video Language:
English
Duration:
02:30
Josh Kline edited English subtitles for HTML comments

English subtitles

Revisions