Notes: HTML

HTML is an acronym for Hypertext Markup Language. It is a declarative language that instructs by providing code that tells the browser how to organize and render content. Content may be text, images, video, audio, and other types of media.

Browsers

Browsers interpret HTML. Not all browsers are the same. The chart below from Statista shows that Google Chrome has the most market share, followed by Apple Safari and Microsoft Edge.

The HTML language is always evolving. To find out if the HTML you are using will work in the browsers you support, visit the Caniuse page. In the picture below, Caniuse reports that the HTML table tag element is supported in all browsers.

Containment

The word containment refers to the way in which an HTML element may or may not contain other HTML elements or text. Many elements will include other elements or text.

The examples below show elements that contain text.

<h1>Title at the Top of the Page</h1>

<p>This is a paragraph.</p>

The example below shows an element-ordered list that contains other elements, which are list items.

<ol>

<li>Item 1</li>

<li>Item2</li>

</ol>

In the code below, the figure contains an image and a figure caption. The image element, img, will not contain any other elements. The figure caption, figcaptionelement contains text.

<figure>

<img src="dog.jpg">

<figcaption>This is my dog</figcaption>

</figure>

In the table at the bottom of this page, elements that don't use closing tags will not contain other elements. These elemen are marked "no" for closing.

Block and Inline HTML Elements

Block and Inline HTML concepts are essential in setting up page layout. As CSS is added to a page, knowing which elements are blocked and which are inline will become more critical.

For now, it's helpful to understand that block elements use the entire page width, and therefore, any elements following them will be rendered on the next line. Inline elements will be rendered on the same line.

Images are inline elements. If we want images to be rendered on a line by themselves, we need to contain them in a block element. Here is an example of containing them in a div element.

<div>

<img src="dog.jpg">

</div>

Just because an HTML tag element has a closing tag doesn't make it a block element. For example a span tag contains text that will be rendered on the same line.

<span>This is important text.</span>

Semantic HTML

Just like spoken languages evolve so has HTML. Years ago div and span were used as containers for most web pages. Semantic HTML tag elements were introduced to so that the structure that HTML provides would also have meaning. This is important for accessibility. While it is possible to style a div element to look like a button element, the meaning is not the same. The word "semantic" is defined as "meaning in a language".

Screen readers that read web pages for visually impaired users can take advantage of semantic HTML. For example, if a developer uses an article element instead of a div element, it can inform the user that it is reading an article. Visually, the browser would render the article and element the same, so in that respect, these tags are interchangeable. However, if the developer is thinking about accessibility, then these tags are very different.

HTML Attributes

The HTML language is made up of tags that render elements in the browser. HTML attributes are bits of language markup that supplement the rendered element's behavior and/or look. Attributes are words followed by an equal sign and quoted text or numbers.

In the example below, the images have sources, src, height and width attributes. The source attribute tells the browser where to get the image, and the height and width tell it how to size it on the web page. In this example dog.jpg refers to image files with a name dog.jpg that is in the same directory as the HTML file. The width attribute is set to 400px. A px is a unit of measure that is shorthand for pixel. You can think of a pixel as a unit of light emitted on a computer screen. This means that the width of the image will be rendered as 400 of these units wide. To put this in perspective, a mobile device averages 350 pixels, and a laptop averages about 1920 pixels. The height attribute is set to "auto". This ensures the image won't look funny due to stretching and removing the aspect ratio.

<img src="dog.jpg" width="400px" height="auto">

Here's another example of attributes being used. In this example, an anchor tag renders a clickable link. The href attribute is set to a URL that the user can go to just by clicking on the link. The href attribute name is shorthand for hypertext reference. The term "web," used to describe the Internet, came about because sites all over the world are connected by these links.

<a href="https://www.example.com">Example Link</a>

Categorized List of HTML Element Tags

CategoryTagsClosingTag Example

Document

!DOCTYPE html

no

<!DOCTYPE html>

<! Comments -->

no

<!-- Comments -->

html

<html>...</html>

Meta Data

base

no

default target for links <base href="https://www.example.com" target="_blank" >

head

<head>...</head>

link

no

link to CSS file<link href="style.css" rel="stylesheet" type="text/css" />

meta

no

<meta name="viewport" content="width=device-width">

style

local CSS <style>...</style>

title

title appears in the tab of the browser <title>...</title>

Structure

address

Contact Information <address>...</address>

article

<article>...</article>

aside

<aside>...</aside>

body

<body>...</body>

div

<div>...</div>

footer

<footer>...</footer>

h1

<h1>...</h1>

h2

<h2>...</h2>

h3

<h3>...</h3>

h4

<h4>...</h4>

h5

<h5>...</h5>

h6

<h6>...</h6>

header

<header>...</header>

paragraph

<p>...</p>

nav

<nav>...</nav>

section

<section>...</section>

span

<span>...</span>

Grouping

blockquote

<blockquote citation="URL">...</blockquote>

dd

definition contained in description list <dd>...</dd>

dl

description list <dl>...</dd>

dt

term contained in description list <dt>...</dt>

figure

contain photos, diagrams, code, figcaption <figure>...</figure>

figcaption

<figcaption>...</figcaption>

hr

no

horizonal rule <hr>

li

list item contained in ordered or unordered list<li>...</li>

ol

ordered list <ol>...</ol>

pre

preformatted text <pre>...</pre>

ul

unordered list <ul>...</ul>

Embedding

area

no

defines coordinates inside image map <area >

audio

contains source for audio files <audio>...</audio>

canvas

area on web page for drawing graphics <canvas>...</canvas>

embed

no

container for external source like video <embed>

iframe

container to embed a web page from another server <iframe src="" title="">...</iframe>

img

no

image <img srce="" height="" width="">

map

make clickable areas in different parts of a single image <map>...</map>

object

embed external source like video player, web page <object>...</object>

param

no

define parameters in an object <param>...</param>

picture

contain images for responsive web pages <picture>...</picture>

source

no

media sources for video, audio and pictures <source src="" type="">

track

no

used for subtitles and caption in video and audio <track src="" kind="" srclang="" label="">

video

<video>...</video>

Forms

button

<button>...</buton>

datalist

list of selectable options <datalist>...</datalist>

fieldset

group related form elements <fieldset>...</fieldset>

form

<form>...</form>

input

no

<input type="" value="" id="" name="" >

label

<label for=""></label>

legend

caption for a fieldset <legend>...</legend>

meter

renders a bar showing a measurement <meter value="" min="" max="">...</meter>

optgroup

group related options in a select <optgroup label="">...</optgroup>

option

option contained by optgroup, select or datalist <option value="">...</option>

output

output of a calculation <output>...</output>

progress

progress bar <progress value="" max=""></progress>

select

select from a list of options <select>...</select>

textarea

multiline text input <textarea rows="" cols="">...</textarea>

Tabular

caption

table caption <caption>...</caption>

col

no

properties for a colgroup <col span="" style="">

colgroup

contains a set of cols <colgroup>...</colgroup>

table

<table>...</table>

tbody

body of the table <tbody>...</tbody>

td

table detail is a cell in the table <td>...</td>

tfoot

table footer <tfoot>...</tfoot>

th

table header cell <th>...</th>

thead

table header <thead>...</thead>

tr

table is made of of rows containing cells table row <tr>...</tr>

Interactive

details

container for interactive content that can be opened and closed by user <details>...</details>

summary

heading you see for details <summary>...</summary>

dialog

container where you show content by adding an "open" attribute <dialog>...</dialog>

Script

noscript

alternate content if you brower doesn't support javascript <noscript>...</noscript>

script

JavaScript rendered on the web page <script src="script.js">...</script>

template

hidden content container that can be rendered later using JavaScript <template>...</template>

Resources

W3 Schools HTML

W3 Schools Block and Inline Elements

Last updated