Developing for the web requires at least 3 things pieces of software:
For our code editor, we will be using Visual Studio Code, which is a free (open source) code editor created and maintained by Microsoft. It also works on Windows, macOS, and Linux. Make sure you have downloaded and installed it on all the computers you will use for web development.
For our web client we will use the many web browsers we introduced in Week 1, namely:
There are many more, and you are highly encouraged to install as many as possible.
We will also need a web server to host our web pages and applications. Installing and running a web server can be complicated. Industry grade web servers like Apache and nginx are free and can be installed and run on your local computer; however, they are much more complicated and powerful than anything we will need for hosting our initial web pages.
For our purposes, we will use a simple node.js based http-server. In order to use it, do the following:
This will download and run the necessary software, and show you the following message:
Starting up http-server, serving ./ Available on: http://127.0.0.1:8080 http://192.168.2.124:8080 Hit CTRL-C to stop the server
You can now open your web browser to
http://127.0.0.1:8080 and load your files.
This uses the
http protocol, and connects you to the special IP address
127.0.0.1, also known as localhost
(i.e., you can also use
http://localhost:8080). The localhost IP address always
refers to this computer, and allows you to connect network clients to your own
machine. The final
:8080 portion of the URL is a port number. Together,
http://127.0.0.1:8080 means connect using HTTP to my local computer on port 8080.
When you are done testing your web site, stop the web server by pressing
in your terminal window. To run the server again, use
NOTE: the second IP address will be different than the above, but 127.0.0.1 will always be correct.
HTML is the HyperText Markup Language. It allows us to write content in a document, just as we would in a file created by a word processor. Unlike a regular text file, it also includes structural and layout information about this content. We literally mark up the text of our document with extra information.
When talking about HTML’s markup, we’ll often refer to the following terms:
>characters, for example the image tag
<h1>Chapter 1</h1>. Here an element is made up of an
<h1>tag (i.e., opening Heading 1 tag), the text content
Chapter 1, and a closing
</h1>tag. These three together create an
h1element in the document.
name="value", for example
<p id="error-message" hidden>There was an error downloading the file</p>. Here two attributes are included with the
"error-message"(in quotes), and the
hiddenattribute (note: not all attributes need to have a value). Full list of common attributes.
&and end with
;. For example, if you need to use the
<character in your document, you need to use
<would be interpreted as part of an HTML tag.
is a single whitespace and
&symbol. Full list of named entities.
Since then, the web has gone through many versions:
Here’s a basic HTML5 web page:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>My Web Page</title> </head> <body> <!-- This is a comment --> <h1>Hello World!</h1> </body> </html>
Let’s break this down and look at what’s happening.
<!doctype html>tells the browser what kind of document this is, and how to interpret/render it
<html>the root element of our document: all other elements will be included with
<head>provides various information about the document as opposed to providing its content. This is metadata that describes the document.
<meta>an example of some piece of metadata, in this case defining the character set used in the document: utf-8
<title>an example of a specific (named) metadata element: the document’s title, shown in the browser’s title bar. There are a number of specific named metadata elements like this.
<body>the content of the document is contained within
<!-- ... -->a comment, similar to using
<h1>a heading element (there are headings 1 through 6), which is a title or sub-title in a document.
Now let’s try creating and loading this file in our browser:
http://localhost:8080in the URL bar
Hello World!in black text.
Now let’s make a change to our document:
index.htmlfile so that instead of
Hello World!you have
This is my web page.
This is my web page.
Every time we update anything in our web page, we have to refresh the web page in our browser. The web server will serve the most recent version of the file on disk when it is requested.
There are dozens of HTML elements you’ll learn and use, but the following is a good set to get you started.
Information about the document vs. the document’s content goes in various metadata elements:
<link>- links from this document to external resources, such as CSS stylesheets
<meta>- metadata that can’t be included via other elements
<title>- the document’s title
These are organizational blocks within the document, helping give structure to the content and provide clues to browsers, screen readers, and other software about how to present the content:
<header>- introductory material at the top of a document
<nav>- content related to navigation (a menu, index, links, etc)
<main>- the main content of the document. For example, a news article’s paragraphs vs. ads, links, navigation buttons, etc.
<h1>, <h2>, ..., <h6>- (sub) headers for different sections of content
<footer>- end material (author, copyright, links)
We organize content into “boxes,” some of which have unique layout characteristics.
<div>- a generic container we use to attach CSS styles to a particular area of content
<ol>- an ordered list (1, 2, 3) of list items
<ul>- an unordered list (bullets) of list items
<li>- a list item in an
<p>- a paragraph
<blockquote>- an extended quotation
We also use elements within larger text content to indicate that certain words or phrases are to be shown differently:
<a>- an “anchor” element, which will produce a hyperlink, allowing users to click and navigate to some other document.
<code>- formats the text as computer code vs. regular text.
<em>- adds emphasis to the text (often in italics)
<span>- another generic container, used to define CSS styles
In addition to text, HTML5 also defines a number of rich media elements:
<img>- an element used to embed images in a document.
<audio>- an element used to embed sound in a document.
<video>- an element used to embed video in a document
We create dynamic web content and applications through the use of scripting: