Return to Video

HTML Images (Video Version)

  • 0:00 - 0:02
    - [Voiceover] We've been
    talking about rabbits
  • 0:02 - 0:06
    this whole time, describing
    them with paragraphs and lists,
  • 0:06 - 0:09
    but we could just put a
    picture on our webpage
  • 0:09 - 0:12
    and actually show what
    a rabbit looks like.
  • 0:12 - 0:16
    Well, to insert a picture in
    a webpage, we use the img tag,
  • 0:16 - 0:19
    which, as you might
    guess, stands for image.
  • 0:19 - 0:23
    If we just type "image"
    though, we don't see anything.
  • 0:23 - 0:24
    Why not?
  • 0:24 - 0:28
    Well, we didn't tell the
    browser which image to show.
  • 0:28 - 0:29
    There are millions of
    images on the internet,
  • 0:29 - 0:31
    and we certainly don't want
    it to pick a random one
  • 0:31 - 0:34
    because it might be something
    gross that we don't like,
  • 0:35 - 0:38
    and it also just won't be
    what we want it to be of.
  • 0:38 - 0:41
    We need to tell it the URL of the image.
  • 0:41 - 0:43
    The URL is what shows up at the top
  • 0:43 - 0:45
    of browsers in the address bar,
  • 0:45 - 0:47
    and that's what it is, an address.
  • 0:47 - 0:49
    It's a way of finding
    some resource on the web,
  • 0:50 - 0:52
    and it means that we
    can only insert an image
  • 0:52 - 0:55
    if it's already on the internet somewhere.
  • 0:55 - 0:58
    We can't just insert images
    that are only on our computer.
  • 0:58 - 1:01
    There are many ways to find
    images on the internet,
  • 1:01 - 1:03
    but we're making it easier for you here
  • 1:03 - 1:06
    by providing an image picker
    in a photo collection.
  • 1:06 - 1:08
    To get that to pop up, we need to add
  • 1:08 - 1:11
    an attribute to our image tag.
  • 1:11 - 1:13
    An attribute is an additional bit
  • 1:13 - 1:15
    of information about a tag, and this is
  • 1:15 - 1:17
    the first attribute that we've seen.
  • 1:18 - 1:20
    To tell the browser the URL, we're going
  • 1:20 - 1:23
    to add an attribute with the name, source,
  • 1:23 - 1:26
    and we'll add a space and then type src.
  • 1:28 - 1:31
    Now, it stands for source,
    but it's very important
  • 1:31 - 1:33
    that you spell it src because the browser
  • 1:33 - 1:35
    will ignore it if we misspell it.
  • 1:36 - 1:39
    Now, I need to put an equal
    sign so that I can tell
  • 1:39 - 1:41
    the browser what the attribute value is,
  • 1:41 - 1:45
    and now I'll add a quote, and the editor
  • 1:45 - 1:47
    will autocomplete the end quote,
  • 1:47 - 1:51
    so attribute values are
    always wrapped in two quotes.
  • 1:52 - 1:56
    Okay, so normally, this is
    when we'd start typing our URL,
  • 1:56 - 1:58
    but here on Khan Academy, that's when
  • 1:58 - 2:00
    our image picker will pop up.
  • 2:00 - 2:04
    We'll just pick image, and I
    want a picture of a rabbit,
  • 2:04 - 2:07
    so I'll click the animals tab and select
  • 2:07 - 2:09
    the adorable rabbit and click okay.
  • 2:10 - 2:13
    Do you see how there's a
    URL inside our quotes now,
  • 2:13 - 2:16
    and do you see how that
    URL starts with http?
  • 2:16 - 2:18
    That's how we know it's pointing
  • 2:18 - 2:20
    at some image somewhere on the internet.
  • 2:20 - 2:22
    Hey, look, there's a bunny on my webpage,
  • 2:23 - 2:26
    but what if the server
    hosting the image was failing,
  • 2:26 - 2:28
    and the browser couldn't load the image?
  • 2:28 - 2:31
    How would the viewer know
    what my amazing image was of?
  • 2:31 - 2:33
    They'll see nothing
    and wonder for the rest
  • 2:33 - 2:35
    of their lives what they missed out on.
  • 2:36 - 2:39
    That's why image tags have
    another attribute, alt,
  • 2:39 - 2:41
    which we use to tell browsers
  • 2:41 - 2:44
    what the alternate text for an image is.
  • 2:44 - 2:47
    To add another attribute,
    we just put a space
  • 2:47 - 2:50
    after the final quote for the last one.
  • 2:50 - 2:54
    Then we type alt equals quotes,
  • 2:54 - 2:57
    and inside these quotes, the text will be
  • 2:57 - 2:59
    some helpful description of the image
  • 2:59 - 3:04
    like "rabbit with lop ears in barn."
  • 3:05 - 3:07
    That also helps people who see webpages
  • 3:07 - 3:10
    but can't really see them, like the blind.
  • 3:10 - 3:11
    They use an app called a screen reader,
  • 3:11 - 3:14
    which will literally
    read a webpage to them,
  • 3:14 - 3:16
    describing each tag it sees.
  • 3:16 - 3:18
    When it sees an image tag,
    it will read off the alt text
  • 3:18 - 3:21
    since a blind person can't see images,
  • 3:21 - 3:24
    so you should always, always use alt text
  • 3:24 - 3:28
    so that the whole world can
    experience your webpage.
  • 3:29 - 3:31
    Okay, back to the image we can see.
  • 3:31 - 3:33
    It's a little big.
  • 3:33 - 3:34
    Let's resize it.
  • 3:34 - 3:36
    We can do that with more attributes
  • 3:37 - 3:39
    with our width or height.
  • 3:39 - 3:43
    Let's say, "width equals 100."
  • 3:44 - 3:47
    Okay, so now it's 100 pixels wide.
  • 3:47 - 3:49
    That's a little too small.
  • 3:49 - 3:51
    Let's put our cursor inside and use
  • 3:51 - 3:54
    the number scrubber to make it bigger.
  • 3:54 - 3:57
    Okay, that looks a lot better.
  • 3:57 - 3:59
    Now, let's try adding height.
  • 3:59 - 4:01
    I'll just say, "height equals 50."
  • 4:01 - 4:03
    Uh-oh!
  • 4:03 - 4:05
    I squashed my bunny, poor bunny!
  • 4:05 - 4:09
    See, that's why you should
    usually only specify
  • 4:09 - 4:11
    either width or height, but not both
  • 4:11 - 4:13
    because you might use the wrong dimensions
  • 4:13 - 4:17
    and squish your bunnies, so
    I say just let the browser
  • 4:17 - 4:21
    do the math to decide what the
    other dimensions should be.
  • 4:21 - 4:22
    I'm going to delete height.
  • 4:22 - 4:25
    Now that you can make
    images, start thinking
  • 4:25 - 4:28
    about combining all the tags
    you have in your toolbox,
  • 4:28 - 4:33
    lists with images and paragraphs,
    top 10 craziest animals.
  • 4:33 - 4:36
    Just don't put too many
    images on your page
  • 4:36 - 4:38
    because the person
    checking out your webpage
  • 4:38 - 4:40
    will have to load all of them,
  • 4:40 - 4:43
    but you can still have a lot of fun.
Title:
HTML Images (Video Version)
Description:

{'type': u'plain'}

more » « less
Video Language:
English
Duration:
04:45
Myusernamegoeshere2 edited English subtitles for HTML Images (Video Version)

English subtitles

Revisions