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.
- 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
- Type your HTML in the text editor.
- Save as
mypage.html. Make sure the editor does not add.txton the end. - Double-click the file, or use File, Open in your browser. The address bar shows a path such as
C:\MyDocuments\mypage.html. - Edit, save, and reload the browser to see changes.
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
<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>| Line | What 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>© 2026 Your Name</p>
</footer>
<script src="script.js"></script>
</body>
</html><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.
| Version | Year | Who | What it brought |
|---|---|---|---|
| HTML (first draft) | 1991 | Tim Berners-Lee, CERN | About 18 tags for headings, paragraphs, lists and links. Built on SGML. Came with the first browser and web server. |
| HTML 2.0 | 1995 | IETF (RFC 1866) | The first official standard. Collected what browsers already did: forms, images (<img>, added by Mosaic in 1993), basic text markup. |
| HTML 3.2 | 1997 | W3C | Standardized 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.01 | 1997 / 1999 | W3C | Separated 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.0 | 2000 | W3C | HTML 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. |
| HTML5 | 2008 draft, 2014 standard | WHATWG, then W3C | Browser 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 Standard | 2019 onward | WHATWG | The 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
- 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,widthon tables,cellpadding,cellspacing,border- Tables as a layout tool. Tables are for data; CSS grid and flexbox handle layout
- The
nameattribute on<a>for page anchors; useidon 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.
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.
<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 CSSclass— a name shared by several elements, used by CSStitle— text that appears when the mouse rests on the elementstyle— inline CSS, such asstyle="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 sectionsThis 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
<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
| Tag | Defines | Status |
|---|---|---|
<abbr> | An abbreviation; title holds the full text and shows as a tooltip: <abbr title="as soon as possible">ASAP</abbr> | HTML5 |
<acronym> | An acronym | Removed in HTML5 use <abbr> |
<address> | Contact information for the page or article | HTML5 |
<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 files | HTML5 |
<blockquote> | A long quotation, usually indented | HTML5 |
<del> | Deleted text, usually struck through: Was <del>$20</del> now $15 | HTML5 |
<dfn> | The defining instance of a term, the first time you explain it: A <dfn>tag</dfn> is a label in angle brackets | HTML5 |
<em> | Emphasized text, usually italic; it changes how a sentence is read: I <em>did</em> send it | HTML5 |
<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 kept | HTML5 |
<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 surface | HTML5 |
<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
| Tag | Defines | Status |
|---|---|---|
<b> | Bold text | HTML5 now means “stylistically offset”, such as keywords |
<big> | Bigger text | Removed in HTML5 |
<i> | Italic text | HTML5 now means an alternate voice, such as a term or a ship name |
<small> | Smaller text | HTML5 now means side comments and fine print |
<sup> | Superscript | HTML5 |
<sub> | Subscript | HTML5 |
<tt> | Teletype (monospace) text | Removed in HTML5 use <code> or CSS |
<u> | Underline | HTML5 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
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.
| Result | Description | Entity name | Entity number |
|---|---|---|---|
| non-breaking space | |   | |
| < | less than | < | < |
| > | greater than | > | > |
| & | ampersand | & | & |
| " | quotation mark | " | " |
| ' | apostrophe | ' | ' |
| © | copyright | © | © |
| — | em dash | — | — |
- Names are easier to remember; numbers work in every browser, including very old ones
- Entities are case sensitive:
<is not< - HTML5
'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. 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 would appear with three extra spaces.</p>Would display
This code would appear with three extra spaces.
Do not use rows of 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).
| Color | Hex | RGB | Name |
|---|---|---|---|
#000000 | rgb(0,0,0) | black | |
#FF0000 | rgb(255,0,0) | red | |
#00FF00 | rgb(0,255,0) | lime | |
#0000FF | rgb(0,0,255) | blue | |
#FFFF00 | rgb(255,255,0) | yellow | |
#00FFFF | rgb(0,255,255) | aqua | |
#FF00FF | rgb(255,0,255) | fuchsia | |
#C0C0C0 | rgb(192,192,192) | silver | |
#FFFFFF | rgb(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:
| Color | Hex | Name |
|---|---|---|
#F0F8FF | AliceBlue | |
#FAEBD7 | AntiqueWhite | |
#7FFFD4 | Aquamarine | |
#000000 | Black | |
#0000FF | Blue | |
#8A2BE2 | BlueViolet | |
#A52A2A | Brown |
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.
<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-seriformonospace.font-size— how big.16pxis the browser default for body text; headings are usually set inemorremso they scale with it.color— the text color, in any of the forms from the Color Values tab. Here#333333is 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
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
- Coffee
- 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.
Links
Lists, Links and Images
The Anchor Tag
HTML uses the <a> anchor tag to link to another document. href is the address; the text between the tags is what the visitor clicks. An anchor can point to a page, an image, a sound file, a movie, anything with an address.
This code
<a href="http://www.austincc.edu/">Visit ACC!</a>Would display
<a href="http://www.austincc.edu/" target="_blank" rel="noopener">Visit ACC!</a>target="_blank" opens a new window or tab. HTML5 Add rel="noopener" so the new page cannot control the one that opened it.
<a href="mailto:helpdesk@austincc.edu">Email Help Desk</a>
<a href="mailto:helpdesk@austincc.edu?subject=Email Assistance">Email Help Desk</a>mailto: opens the visitor’s email program. ?subject= fills in a subject line.
Absolute or relative? href="https://www.austincc.edu/" is absolute: the full address, used for other websites. href="about.html" is relative: a file next to this one, used for pages on your own site, and it keeps working when the site moves. The classic mistake is href="www.example.com" with no https://: the browser treats it as a relative file name and looks for a file called www.example.com in your folder.
Jumping to a Spot on the Page
A link can target a specific section instead of the top of a page. Mark the spot, then link to it with # and its name. If the browser cannot find the name it simply goes to the top; no error.
<a name="top">Text to be displayed</a>
<a href="#top">Back to top of page</a>
<a href="http://example.com/10links.html#top">Back to top</a>Removed in HTML5 The name attribute on <a>.
<h2 id="top">Text to be displayed</h2>
<a href="#top">Back to top of page</a>
<a href="http://example.com/10links.html#top">Back to top</a>Any element can carry an id, and the link syntax is the same. This is how a table of contents at the top of a long page works.
Trailing slash. Link to folders as http://example.com/html/, not http://example.com/html. Without the slash the server has to answer once to add it and the browser asks again: two requests instead of one.
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">| src | Where 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
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:
- Spelling and capitals.
Chef.GIFandchef.gifare different files on a web server, even if Windows treats them as the same on your computer. - The extension. The file may really be
chef.jpg; make your editor show file extensions. - The folder. Count the
../steps against where the HTML file actually sits, not where the image sits. - Spaces in the name. Rename
my photo.jpgtomy-photo.jpg; spaces break paths. - Whether the file was uploaded. A page that works on your computer and not online usually left the
imagesfolder 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
| Tag | Defines | Status |
|---|---|---|
<table> | A table | HTML5 |
<tr> | A table row | HTML5 |
<td> | A data cell | HTML5 |
<th> | A header cell | HTML5 |
<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 cell | HTML5 |
<col> | One column inside a colgroup; empty, like br: <col span="2"> covers two columns | HTML5 |
<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 own | HTML5 added since the workshop |
To build a table, work from the outside in:
- Open
<table>. - Add one
<tr>for the header row, with a<th>for every column. - Add one
<tr>per row of data, with the same number of<td>cells as there are headers. - 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
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
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
<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.
- 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> <img src="http://profdevtrain.austincc.edu/html/graphics/chef.gif"> </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:
- The required page codes: doctype, html, head, title and body
- A link to another web page
- An email link
- A picture
- A list of information
Name it with your initials, for example mg_html_basics.html.