M1D2: Introduction to HTML

Frontend Developer Roadmap

Summary

  • HTML stands for HyperText Markup Language and is used to create the structure and content of a webpage.
  • Most HTML elements contain opening and closing tags with raw text or other HTML tags between them.
  • HTML elements can be nested inside other elements. The enclosed element is the child of the enclosing parent element.
  • Any visible content should be placed within the opening and closing <body> tags.
  • Headings and sub-headings, <h1> to <h6> tags, are used to provide titles for sections of content.
  • <p><span> and <div> tags specify text or blocks.
  • The <em> and <strong> tags are used to emphasize text.
  • Line breaks are created with the <br> tag.
  • Ordered lists (<ol>) are numbered and unordered lists (<ul>) are bulleted.
  • Images (<img>) and videos (<video>) can be added by linking to an existing source.

Here are a few more resources to add to your toolkit:


HTML provides structure to the content appearing on a website, such as images, text, or videos. Right-click on any page on the internet, choose “Inspect,” and you’ll see HTML in a panel of your screen.

HTML stands for HyperText Markup Language:

  • markup language is a computer language that defines the structure and presentation of raw text.
  • In HTML, the computer can interpret raw text that is wrapped in HTML elements.
  • HyperText is text displayed on a computer or device that provides access to other text through links, also known as hyperlinks

HTML Structure

HTML is organized as a collection of family tree relationships.

When an element is contained inside another element, it is considered the child of that element. The child element is said to be nested inside of the parent element.

<body>
  <p>This paragraph is a child of the body</p>
</body>

Since there can be multiple levels of nesting, this analogy can be extended to grandchildren, great-grandchildren, and beyond. The relationship between elements and their ancestor and descendent elements is known as hierarchy.

<body>
  <h1>Hello World</h1>
  <p>This paragraph is a child of the body element</p>
  <div>
  <p>This paragraph is a child of the div element and a grandchild of the body element</p>
  </div> 
</body>

Understanding HTML hierarchy is important because child elements can inherit behavior and styling from their parent element. 

Headings

In HTML, there are six different headings, or heading elementsHeadings can be used for a variety of purposes, like titling sections, articles, or other forms of content.

The following is the list of heading elements available in HTML. They are ordered from largest to smallest in size.

  1. <h1> — used for main headings. All other smaller headings are used for subheadings.
  2. <h2>
  3. <h3>
  4. <h4>
  5. <h5>
  6. <h6>
<body>
  <h1>The Brown Bear</h1>
  <h2>About Brown Bears</h2>
  <h3>Species</h3>
  <h3>Features</h3>
  <h2>Habitat</h2>
  <h3>Countries with Large Brown Bear Populations</h3>
  <h3>Countries with Small Brown Bear Populations</h3>
  <h2>Media</h2>
</body>

Divs

<div> is short for “division” or a container that divides the page into sections. These sections are very useful for grouping elements in your HTML together.

<div>s don’t inherently have a visual representation, but they are very useful when we want to apply custom styles to our HTML elements. <div>s allow us to group HTML elements to apply the same styles for all HTML elements inside. We can also style the <div> element as a whole.

<body>
  <h1>The Brown Bear</h1>
  <div>
    <h2>About Brown Bears</h2>
    <h3>Species</h3>
    <h3>Features</h3>
  </div>
  <div>
    <h2>Habitat</h2>
    <h3>Countries with Large Brown Bear Populations</h3>
    <h3>Countries with Small Brown Bear Populations</h3>
  </div>
  <div>
    <h2>Media</h2>
  </div>
</body>

Attributes

If we want to expand an element’s tag, we can do so using an attribute. Attributes are content added to the opening tag of an element and can be used in several different ways, from providing information to changing styling. Attributes are made up of the following two parts:

  • The name of the attribute
  • The value of the attribute

One commonly used attribute is the id. We can use the id attribute to specify different content (such as <div>s) and is really helpful when you use an element more than once. ids have several different purposes in HTML, but for now, we’ll focus on how they can help us identify content on our page.

<body>
  <h1>The Brown Bear</h1>
  <div id="introduction">
    <h2>About Brown Bears</h2>
    <h3>Species</h3>
    <h3>Features</h3>
  </div>
  <div id="habitat">
    <h2>Habitat</h2>
    <h3>Countries with Large Brown Bear Populations</h3>
    <h3>Countries with Small Brown Bear Populations</h3>
  </div>
  <div id="media">
    <h2>Media</h2>
  </div>
</body>

Displaying Text

  • Paragraphs (<p>)contain a block of plain text.
  • <span> contains short pieces of text or other HTML. They are used to separate small pieces of content that are on the same line as other content.
<div>
  <h1>Technology</h1>
</div>
<div>
  <p><span>Self-driving cars</span> are anticipated to replace up to 2 million jobs over the next two decades.</p>
</div>

In the example above, there are two different <div>. The second <div> contains a <p> with <span>Self-driving cars</span>. This <span> element separates “Self-driving cars” from the rest of the text in the paragraph.

It’s best to use a <span> element when you want to target a specific piece of content that is inline, or on the same line as other text. If you want to divide your content into blocks, it’s better to use a <div>.

Styling Text

The <em> tag emphasizes text, while the <strong> tag highlights important text.

  • The <em> tag will generally render as italic emphasis.
  • The <strong> will generally render as bold emphasis.
<p><strong>The Nile River</strong> is the <em>longest</em> river in the world, measuring over 6,850 kilometers long (approximately 4,260 miles).</p>

Line Breaks

The spacing between code in an HTML file doesn’t affect the positioning of elements in the browser. If you are interested in modifying the spacing in the browser, you can use HTML’s line break element: <br>.

The line break element is unique because it is only composed of a starting tag. You can use it anywhere within your HTML code and a line break will be shown in the browser.

<p>The Nile River is the longest river <br> in the world, measuring over 6,850 <br> kilometers long (approximately 4,260 <br> miles).</p>

Unordered Lists

In HTML, you can use an unordered list tag (<ul>) to create a list of items in no particular order. An unordered list outlines individual list items with a bullet point.

The <ul> element should not hold raw text and won’t automatically format raw text into an unordered list of items. Individual list items must be added to the unordered list using the <li> tag. The <li> or list item tag is used to describe an item in a list.

<ul>
  <li>Limes</li>
  <li>Tortillas</li>
  <li>Chicken</li>
</ul>

Ordered Lists

Ordered lists (<ol>) are like unordered lists, except that each list item is numbered.

You can create the ordered list with the <ol> tag and then add individual list items to the list using <li> tags.

<ol>
  <li>Preheat the oven to 350 degrees.</li>
  <li>Mix whole wheat flour, baking soda, and salt.</li>
  <li>Cream the butter, sugar in separate bowl.</li>
  <li>Add eggs and vanilla extract to bowl.</li>
</ol>

Images

The <img> tag allows you to add an image to a web page. Most elements require both opening and closing tags, but the <img> tag is a self-closing tag. Note that the end of the <img> tag has a forward slash /. Self-closing tags may include or omit the final slash — both will render properly.

<img src="image-location.jpg" />

The <img> tag has a required attribute called src. The src attribute must be set to the image’s source, or the location of the image. In this case, the value of src must be the uniform resource locator (URL) of the image. A URL is the web address or local address where a file is stored.

Image Alts

The alt attribute, which means alternative text, brings meaning to the images on our sites. The alt attribute can be added to the image tag just like the src attribute. The value of alt should be a description of the image.

<img src="#" alt="A field of yellow sunflowers" />

The alt attribute also serves the following purposes:

  • If an image fails to load on a web page, a user can mouse over the area originally intended for the image and read a brief description of the image. This is made possible by the description you provide in the alt attribute.
  • Visually impaired users often browse the web with the aid of screen reading software. When you include the alt attribute, the screen reading software can read the image’s description out loud to the visually impaired user.
  • The alt attribute also plays a role in Search Engine Optimization (SEO), because search engines cannot “see” the images on websites as they crawl the internet. Having descriptive alt attributes can improve the ranking of your site.

Videos

In addition to images, HTML also supports displaying videos. Like the <img> element, the <video> element requires a src attribute with a link to the video source. Unlike the <img> element however, the <video> element requires an opening and a closing tag.

<video src="myVideo.mp4" width="320" height="240" controls>
  Video not supported
</video>

In this example, the video source (src) is "myVideo.mp4". The source can be a video file that is hosted alongside your webpage, or a URL that points to a video file hosted on another webpage.

After the src attribute, the width and height attributes are used to set the size of the video displayed in the browser. The controls attribute instructs the browser to include basic video controls such as pausing and playing.

The text, Video not supported, between the opening and closing video tags will only be displayed if the browser is unable to load the video.


This entry was posted in Study Notes and tagged , . Bookmark the permalink.

One Response to M1D2: Introduction to HTML

  1. Pingback: Month 1 – Day 2 – rose learns.to('code');

Leave a Reply