💻
HTML/CSS
  • Overview
  • How the Web Works
    • DNS, TCP/IP, HTTP, HTML
    • Anatomy of a Web Page
    • How a Web Page Gets Loaded
  • HTML/CSS intro
    • HTML
      • Boilerplate HTML
      • HTML Hierarchy
      • Meta Section
      • Text-formatting Elements
      • Image
      • Video
      • Anchor
      • Tables
      • Semantic Elements
    • CSS
      • Properties
      • Selectors
      • Box-Model
      • Block vs Inline
      • The Cascade
    • Layout
      • Container Elements
      • Grid vs Flexbox
      • Flexbox
      • Grid
  • Miscellaneous Topics
    • Background Image
    • Border-radius
    • Box-shadow
    • Centering Elements
    • Colors
    • Custom Properties
    • Forms
    • Typography
    • Units
  • Appendix
    • Google Fonts
    • Lorem Ipsum
    • HTML Cheatsheet
    • CSS Cheatsheet
    • Browser Support for HTML/CSS
    • unsplash.com (free images)
    • pexels.com (free images)
    • Chrome Default Stylesheet
  • Further Learning Resources
    • FE Mentor Challenges
    • Free Scrimba Courses
    • Kevin Powell Youtube
Powered by GitBook
On this page
  • Images - <img>
  • img element attributes
  • Images are inline elements
  • Image Guidelines
  • Finding Place-holder Images

Was this helpful?

  1. HTML/CSS intro
  2. HTML

Image

PreviousText-formatting ElementsNextVideo

Last updated 3 years ago

Was this helpful?

Images - <img>

The img element is a self-closing element. There is no content allowed between the opening and closing tags, so the correct syntax is <img/>

Attribute

Description

Embeds an image in the document

src

The value of the src attribute can be a path to a local image or an url to a remote image.

alt

An alternative to identify the content of the image for screen readers.

img element attributes

The <img element is our first element that demonstrates the use of attributes on the element.

<img src="images/pink-jelly.jpg" alt="jellyfish">

  • src - the location of the image file

    • can be the relative location of an image file within the project directory

    • can also be an URL to a remote image file.

  • alt - text used to support accessibility and search engines, or to display fallback text in case the image cannot be loaded.

Images are inline elements

This means that they only take up as much horizontal space as their width and it can effect how the content following it behaves. For more information on how this effects the display of an images see the topic on.

Image Guidelines

  • The best format for images are jpeg, gif, or png.

  • Store images in a special folder, named images, within the project to keep things organized.

Finding Place-holder Images

Save the image in the correct size for which it will be displayed so that it doesn't waste a lot of time downloading. If you need to crop or shrink an image, sites like are a good choice.

Just like we used place-holder text for our paragraph content, we often need place-holder images to use for development purposes. The sites and are great sites that have a wide assortment of free images to use in your pages.

Block vs Inline Elements
www.pixlr.com
unsplash.com
pexels.com