What an HTML File Is

Getting Started

HTML in One Paragraph

HTML stands for Hyper Text Markup Language. An HTML file is a plain text file containing small markup tags. The tags tell a web browser how to display the page. Save the file with an .html extension, open it in any browser, and you have a web page.

What you need
What you will be able to do
  • A plain text editor: Notepad on Windows, TextEdit on Mac set to plain text, or a code editor such as VS Code
  • Any web browser

Never use a word processor. Word and Google Docs add hidden formatting that breaks the tags. If you use TextEdit, switch it to plain text first (Format, Make Plain Text).

  • Write a page in a text editor
  • Mark up paragraphs, emphasis and special text
  • Link to other pages and to an email address
  • Add images
  • Build tables
  • Apply colors

Saving and Opening

  1. Type your HTML in the text editor.
  2. Save as mypage.html. Make sure the editor does not add .txt on the end.
  3. Double-click the file, or use File, Open in your browser. The address bar shows a path such as C:\MyDocuments\mypage.html.
  4. Edit, save, and reload the browser to see changes.
.htm or .html?
View the source

Either works. .htm comes from the days when some software only allowed three-letter extensions. Pick one and stay consistent: mypage.htm and mypage.html are two different files to the browser.

The fastest way to learn is to read other people’s pages. In any browser, right-click and choose View Page Source, or press Ctrl+U (Cmd+Option+U on Mac). Every tag on this site is there to read.

Your First Page

This is the smallest page from the original workshop. It works, but it is missing the first line every modern page starts with. The next tab has the full HTML5 version to copy.

This code

<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>

Would display

This is my first homepage. This text is bold
  • <html> … </html> — the whole document
  • <head> — information about the page; nothing here shows in the window
  • <title> — the text in the browser tab
  • <body> — everything the visitor sees
  • <b> — bold

The HTML5 Template

Getting Started

Copy This

Paste it into a text editor, save it as index.html, and open it in a browser. Everything you build starts from these lines.

Minimal HTML5 page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Webpage</title>
</head>
<body>

    <h1>My First Webpage</h1>
    <p>This is my first homepage. <strong>This text is bold.</strong></p>

</body>
</html>
LineWhat it does
<!DOCTYPE html>Tells the browser this is an HTML5 document. Always the first line. Older versions needed a long, hard-to-remember doctype; HTML5 reduced it to this.
<html lang="en">The root element. lang tells browsers and screen readers the language of the page.
<head>Information about the page. Nothing inside it is displayed.
<meta charset="UTF-8">The character encoding. UTF-8 covers every language and symbol, so accents, curly quotes and π display correctly.
<meta name="viewport" ...>Makes the page scale properly on phones instead of showing a shrunken desktop layout.
<title>The text in the browser tab and in search results.
<body>Everything the visitor sees goes between these tags.

Starter Page With Sections

The same skeleton with the HTML5 landmark elements, a stylesheet link and a script. Delete what you don’t need.

Starter page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Title</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>

    <header>
        <h1>Site Name</h1>
        <nav>
            <a href="index.html">Home</a>
            <a href="about.html">About</a>
            <a href="mailto:you@example.com">Email</a>
        </nav>
    </header>

    <main>
        <h2>Welcome</h2>
        <p>Your content goes here.</p>
        <img src="images/photo.jpg" alt="Describe the picture" width="300" height="200">
        <ul>
            <li>First item</li>
            <li>Second item</li>
        </ul>
    </main>

    <footer>
        <p>&copy; 2026 Your Name</p>
    </footer>

    <script src="script.js"></script>
</body>
</html>
LandmarksNew in HTML5
Linking files
  • <header> — top of the page or of a section
  • <nav> — a group of links
  • <main> — the main content, once per page
  • <section>, <article>, <aside> — parts of the content
  • <footer> — bottom of the page or of a section

They display like plain <div> blocks, but they tell browsers, search engines and screen readers what each part is.

  • <link rel="stylesheet" href="styles.css"> goes in the head and attaches a CSS file
  • <script src="script.js"></script> goes just before </body> so the page content loads first
  • Paths are relative to the HTML file, exactly like image paths (see the Images tab)

History and Versions

Getting Started

How HTML Got Here

HTML was invented so physicists could share documents. Every version since has been a negotiation between browser makers adding features and standards bodies trying to keep pages working everywhere.

VersionYearWhoWhat it brought
HTML (first draft)1991Tim Berners-Lee, CERNAbout 18 tags for headings, paragraphs, lists and links. Built on SGML. Came with the first browser and web server.
HTML 2.01995IETF (RFC 1866)The first official standard. Collected what browsers already did: forms, images (<img>, added by Mosaic in 1993), basic text markup.
HTML 3.21997W3CStandardized tables, applets and text flowing around images. Absorbed the browser-war extras such as <font> and bgcolor that Netscape and Internet Explorer had invented.
HTML 4.0 / 4.011997 / 1999W3CSeparated structure from presentation: style sheets (CSS) take over appearance, and <font>, align, bgcolor are deprecated. Added scripting, frames, richer forms and accessibility features. Three flavors: Strict, Transitional, Frameset.
XHTML 1.02000W3CHTML 4.01 rewritten as XML: lowercase tags, every element closed, every attribute quoted. Strict and unforgiving. The planned XHTML 2.0 was abandoned in 2009.
HTML52008 draft, 2014 standardWHATWG, then W3CBrowser makers (Apple, Mozilla, Opera) formed the WHATWG in 2004 to evolve HTML pragmatically; the W3C adopted the work in 2007 and published it as a Recommendation on 28 October 2014. HTML 5.1 followed in 2016 and 5.2 in 2017.
HTML Living Standard2019 onwardWHATWGThe W3C and WHATWG agreed there is one HTML, maintained continuously by the WHATWG. Version numbers were dropped; “HTML5” now just means modern HTML.

What HTML5 Changed

Added
Removed or replaced by CSS
  • A one-line doctype: <!DOCTYPE html>
  • Landmark elements: <header>, <nav>, <main>, <section>, <article>, <aside>, <footer>, <figure>
  • Native media: <audio>, <video>, <canvas>, inline SVG
  • Form input types such as email, date, number, range, with built-in validation
  • Browser APIs: local storage, geolocation, drag and drop, offline pages
  • Forgiving parsing: every browser now handles broken markup the same way
  • <font>, <center>, <big>, <tt>, <strike>, <acronym>, <frame>
  • bgcolor, background, align, width on tables, cellpadding, cellspacing, border
  • Tables as a layout tool. Tables are for data; CSS grid and flexbox handle layout
  • The name attribute on <a> for page anchors; use id on any element

Browsers still render most of the old tags and attributes, which is why the workshop examples on this sheet still work. New pages should not use them.

Tags, Elements and Nesting

Tags and Elements

What Tags Are

  • Tags mark up HTML elements and are surrounded by angle brackets: < and >
  • They normally come in pairs: a start tag <b> and an end tag </b>
  • The text between them is the element’s content
  • Tags are not case sensitive; <B> means the same as <b>. Write them in lowercase anyway: the W3C recommended it in HTML 4, XHTML required it, and it is the universal convention
Anatomy of an element
Empty elements
<b>This text is bold</b>
  • Start tag: <b>
  • Content: This text is bold
  • End tag: </b>

The <body> element works the same way; it just has other elements as its content.

Some elements have no content and no end tag: <br>, <hr>, <img>, <meta>, <link>. XHTML wrote them as <br />; in HTML5 the slash is optional.

Nesting

When elements sit inside each other, the last one opened is the first one closed. It does not matter which tag comes first, only that they close in reverse order.

Wrong
Right
<p><b><em>This is NOT the proper way.</p></em></b>
<p><b><em>This is the proper way.</em></b></p>

Both versions usually look right, because browsers repair bad nesting silently. The repair is a guess, and the guess changes from one page to the next: a stray <b> that is never closed can make the rest of the page bold, and an unclosed <a> turns every following word into a link. Read your tags as a stack: open p, open b, open em, so close em, close b, close p.

The three nesting mistakes beginners actually make. (1) Forgetting an end tag, most often </p>, </li> or </div>; the symptom is formatting that “leaks” into everything below. (2) Putting a block element inside an inline one, such as <a><p>…</p></a> in older HTML or <span><div>; keep blocks outside spans. (3) Typing the closing slash in the wrong place: <b/> is not an end tag, </b> is. When a page breaks, indent your source so each child sits one step in from its parent; the missing tag becomes obvious.

The Basic Tags

TagDefinesUse it whenExample
<html>An HTML documentAlways; it wraps everything except the doctype, exactly once<html lang="en"> … </html>
<head>Information about the document (title, character set, stylesheets)Always; anything that describes the page rather than appears on it<head><title>Menu</title></head>
<title>The title shown in the browser tabAlways; it is also the text of a bookmark and a search result<title>Sam’s Cafe: Menu</title>
<body>The document’s visible contentAlways; one per page, after the head<body><p>Hello</p></body>
<h1> to <h6>Headings, largest to smallestOne h1 for the page title, h2 for each section, h3 inside a section; never for size alone<h2>Opening Hours</h2>
<p>A paragraphEvery block of running text; the browser adds a blank line before and after<p>We open at nine.</p>
<br>A single line breakA new line inside a paragraph: addresses, poems, song lyrics12 High St<br>Austin, TX
<hr>A horizontal ruleA change of topic within a page; shows as a thin line across the width<p>End of part one.</p><hr>
<!-- -->A comment, ignored by the browserNotes to yourself or to hide a block temporarily; visible in View Source, so never put secrets in one<!-- TODO: add the map -->

The browser shows nothing for html, head, title and body themselves; they are the frame. The first thing a visitor sees is the first element inside body.

Attributes and Quotes

Tags and Elements

Name and Value

A tag tells the browser to do something; an attribute tells it how. Attributes go in the start tag as name="value" pairs, and the value is always quoted.

Examples from the workshop
Global attributes you will use today
<body bgcolor="blue">
<table border="0">
<a href="page.html">

Removed in HTML5 bgcolor and border are presentational and gone from HTML5. Use CSS href is still exactly how links work.

  • id — a unique name for one element, used by links and CSS
  • class — a name shared by several elements, used by CSS
  • title — text that appears when the mouse rests on the element
  • style — inline CSS, such as style="color: red"
  • lang — the language of the element’s text

Three attribute mistakes to check first when something will not work. (1) A missing closing quote: <a href="page.html>Next</a> swallows everything up to the next quote mark on the page, often making a whole paragraph vanish. (2) A space on either side of the equals sign or inside the value: href = "page.html" is tolerated, but src="my photo.jpg" fails if the file is really my_photo.jpg; file names must match exactly, including capitals. (3) Using the same id twice: links and CSS will only ever find the first one. If several elements share a label, that label is a class.

Double or Single Quotes

Double quotes are the norm. Single quotes are allowed and are necessary when the value itself contains double quotes:

name='George "Machine Gun" Kelly'

Deprecated means on its way out. The W3C marks a tag or attribute deprecated when it is scheduled for removal. Browsers keep supporting deprecated features for compatibility, but new pages should use the replacement, which for presentation is always CSS.

Headings, Paragraphs and Breaks

Tags and Elements

Headings

<h1> is the largest heading and <h6> the smallest. Browsers add space above and below each one. Use headings in order for structure, not to make text big; size belongs to CSS.

This code

<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
<h4>This is a heading</h4>
<h5>This is a heading</h5>
<h6>This is a heading</h6>

Would display

This is a heading

This is a heading

This is a heading

This is a heading

This is a heading
This is a heading

Common mistakes: more than one <h1> on a page (keep one, the page title); skipping levels, h1 straight to h4, because the smaller size looked nicer; and wrapping a whole paragraph in a heading to make it bold. Screen readers and search engines read the headings as the outline of your page, so the levels should read like a table of contents.

Removed in HTML5 <h5 align="center"> centered a heading in HTML 4. Use CSS text-align: center does it now.

Paragraphs

A paragraph is a block of text. The browser ignores the line breaks, indents and blank lines in your source; without <p> tags the whole document runs together as one paragraph.

This code

<p>This is a paragraph</p>
<p>this is another paragraph</p>

Would display

This is a paragraph

this is another paragraph

What the browser shows: each paragraph starts on its own line with a blank line’s worth of space above and below, however many returns you typed in the source. Common mistakes: stacking <br><br> or empty <p></p> tags to push content down (use CSS margin instead) and forgetting </p>, which usually still renders but makes the next element inherit the paragraph’s styles unpredictably.

Line Breaks and Horizontal Rules

<br>A new line without a new paragraph
<hr>A divider between sections

This code

<p>This <br> is a para<br> graph with
line breaks</p>

Would display

This
is a para
graph with line breaks

No closing tag. Use it for addresses and poems, not to space things out.

This code

<p>Above the rule</p>
<hr>
<p>Below the rule</p>

Would display

Above the rule


Below the rule

Removed in HTML5 width="50%" and align on a rule. Use CSS width and margin.

Comments

Anything between <!-- and --> is ignored by the browser but visible in the source. Use comments for notes to yourself or to whoever reads your code next. Note the exclamation mark after the opening bracket and not before the closing one.

This code

<p>This html comment would <!-- This
is a comment --> be displayed like
this.</p>

Would display

This html comment would be displayed like this.

Logical and Physical Text Tags

Tags and Elements

Two Kinds of Tag

Logical tagsDescribe what the text means
Physical tagsDictate how the text looks

<strong> tells the browser the text is important. Browsers show it bold by default, but a screen reader can stress it and a stylesheet can restyle it. Prefer these: they are more uniformly supported and they keep meaning separate from looks.

<b> just says “make this bold”. Physical tags were invented to style pages before style sheets existed. HTML5 kept a few and gave them new meanings; for anything purely visual, use CSS.

Logical Tags

TagDefinesStatus
<abbr>An abbreviation; title holds the full text and shows as a tooltip: <abbr title="as soon as possible">ASAP</abbr>HTML5
<acronym>An acronymRemoved in HTML5 use <abbr>
<address>Contact information for the page or articleHTML5
<cite>The title of a work being cited, shown in italics: <cite>Moby-Dick</cite>HTML5
<code>Computer code, a file name or a command, shown in a monospace font: type <code>dir</code> to list filesHTML5
<blockquote>A long quotation, usually indentedHTML5
<del>Deleted text, usually struck through: Was <del>$20</del> now $15HTML5
<dfn>The defining instance of a term, the first time you explain it: A <dfn>tag</dfn> is a label in angle bracketsHTML5
<em>Emphasized text, usually italic; it changes how a sentence is read: I <em>did</em> send itHTML5
<ins>Inserted text, usually underlined; pairs with <del> to show an edit: <del>Monday</del> <ins>Tuesday</ins>HTML5
<kbd>Keys the reader should press: Press <kbd>Ctrl</kbd>+<kbd>S</kbd>HTML5
<pre>Preformatted text; spaces and line breaks are keptHTML5
<q>A short inline quotation; the browser adds the quotation marks: She said <q>no</q>.HTML5
<samp>Sample program output, what the computer printed: <samp>File not found</samp>HTML5
<strong>Important text, usually bold: <strong>Warning:</strong> hot surfaceHTML5
<var>A variable or placeholder, usually italic: Type your <var>username</var>HTML5

How to choose: ask what the text is, not how it should look. A product name you want bold is a strong only if it is important; a book title is a cite; a key the reader presses is a kbd. If no logical tag fits and you only want a look, use a span with a class and style it in CSS.

Physical Tags

TagDefinesStatus
<b>Bold textHTML5 now means “stylistically offset”, such as keywords
<big>Bigger textRemoved in HTML5
<i>Italic textHTML5 now means an alternate voice, such as a term or a ship name
<small>Smaller textHTML5 now means side comments and fine print
<sup>SuperscriptHTML5
<sub>SubscriptHTML5
<tt>Teletype (monospace) textRemoved in HTML5 use <code> or CSS
<u>UnderlineHTML5 but avoid it: readers expect underlines to be links

<b> and <strong> look identical, as do <i> and <em>; the difference is what a screen reader or a search engine makes of them. A quick rule: if removing the formatting would change the meaning of the sentence, use strong or em; if it would only change the look (a keyword list, a Latin species name), use b or i.

Examples

This code

<blockquote>We the people of the United States, in order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.</blockquote>

Would display

We the people of the United States, in order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.

Browsers indent a blockquote, but indenting is not its purpose; it marks a quotation. Use CSS margins to indent ordinary text.

This code

<abbr title="World Wide Web">WWW</abbr>

Would display

WWW  (rest the mouse on it)

Character Entities

Tags and Elements

Characters With a Special Meaning

The less-than sign starts a tag, so you cannot type it as text. To display such characters you write an entity: an ampersand, a name or a number, and a semicolon.

ResultDescriptionEntity nameEntity number
non-breaking space&nbsp;&#160;
<less than&lt;&#60;
>greater than&gt;&#62;
&ampersand&amp;&#38;
"quotation mark&quot;&#34;
'apostrophe&apos;&#39;
©copyright&copy;&#169;
—em dash&mdash;&#8212;
  • Names are easier to remember; numbers work in every browser, including very old ones
  • Entities are case sensitive: &LT; is not &lt;
  • HTML5 &apos; did not work in old Internet Explorer; every current browser supports it
  • HTML5 With <meta charset="UTF-8"> you can also type most symbols directly, such as © or π. Only <, > and & must stay as entities

The Non-Breaking Space

HTML collapses runs of spaces to one. Ten spaces in the source become one on the page. &nbsp; forces a space the browser will keep, and it also stops a line from breaking at that point.

This code

<p>This code                 would appear
as this.</p>

Would display

This code would appear as this.

This code

<p>This code &nbsp;&nbsp;&nbsp; would appear with three extra spaces.</p>

Would display

This code     would appear with three extra spaces.

Do not use rows of &nbsp; to position things. That is what CSS padding and margins are for.

Color Values

Color and Backgrounds

Hexadecimal and RGB

A color is a mix of red, green and blue light. Each channel runs from 0 (hex 00) to 255 (hex FF). A hex color is #RRGGBB; the same mix can be written rgb(r, g, b).

ColorHexRGBName
#000000rgb(0,0,0)black
#FF0000rgb(255,0,0)red
#00FF00rgb(0,255,0)lime
#0000FFrgb(0,0,255)blue
#FFFF00rgb(255,255,0)yellow
#00FFFFrgb(0,255,255)aqua
#FF00FFrgb(255,0,255)fuchsia
#C0C0C0rgb(192,192,192)silver
#FFFFFFrgb(255,255,255)white

256 × 256 × 256 is more than 16 million colors. Every modern screen can show all of them.

Color Names

HTML 4 guaranteed only 16 names: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white and yellow. For anything else the workshop recommended hex. Today CSS defines about 140 names that every browser supports, such as these:

ColorHexName
#F0F8FFAliceBlue
#FAEBD7AntiqueWhite
#7FFFD4Aquamarine
#000000Black
#0000FFBlue
#8A2BE2BlueViolet
#A52A2ABrown

Web Safe Colors

When most computers could show only 256 colors, a palette of 216 “web safe” colors (built from the values 00, 33, 66, 99, CC and FF) was proposed so pages looked the same on Windows and Mac. Screens moved past 256 colors long ago, so the palette is history. Use any hex value you like.

Backgrounds and Fonts

Color and Backgrounds

Background Color and Image

In HTML 4 the <body> tag took two attributes: bgcolor for a color (hex, rgb or name) and background for an image URL. A small image tiles until it fills the window.

The workshop’s wayDeprecated in HTML 4, removed in HTML5
The CSS wayWhat to write today
<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">

<body background="clouds.gif">
<body background="http://example.com/clouds.gif">

All three bgcolor lines set black. The image URL can be relative or absolute.

<style>
    body {
        background-color: #000000;
        background-image: url("clouds.gif");
    }
</style>

Put this in the <head>, or in a linked stylesheet. If the image fails to load, the color shows instead, exactly as before.

Before you tile an image, ask: Will it slow the page down? Does it look good with the other images, with the text colors, and when repeated? Does it pull focus from the text? Most of the time a plain color wins.

Fonts

The <font> tag is gone. The W3C removed it from its recommendations, and every browser since has styled text with CSS:

<style>
    body  { font-family: Georgia, serif; font-size: 16px; color: #333333; }
    h1    { font-family: Arial, sans-serif; }
</style>

List more than one font family so the browser has a fallback if the first is not installed.

  • font-family — the typeface. The browser tries each name in order and uses the first one installed on the visitor’s computer; the last name should be a generic family: serif, sans-serif or monospace.
  • font-size — how big. 16px is the browser default for body text; headings are usually set in em or rem so they scale with it.
  • color — the text color, in any of the forms from the Color Values tab. Here #333333 is a dark gray that reads more comfortably than pure black on white.

A font name with a space in it needs quotes: font-family: "Times New Roman", serif;. Forgetting them is the usual reason a font “does not work”.

Lists

Lists, Links and Images

Three Kinds of List

UnorderedBullets
OrderedNumbers

This code

<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>

Would display

  • Coffee
  • Milk

This code

<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>

Would display

  1. Coffee
  2. Milk

Both use <li> for each item. Inside an item you can put paragraphs, line breaks, images, links, or another list. HTML5 <ol> still takes start and reversed; the type attribute for bullet and number styles is now the CSS property list-style-type.

Definition Lists

A term and its description. Three elements: the container <dl>, the term <dt>, and the description <dd>.

This code

<dl>
<dt>Cascading Style Sheets</dt>
<dd>Style sheets are used to provide
presentational suggestions for
documents marked up in HTML.</dd>
</dl>

Would display

Cascading Style Sheets
Style sheets are used to provide presentational suggestions for documents marked up in HTML.

Use a definition list for glossaries, FAQ pages (question in dt, answer in dd) and name-value pairs such as a product’s specifications. The browser shows the term flush left and the description indented beneath it. One term can have several dd descriptions, and several dt terms can share one description.

List mistakes. Text placed directly inside <ul> without an <li> renders, but it is invalid and gets no bullet. A nested list goes inside the item it belongs to, before that item’s </li>: <li>Coffee<ul><li>Espresso</li></ul></li>, not between two items. And a list of steps that must happen in order is an <ol>, even if you would rather not see numbers; hide them with CSS.

Images

Lists, Links and Images

The Image Tag

<img> is empty: attributes only, no closing tag. src (source) is the address of the image file. The browser puts the picture exactly where the tag sits in the text.

<img src="graphics/chef.gif" width="130" height="101" alt="Smiling Happy Chef">
srcWhere the browser looks
src="chef.gif"Same folder as the HTML file
src="images/chef.gif"One folder down, inside images
src="../chef.gif"One folder up
src="../../chef.gif"Two folders up
src="../images/chef.gif"One folder up, then down into images
src="../../../other/images/chef.gif"Three folders up, then down two

graphics/chef.gif means: look in a folder called graphics that sits next to the HTML file. .. means go up one level. The same rules apply to links and stylesheets.

alt, width and height

altAlways include it
width and heightStill a good idea

Text shown if the image cannot load, and read aloud by screen readers. Describe what the picture shows. For a purely decorative image use an empty alt="" so it is skipped.

With the pixel dimensions the browser reserves the space and keeps loading the page, then fills the image in. Without them, the page jumps around as images arrive. HTML5 Still recommended; use CSS to scale the image if needed.

Removed in HTML5 align="center" on an image. Use CSS display: block; margin: 0 auto; centers it.

When the Image Does Not Show

A broken image shows as a small icon with the alt text beside it. Nearly always the browser cannot find the file. Check in this order:

  1. Spelling and capitals. Chef.GIF and chef.gif are different files on a web server, even if Windows treats them as the same on your computer.
  2. The extension. The file may really be chef.jpg; make your editor show file extensions.
  3. The folder. Count the ../ steps against where the HTML file actually sits, not where the image sits.
  4. Spaces in the name. Rename my photo.jpg to my-photo.jpg; spaces break paths.
  5. Whether the file was uploaded. A page that works on your computer and not online usually left the images folder behind.

The most common accessibility mistake is leaving alt off entirely: a screen reader then reads the file name aloud, “IMG underscore 4471 dot jpg”. Write what you would say to someone on the phone.

Table Rows, Cells and Headers

Tables

Rows and Cells

A table is <table>, divided into rows with <tr>, and each row into data cells with <td> (table data). A cell can hold text, images, lists, paragraphs, forms, rules, even another table.

This code

<table>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Would display

row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

Without a border attribute or CSS border, the grid is invisible; only the alignment shows.

Headings

Header cells use <th> instead of <td>. Browsers show them bold and centered, and screen readers use them to announce what each column means.

This code

<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

Would display

Heading Another Heading
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

Table Tags

TagDefinesStatus
<table>A tableHTML5
<tr>A table rowHTML5
<td>A data cellHTML5
<th>A header cellHTML5
<caption>A title for the table, placed as the first child and shown above it: <caption>Opening hours</caption>HTML5
<colgroup>A group of columns, so that a whole column can be styled without touching each cellHTML5
<col>One column inside a colgroup; empty, like br: <col span="2"> covers two columnsHTML5
<thead>, <tbody>, <tfoot>Header, body and footer row groups; a header group repeats on each printed page and lets a long body scroll on its ownHTML5 added since the workshop

To build a table, work from the outside in:

  1. Open <table>.
  2. Add one <tr> for the header row, with a <th> for every column.
  3. Add one <tr> per row of data, with the same number of <td> cells as there are headers.
  4. Close </table>, then add borders and padding in CSS.

Two mistakes produce most broken tables: a row with one cell too few or too many, which pushes everything in that row sideways; and a <td> written outside a <tr>, which the browser silently moves or drops. If a cell must span columns, say so with colspan="2" and leave out that many cells from the row.

Borders, Padding and Size

Tables

Borders

border="1"
border="5"

This code

<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>

Would display

Row 1, cell 1 Row 1, cell 2

This code

<table border="5">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>

Would display

Row 1, cell 1 Row 1, cell 2

What the browser draws: a line around the table and a thinner line around every cell, with a small gap between the two, so the grid looks double. border="5" only thickens the outer frame; the cell lines stay one pixel. Removed in HTML5 The attribute still renders but is gone from the standard. Use CSS table, th, td { border: 1px solid black; } draws the same grid, and border-collapse: collapse; on the table merges the double lines into one.

Cell Spacing and Cell Padding

cellspacingSpace between cells
cellpaddingSpace inside each cell

This code

<table border="1" cellspacing="5">
<tr>
<td>some text</td>
<td>some text</td>
</tr><tr>
<td>some text</td>
<td>some text</td>
</tr>
</table>

Would display

some text some text
some text some text

The width of the gap between cells, in pixels: the thickness of the grid. Default 0.

This code

<table border="1" cellpadding="10">
<tr>
<td>some text</td>
<td>some text</td>
</tr><tr>
<td>some text</td>
<td>some text</td>
</tr>
</table>

Would display

some text some text
some text some text

The gap between a cell’s content and its border. Default 0. Handy when borders are on and the text feels cramped.

Removed in HTML5 border, cellspacing, cellpadding and width on tables. Browsers still honor them, which is why the examples above render, but the CSS equivalents are border, border-spacing, padding on the cells, and width. border-collapse: collapse merges the double lines into one.

Table Width

Fixed widthPixels
Relative widthPercent of the window
<table width="550">

Always 550 pixels wide, whatever the screen.

<table width="80%">

Takes 80 percent of the window, so it fits an 800-pixel screen and a 1920-pixel screen alike. Relative widths mean the visitor never has to scroll sideways, which everyone hates.

Use CSS The same two choices are table { width: 550px; } and table { width: 80%; }. A table is also the one element that will happily grow wider than the screen when a cell holds a long word or a wide image; max-width: 100% on the table, or wrapping it in a block with overflow-x: auto, keeps it in bounds on a phone.

Layout with Tables

Tables

The Old Trick

For years the common way to put a page into columns was a table with no borders and a little cell padding: one row, two cells, menu on the left and content on the right. The text stays inside its column no matter how much you add.

Why it worked
Why we stopped
  • Every browser could draw a table
  • Columns stayed aligned automatically
  • It needed no CSS knowledge
  • Screen readers announce layout tables as data tables, which is confusing
  • The page cannot rearrange itself for a phone screen
  • HTML5 CSS grid and flexbox do columns in a few lines and adapt to any screen
  • Tables are for data: schedules, scores, price lists

The Workshop’s Full Example

Everything from the workshop in one page: a two-row layout table, headings, a list of links, a blockquote with a citation, a rule, an address and an email link. It still renders in every browser. Indenting nested tags, as this example does, makes HTML far easier to read.

mytable2.html

<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<table width="90%" cellpadding="5" cellspacing="0">
  <tr bgcolor="#EDDD9E">
    <td width="200" valign="top"><img src="graphics/contact.gif" width="100" height="100"></td>
    <td valign="top"><h1 align="right">Janet Doeson</h1>
    <h3 align="right">Technical Specialist</h3></td>
  </tr>
  <tr>
    <td width="200">
      <h3>Menu</h3>
      <ul>
        <li><a href="home.html">Home</a></li>
        <li><a href="faq.html">FAQ</a></li>
        <li><a href="contact.html">Contact</a></li>
        <li><a href="http://www.austincc.edu">Links</a></li>
      </ul></td>
    <td valign="top"><h2 align="center">Welcome!</h2>
    <p>Welcome to my first webpage. I created this webpage without the assistance of a
    webpage editor. Just my little text editor and a keen understanding of html.</p>
    <p>Look around. Notice I'm able to use paragraphs, lists and headings. You may not
    be able to tell, but the layout is done with a table. I'm very clever.</p>
    <blockquote>
      <p>I always wanted to be somebody, but now I realize I should have been more specific.</p>
      <cite>Lily Tomlin</cite>
    </blockquote></td>
  </tr>
</table>
<hr width="90%" align="left">
<address>
   Janet Doeson<br>
   Technical Specialist<br>
   512.555.5555
</address>
<p>Contact me at <a href="mailto:jdoeson@acme.com">jdoeson@acme.com</a></p>
</body>
</html>

The Same Page in HTML5

How the layout would be written today: landmark elements for structure, and a few lines of CSS for the two columns.

Modern version

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Janet Doeson</title>
    <style>
        body   { font-family: Arial, sans-serif; margin: 0 5%; }
        header { background-color: #EDDD9E; padding: 5px; display: flex; justify-content: space-between; align-items: center; }
        .cols  { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
    </style>
</head>
<body>
    <header>
        <img src="graphics/contact.gif" width="100" height="100" alt="Janet Doeson">
        <div>
            <h1>Janet Doeson</h1>
            <h3>Technical Specialist</h3>
        </div>
    </header>
    <div class="cols">
        <nav>
            <h3>Menu</h3>
            <ul>
                <li><a href="home.html">Home</a></li>
                <li><a href="faq.html">FAQ</a></li>
                <li><a href="contact.html">Contact</a></li>
                <li><a href="http://www.austincc.edu">Links</a></li>
            </ul>
        </nav>
        <main>
            <h2>Welcome!</h2>
            <p>Welcome to my first webpage. I created this webpage without the assistance of a
            webpage editor. Just my little text editor and a keen understanding of html.</p>
            <blockquote>
                <p>I always wanted to be somebody, but now I realize I should have been more specific.</p>
                <cite>Lily Tomlin</cite>
            </blockquote>
        </main>
    </div>
    <hr>
    <address>
        Janet Doeson<br>
        Technical Specialist<br>
        512.555.5555
    </address>
    <p>Contact me at <a href="mailto:jdoeson@acme.com">jdoeson@acme.com</a></p>
</body>
</html>

Try It Out

The workshop’s exercises in order. Copy each one, save it with the file name shown, and open it in a browser.

These are the original workshop files. They use HTML 4 attributes such as align and bgcolor, which browsers still display. Once each one works, try rewriting it with the HTML5 template and CSS.

1. The skeleton

Save as mypage.html. Open it in your browser.

mypage.html

<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>

2. Headings and paragraphs

Save as mypage2.html. A centered heading, two paragraphs and a line break.

mypage2.html

<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Webpage</h1>
<p>Welcome to my first web page. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
</body>
</html>

3. Backgrounds

Save as mypage3.html. A background image with a fallback color, <strong> and <del>. If the image cannot be found, the color shows.

mypage3.html

<html>
<head>
<title>My First Webpage</title>
</head>
<body background="http://profdevtrain.austincc.edu/html/graphics/clouds.gif" bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create webpages like a <del>beginner</del> pro....<br>
which I am of course.</p>
</body>
</html>

4. A list

Save as mypage4.html. Adds an unordered list of what you have learned.

mypage4.html

<html>
<head>
<title>My First Webpage</title>
</head>
<body bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
Here's what I've learned:
<ul>
<li>How to use HTML tags</li>
<li>How to use HTML colors</li>
<li>How to create Lists</li>
</ul>
</body>
</html>

5. An image and a comment

Save as mypage5.html. Adds a comment the browser ignores and an image with alt text and dimensions. You will need a graphics folder with chef.gif in it, or change the path to a picture you have.

mypage5.html

<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Web page</h1>
<p>Welcome to my first webpage. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
<!-- Who would have guessed how easy this would be :) -->
<p><img src="graphics/chef.gif" width="130" height="101" alt="Smiling Happy Chef" align="center"></p>
<p align="center">This is my Chef</p>
</body>
</html>

6. A table

Save as mytable1.html. Only the body content is shown; wrap it in the skeleton from exercise 1.

mytable1.html (body only)

<table border="1">
<tr>
<td>Tables can be used to layout information</td>
<td>&nbsp; <img src="http://profdevtrain.austincc.edu/html/graphics/chef.gif"> &nbsp;</td>
</tr>
</table>

7. Everything together

Save as mytable2.html. The full layout page from the Layout with Tables tab.

mytable2.html

<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<table width="90%" cellpadding="5" cellspacing="0">
  <tr bgcolor="#EDDD9E">
    <td width="200" valign="top"><img src="graphics/contact.gif" width="100" height="100"></td>
    <td valign="top"><h1 align="right">Janet Doeson</h1>
    <h3 align="right">Technical Specialist</h3></td>
  </tr>
  <tr>
    <td width="200">
      <h3>Menu</h3>
      <ul>
        <li><a href="home.html">Home</a></li>
        <li><a href="faq.html">FAQ</a></li>
        <li><a href="contact.html">Contact</a></li>
        <li><a href="http://www.austincc.edu">Links</a></li>
      </ul></td>
    <td valign="top"><h2 align="center">Welcome!</h2>
    <p>Welcome to my first webpage. I created this webpage without the assistance of a
    webpage editor. Just my little text editor and a keen understanding of html.</p>
    <p>Look around. Notice I'm able to use paragraphs, lists and headings. You may not
    be able to tell, but the layout is done with a table. I'm very clever.</p>
    <blockquote>
      <p>I always wanted to be somebody, but now I realize I should have been more specific.</p>
      <cite>Lily Tomlin</cite>
    </blockquote></td>
  </tr>
</table>
<hr width="90%" align="left">
<address>
   Janet Doeson<br>
   Technical Specialist<br>
   512.555.5555
</address>
<p>Contact me at <a href="mailto:jdoeson@acme.com">jdoeson@acme.com</a></p>
</body>
</html>

8. Create your own page

Build a page from scratch that contains all of the following, then open it in a browser and view its source:

  1. The required page codes: doctype, html, head, title and body
  2. A link to another web page
  3. An email link
  4. A picture
  5. A list of information

Name it with your initials, for example mg_html_basics.html.