Week 2 Lecture Slides
Week 2 Lecture Slides
Root element
<html>
Element Element
<head> <body>
Doctype
• HTML5
• <!DOCTYPE html>
• Previous versions dictated backwards compatibility
• <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
• <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
INTRODUCTION
Document Object Model (DOM)
TO HTML5
Head
• Additional information used by the browser
• Meta data – language, title
• Supporting files – JavaScript, Styling, Add-ons
Body
• Bulk of your page
Example
• Example: template.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body>
This should be displayed by the browser.
</head>
</html>
INTRODUCTION
Document Object Model (DOM)
TO HTML5
INTRODUCTION
Document Object Model (DOM)
TO HTML5
Success!!
INTRODUCTION
Document Object Model (DOM)
TO HTML5
Review
• Well-formed pages use the DOM structure
• Use beginning and end tags
• Close inner tags before outer ones
• Use valid attributes
HTML tags
• I can’t teach you all of the tags
<h1>Hello World</h1>
Start tag Closing tag
<img src="x.gif">
Self-closing tag
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Display
• One of the most important attributes of an element
is its display. The two most common are block and
inline
▪ block (can take width and height)
▪ Newline is inserted before and after, e.g. it “Takes up” whole
width
▪ inline (can not take width and height)
▪ Only uses as much space as needed to contain the element.
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Common Tags
• Headings (block)
• <h1>, <h2>, <h3>, <h4>, <h5>, <h6>
• These tags have syntax and semantics
• Paragraphs (block)
• <p> …. </p>
• Should only contain inline elements
• Divs (block)
• <div>...</div>
• Generic section that is larger than a paragraph
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
More tags
● Ordered lists ● Unordered lists
<ol> <ul>
<li> Item One </li> <li> Item One </li>
<li> Item Two </li> <li> Item Two </li>
</ol> </ul>
● Line breaks
<br>
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Attributes
• Attributes provide additional information about an
element
Images
• Images (inline)
<img src = "myPicture.jpg" alt = "Image of Colleen">
• Images rarely work the first time
Images
<img src="logo.jpg" Image filename
More Attributes
• As you learn the tags, you learn their specific attributes.
Some apply to any tag
• class – applies special properties to groups of elements
• id – specifies a unique id to one element on the page
• style – specifies a certain visual style (avoid this one!!!)
• accesskey – a shortcut key to activate an element
• tabindex – the order elements will come into focus
using the tab key.
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Special Entities
• Tags always start with a bracket (<)
• What if you want the browser to display a bracket,
not start a tag?
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Special Entities
If you want…. Then use…
< <
> >
© ©
blank space
¢ ¢
& &
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
Review
• How do you know the difference between a tag and
an attribute?
• What symbol ends a self-closing tag?
HTML5 Tags and Syntax INTRODUCTION
TO HTML5
How to Design
• The most important step in web design is the design.
How to Design
<header>
<section> <aside>
<article>
<footer>
Semantic Tags INTRODUCTION
TO HTML5
<header>
• A group of introductory or navigational aids: title,
navigation links, etc.
<header>
<h1>This is the Title</h1>
<h2>The author is Colleen</h2>
</header>
<nav>
• A section of the page that links to other pages or to parts
within the page.
<nav>
<ul>
<li><a href="#overview">Overview</a></li>
<li><a href="#history">History</a></li>
<li><a href="#development">Development</a></li>
</ul>
</nav>
• Often found in the <header> tag
Semantic Tags INTRODUCTION
TO HTML5
<footer>
• A section that contains info such as copyright data,
related documents, and links to social media
<footer>
© 2015 by Colleen van Lent<br>
<a href= "http://www.intro-webdesign.com/HTML5">Introduction to
HTML5 </a>
</footer>
<figure>
• More semantics than <img>. Can include:
• caption
• multiple multimedia resources
<figure>
<img src="sunset.gif" alt="Ashtabula sunset">
<figcaption>
A sunset over Lake Erie. Taken in Ashtabula Ohio.
</figcaption>
</figure>
Semantic Tags INTRODUCTION
TO HTML5
Review
• The age of <div> is ending
Template Page
Create something in Visual Studio Code!!
Template Page in VS Code INTRODUCTION
TO HTML5
Minimum requirements
• Create a page called index.html
• Meta-Data
• Displayable content
Template Page in VS Code INTRODUCTION
TO HTML5
Template Page
Minimum requirements
• Create a page called index.html
• Meta-Data
• Displayable content
Template Page in Replit INTRODUCTION
TO HTML5
Images
Image Sizes
• When you link to an image the browser displays the
image as big (or small) as the file.
Using an Editor
• Editors can be used to permanently change the size
of the image
• Only works on local files
• Built-in software for this includes Preview (Mac) and
Paint (Windows)
Images INTRODUCTION
TO HTML5
Using Attributes
● Always strive to keep style out of your HTML files
but…
● Some style may improve accessibility
● <img> tag includes width and height attributes
Images INTRODUCTION
TO HTML5
Using Percentages
<figure>
<img src="imgs/Ashtabula.jpg"
width="50%" alt="My house">
<figcaption>Relative image size</figcaption>
</figure>
Images INTRODUCTION
TO HTML5
Favicons
● You can put image/logo/icon next to the title of your
page (in the tab)
Review
● Misuse of file extensions, filename, and file paths are
often a problem
● For now, style the height/width in the html code.
Images INTRODUCTION
TO HTML5
Accessible Images
Tips
● Utilize guidelines: alt Decision Tree | Web
Accessibility Initiative (WAI) | W3C
● Add aria-labels when you can’t add alt text
● Avoid excessive emojis
● Diversify your images
Accessible Images INTRODUCTION
TO HTML5
Hyperlinks
Links
• Links are what make the Web a web.
• The interlinked nature of the web leads to the
“knowledge” that search engines appear to have.
Hyperlinks INTRODUCTION
TO HTML5
Anchor links
• The <a> tag stands for anchor link
• Needs a hyper-reference AND content
• href: reference to location of new content
• content: the “clickable” part (text or image)
Types of links
• Absolute
• Relative
• Internal
• Graphical
Hyperlinks INTRODUCTION
TO HTML5
Absolute reference
Relative References
<a href = "page2.html">Second Page</a>
Link to a local file in the same folder
Absolute vs Relative
• When would you use absolute links?
• Are there any benefits to using local links?
• Your links should NEVER have folders that are
specific to your computer
C:\page2.html
Hyperlinks INTRODUCTION
TO HTML5
Usability Issues
• Make sure the clickable component has an
informative name
• Information in the images should be available to
those who can’t see the image
Hyperlinks INTRODUCTION
TO HTML5
Targets
• Anchors can take a target attribute
• _self - default action
• _blank – open in new tab or window
• _top and _parent
Hyperlinks INTRODUCTION
TO HTML5
Review
• A page without links is rare
• Links can be absolute, relative and internal
• Use caution when using images in links
Hyperlinks INTRODUCTION
TO HTML5
Useful Tags
Block Tags
• Containers
• <article>, <aside>, <section>, <main>, …
• <hr>
• <address>
• <blockquote> - has cite attribute
• <details> with <summary>
Useful Tags INTRODUCTION
TO HTML5
Inline tags
• <span> was the original inline tag for plain text
• <cite>
• <abbr
• <time>
• <code>
• <sub> and <sup>
Useful Tags INTRODUCTION
TO HTML5
Review
• Use the most specific tag possible
• Sometimes tags “don’t work”
• Run your code through a validator, you may
have a syntax error
• Run your code in multiple browsers (good idea
even if your code looks good)
Useful Tags INTRODUCTION
TO HTML5