The HTML Boilerplate
Learning Objectives:
- UTF-8
- HTML Boilerplate
- Linking files in HTML via relative and absolute pathing (http/https only)
Watch These Videos
- HTML Video 1 ~ 14 minutes
- UTF-8 : The Unicode Miracle ~ 9.5 minutes
- Why HTML seems to tolerate mistakes ~ 10 minutes
About HTML Boilerplates
Boilerplate is defined as a standard template of any kind that can be used without much modification.
Lesson Objective
Build an HTML boilerplate and take the time to understand each component's function.
-
HTML documents have some standard elements that are always included:
<!DOCTYPE html>
Put this tag at the top of the document, to declare that this is an HTML5 document
Additional boilerplate tags include
<html>
<head>
<body>
<meta charset="utf-8">
<title>
Ask Yourself:
- What is the function of the
<head>
and<body>
tags? - What kind of tags go inside each one?
- Where does the
<title>
tag go (<head>
or<body>
)? - Where on the web page does the text inside the
<title>
tag appear?
Other things to think about:
- What does
<meta charset="utf-8">
do? (hint see above video) - According to the above video about HTML, what could you guess would happen if you forgot the
<html>
tags?
Make a Boilerplate
There are usually a few common elements that are included in most HTML sites, including folders (for organization), CSS files and JavaScript files. Let's add them, so you can have a boilerplate ready to go whenever you start a new homework or project.
File Structure
What it looks like in your terminal:
What it looks like in your browser (GUI):
Create files and folders
Note: I have a boilerplate
folder already created within this morning's morning_exercise
directory with the files and folders that you will need. Feel free to reference this.
Inside today's Morning Exercise folder:
- Make a new folder (
mkdir
) calledproject-boilerplate
- Navigate into the folder
cd project-boilerplate
Make an HTML file
- touch
index.html
Make a JavaScript file
- touch
app.js
- open
app.js
to edit the file in your text editor - make a
console.log
in the JS file so that you can verify that it is hooked up. So, on line 1 of yourapp.js
file, write the codeconsole.log("My app.js file is attached")
.
Note: if you have more than one JavaScript file, it would be typical to put those files all in a folder called js
(or a similar name - see example with CSS)
Make CSS folder and file
- Create a new folder for your css
mkdir css
- Navigate inside the
css
folder and create a file calledstyle.css
- Use your text editor to edit your
style.css
file. - Select the
body
and give it abackground-color
of any color of your choosing - Take a moment to think about how you can tell if you have successfully linked your stylesheet.
Connect Your Files
- Open your
index.html
in your text editor - Write your HMTL code (see above and reference the videos). HINT: your text editor has a built-in way to create an HTML boilerplate! On line 1 of your
index.html
file, typeHTML
and selectHTML:5
- If you automatically made the tags, they should be tabbed and nested appropriately. If you wrote it from scratch, make sure to nest the tags to show the child / parent relationship.
- Add a link to your
app.js
(where does it go? In the head? in the body?) - Check that it works by looking for the
console.log
that you added in theConsole
tab of your Inspector. - Add a link to your css (where does it go? In the head? in the body?)
- Test it to be sure it works (how can you tell?)
Add a few more common elements
Image tag
- Find an image on the internet that brings you joy
- Copy its URL
- Add an image tag
<img/>
inside the body that will display your image - You will need to give the
<img/>
tag ansrc
attribute and set its value to the image's url. - It is good practice to also add an alt attribute to an
</img>
tag. Why? What does this attribute do?
Heading Level 1 tag
- Add an
<h1>
tag to describe the image you have added
Anchor tag <a>
- Add an anchor tag
<a>
that links to a#
. This will not take you anywhere, but gives the illusion of a link.
Paragraph & Questions
- Use a paragraph tag inside your html and write a short answer to the following: Why were
<b>
(bold) and<i>
(italics) tags replaced by<strong>
(strong) and<em>
(emphasis) tags as the new standard in HTML 5?