reading-notes

Todd Wolden

View on GitHub

Course 201 Class Five “Images, Color, Text”

In order to put a simple image on a web page, we use the <img> element. This is a void element (meaning, it cannot have any child content and cannot have an end tag) that requires two attributes to be useful: src and alt. The src attribute contains a URL pointing to the image you want to embed in the page. As with thehref attribute for <a> elements, the src attribute can be a relative URL or an absolute URL. Without a src attribute, an img element has no image to load.

Alternative text

The next attribute we’ll look at is alt. Its value is supposed to be a textual description of the image, for use in situations where the image cannot be seen/displayed or takes a long time to render because of a slow internet connection.

So, why would you ever see or need alt text? It can come in handy for a number of reasons:

What exactly should you write inside your alt attribute? It depends on why the image is there in the first place. In other words, what you lose if your image doesn’t show up:

Width and height

Use the width and height attributes to specify the width and height of your image. You can find your image’s width and height in a number of ways.

If you need to alter an image’s size, you should use CSS instead of HTML.

Image titles

As with links, you can also add title attributes to images, to provide further supporting information if needed.

CSS background images

The CSS background-image property, and the other background-* properties, are used to control background image placement.

p {
  background-image: url("images/anythingyouwant.jpg");
}

The resulting embedded image is arguably easier to position and control than HTML images. So why bother with HTML images? As hinted to above, CSS background images are for decoration only. If you just want to add something pretty to your page to enhance the visuals, this is fine. Though, such images have no semantic meaning at all. They can’t have any text equivalents, are invisible to screen readers, and so on. This is where HTML images shine!

Summing up: if an image has meaning, in terms of your content, you should use an HTML image. If an image is purely decoration, you should use CSS background images.

Questions

  1. What is a real world use case for the alt attribute being used in a website?

The alt attribute will help search engines find your photod by their description.

  1. How can you improve accessibility of images in an HTML document?

By setting height and width sizes so the image appears faster on webpages and it also provides a size placeholder on pages.

  1. Provide an example of when the figure element would be useful in an HTML document.

when you want to provide a caption for a picture.

  1. Describe the difference between a gif image and an svg image, pretend you are explaining to an elder in your community.

A GIF would be used to put 5 cute puppy pictures in a row and shuffle through them whereas a svg. may be used to show how to complete a project with step by step overlays that show the steps until the project is completed by overlaying the steps on top of each other.

  1. What image type would you use to display a screenshot on your website and why?

I would use a PNG format to keep lossless format over JPG you could also use WebP.

Things that can have color

At the element level, everything in HTML can have color applied to it. Instead, let’s look at things in terms of the kinds of things that are drawn in the elements, such as text and borders and so forth. For each, we’ll see a list of the CSS properties that apply color to them.

Text

Boxes

Every element is a box with some sort of content, and has a background and a border in addition to whatever contents the box may have.

` Borders See Below

Borders

Any element can have a border drawn around it. A basic element border is a line drawn around the edges of the element’s content. See Box properties in The box model to learn about the relationship between elements and their borders, and the article Styling borders using CSS to learn more about applying styles to borders.

You can use the border shorthand property, which lets you configure everything about the border in one shot (including non-color features of borders, such as its width, style (solid, dashed, etc.), and so forth.

Questions

  1. Your friend asks you to give his colorless blog website a touch up. How would you use color to give his blog some character?

I would section his blog into topics then color the individual sections and stylize the font in the sections.

  1. What should you consider when choosing fonts for an HTML document?

Making sure the font is compatible with all browsers is a good start.

  1. Describe the difference between foreground and background colors of an HTML element, pretend you are talking to someone with no technical knowledge.

The foreground color is the text color and the backgriound color is the page color.

  1. Describe two ways you could add spacing around the characters displayed in an h1 element.

Creating a new class in CSS and adding margins.

  1. What do font-size, font-weight, and font-style do to HTML text elements?

Font-style is used to turn italics on or off. Font-weight shows how bold the text is. Font-size is how large the test is displayed

Items I need to learn more about

Applying color to HTML elements using CSS

Images in HTML

Image file type and format guide

Return to the Table of Contents: Table of Contents