HTML5. Web Design Made Easy HTML THE BASICS. HTML Tags. HTML Structure. HTML Formatting. HTML Layouts

Similar documents
HTML Hyperlinks (Links)

CSS CSS how to display to solve a problem External Style Sheets CSS files CSS Syntax

HTML Images - The <img> Tag and the Src Attribute

Web Design 101. What is HTML? HTML Tags. Web Browsers. <!DOCTYPE html> <html> <body> <h1>my First Heading</h1> <p>my first paragraph.

INTRODUCTION TO WEB USING HTML What is HTML?

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

Programmazione Web a.a. 2017/2018 HTML5

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM Advanced Internet Technology Lab.

HTML, beyond the basics

Web Designing HTML5 NOTES

Unit 5 Web Publishing Systems Page 1 of 13 Part 4 HTML Part 4

With HTML you can create your own Web site. This tutorial teaches you everything about HTML.

Fall Semester 2016 (2016-1)

HTML. Hypertext Markup Language. Code used to create web pages

Html basics Course Outline

Web Publishing with HTML

Introduction to HTML

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

introduction to XHTML

CSC 121 Computers and Scientific Thinking

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

A HTML document has two sections 1) HEAD section and 2) BODY section A HTML file is saved with.html or.htm extension

Markup Language SGML: Standard Generalized Markup Language. HyperText Markup Language (HTML) extensible Markup Language (XML) TeX LaTeX

Web Publishing Basics I

It is possible to create webpages without knowing anything about the HTML source behind the page.

INTRODUCTION TO HTML5! HTML5 Page Structure!

Hyper Text Markup Language HTML: A Tutorial

A Balanced Introduction to Computer Science, 3/E

As we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

11. HTML5 and Future Web Application

Part 1: HTML Language HyperText Make-up Language

Web Development & Design Foundations with XHTML. Chapter 2 Key Concepts

c122jan2714.notebook January 27, 2014

What is a web site? Web editors Introduction to HTML (Hyper Text Markup Language)

Announcements. Paper due this Wednesday

How the Internet Works

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Basics of Web Design, 3 rd Edition Instructor Materials Chapter 2 Test Bank

Chapter 1 Self Test. LATIHAN BAB 1. tjetjeprb{at}gmail{dot}com. webdesign/favorites.html :// / / / that houses that information. structure?

Lesson 1 HTML Basics. The Creative Computer Lab. creativecomputerlab.com

By Ryan Stevenson. Guidebook #2 HTML

Introduction, Notepad++, File Structure, 9 Tags, Hyperlinks 1

COMSC-030 Web Site Development- Part 1. Part-Time Instructor: Joenil Mistal

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

HTML Text Formatting. HTML Session 2 2

HTML (Hypertext Mark-up language) Basic Coding

Introduction to Web Technologies

HTML TAG SUMMARY HTML REFERENCE 18 TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES MOST TAGS

CMPT 165 Unit 2 Markup Part 2

Table of Contents. MySource Matrix Content Types Manual

Chapter 2:- Introduction to XHTML. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Introduction to using HTML to design webpages

What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

Creating and Building Websites

Skill Area 323: Design and Develop Website. Multimedia and Web Design (MWD)

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

7300 Warden Avenue, Suite 503 Markham, Ontario Canada L3R 9Z6. Phone: Toll Free: Fax:

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

HTMLnotesS15.notebook. January 25, 2015

Web Technologies - by G. Sreenivasulu Handout - 1 UNIT - I

1. The basic building block of an HTML document is called a(n) a. tag. b. element. c. attribute. d. container. Answer: b Page 5

Page Layout Using Tables

Web Page Creation Part I. CS27101 Introduction to Web Interface Design Prof. Angela Guercio

HTML, CSS, JavaScript

HTML and CSS: An Introduction

What is XHTML? XHTML is the language used to create and organize a web page:

Lab 4 CSS CISC1600, Spring 2012

Text and Layout. Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 11. This presentation 2004, MacAvon Media Productions

Creating Web Pages Using HTML

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

CS134 Web Site Design & Development. Quiz1

Learning Objectives. Review html Learn to write a basic webpage in html Understand what the basic building blocks of html are

Web Design and Development ACS Chapter 3. Document Setup

1 Creating a simple HTML page

Web Programming Week 2 Semester Byron Fisher 2018

Objective % Select and utilize tools to design and develop websites.

LING 408/508: Computational Techniques for Linguists. Lecture 14

Introduction to Computer Science (I1100) Internet. Chapter 7

DREAMWEAVER QUICK START TABLE OF CONTENT

I-5 Internet Applications

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

Unit 2 - HTML Formatting

Web Development & Design Foundations with HTML5 & CSS3 Instructor Materials Chapter 2 Test Bank

HTML+ CSS PRINCIPLES. Getting started with web design the right way

This document provides a concise, introductory lesson in HTML formatting.

Attributes & Images 1 Create a new webpage

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

Beginning Web Site Design

Creating A Web Page. Computer Concepts I and II. Sue Norris

Table Basics. The structure of an table

CSS how to display to solve a problem External Style Sheets CSS files

Desire2Learn: HTML Basics

HTML BEGINNING TAGS. HTML Structure <html> <head> <title> </title> </head> <body> Web page content </body> </html>

Web Engineering (Lecture 01)

HTML and CSS COURSE SYLLABUS

Dreamweaver Basics. Planning your website Organize site structure Plan site design & navigation Gather your assets

HTML & CSS. Lesson 1: HTML Basics Lesson 2: Adding Tables Lesson 3: Intro to CSS Lesson 4: CSS in more detail Lesson 5: Review

Transcription:

HTML5 Web Design Made Easy HTML THE BASICS HTML Tags HTML Structure HTML Formatting HTML Layouts

HTML INTRODUCTION THE BASICS 1 HTML Tags 2 HTML Page Structure 2 HTML Versions 3 EXERCISE 4 The <!DOCTYPE> Declaration 6 HTML Paragraphs 6 EXERCISE 6 HTML Headings 7 HTML Lines 9 HTML Tip - How to View HTML Source 9 HTML Tag Reference 9 HTML Output - Useful Tips 10 EXERCISE 10 HTML Line Breaks 10 EXERCISE 11 HTML TEXT FORMATTING 12 HTML Formatting Tags 12 EXERCISE 13 HTML Comment Tags 14 Software Program Tags 14 HTML Hyperlinks (Links) 15 EXERCISE 16 HTML Head Elements 17 EXERCISE 19 HTML Styles - CSS 20 Inline Styles 20

EXERCISE 22 Internal Style Sheet 23 EXERCISE 23 External Style Sheet 25 HTML IMAGES 26 The <img> Tag and the Src Attribute 26 HTML Images - The Alt Attribute 27 Set Height and Width of an Image 27 EXERCISE 28 Basic Notes - Useful Tips 28 HTML TABLES 29 EXERCISE 30 Add Cell Spacing to a Table 31 HTML LISTS 33 EXERCISE 34 HTML LAYOUTS 35 Website Layouts Using <div> Elements 35 EXERCISE 37 HTML Layout - Useful Tips 37

HTML Introduction The Basics You can build web pages using HTML, which stands for HyperText Markup Language. HTML5 is the latest version of the language. HTML documents are made up of text content and special codes known as tags that tell web browsers how to display that content. HTML documents are identified by their.html or.htm file extensions. You can edit the code in an HTML document by opening the document in a simple text editor or a web design tool such as Adobe Dreamweaver. For the most part HTML is platform independent, which means you can view HTML-based web pages on any computer operating system. HTML also works independently on all modern web browsers including Internet Explorer, Safari, Firefox and Google Chrome. A web browser is software that can receive HTML documents from the web, parse the HTML instructions, and display the resulting web pages. In addition to retrieving the HTML, the browser takes care of downloading all the associated images and other information needed for the page to appear and function properly. 1 P age

HTML Tags HTML is written in the form of HTML elements consisting of tags enclosed in angle brackets (like <html>). HTML elements form the building blocks of all websites. HTML allows images and objects to be embedded and can be used to create interactive forms. It provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links, quotes and other items. It can embed scripts written in languages such as JavaScript which affect the behavior of HTML web pages. HTML markup tags are usually called HTML tags. HTML tags are keywords (tag names) surrounded by angle brackets like <html> HTML tags normally come in pairs like <p> and </p> The first tag in a pair is the start tag, the second tag is the end tag The end tag is written like the start tag, with a slash before the tag name Start and end tags are also called opening tags and closing tags <tagname>content</tagname> HTML Page Structure Below is a visualization of an HTML page structure: 2 P age

HTML Versions Since the early days of the web, there have been many versions of HTML: Version Year HTML 1991 HTML+ 1993 HTML 2.0 1995 HTML 3.2 1997 HTML 4.01 1999 XHTML 2000 HTML5 2012 HTML Example <!DOCTYPE html> <html> <body> <h1>my First Heading</h1> <p>my first paragraph.</p> </body> </html> Example Explained The DOCTYPE declaration defines the document type The text between <html> and </html> describes the web page The text between <body> and </body> is the visible page content The text between <h1> and </h1> is displayed as a heading The text between <p> and </p> is displayed as a paragraph The <!DOCTYPE html> declaration is the doctype for HTML5. 3 P age

EXERCISE Step 1: Open Notepad To open Notepad in Windows 7 or earlier: Click Start (bottom left on your screen). Click All Programs. Click Accessories. Click Notepad. To open Notepad in Windows 8 or later: Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad. Step 2: Write Some HTML Copy the following HTML into Notepad. <!DOCTYPE html> <html> <body> <h1>my First Heading</h1> <p>my first paragraph.</p> </body> </html> 4 P age

Step 3: Save the HTML Page Save the file on your computer. Select File -> Save as in the Notepad menu. Name the file index.html and save it to the Class Files folder When saving an HTML file, use either the.htm or the.html file extension. There is no difference, it is entirely up to you. Step 4: View HTML Page in Your Browser Double-click your saved HTML file, and the result will look much like this: 5 P age

The <!DOCTYPE> Declaration The <!DOCTYPE> declaration helps the browser to display a web page correctly. There are many different documents on the web, and a browser can only display an HTML page 100% correctly if it knows the HTML version and type used. Common Declarations HTML5 <!DOCTYPE html> HTML 4.01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> XHTML 1.0 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> HTML Paragraphs HTML paragraphs are defined with the <p> tag. Example <p>this is a paragraph.</p> <p>this is another paragraph.</p> EXERCISE Step 1: Open index.html Open index.html in Notepad 6 P age

Step 2: Add to existing HTML Add <p>this is another paragraph.</p> below the first <p> tag in the document. Step 3: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 4: View HTML Page in Your Browser Double-click your saved HTML file. HTML Headings Headings are defined with the <h1> to <h6> tags. <h1> defines the most important heading. <h6> defines the least important heading. Example <h1>this is a heading</h1> <h2>this is a heading</h2> <h3>this is a heading</h3> Note: Browsers automatically add some empty space (a margin) before and after each heading. Use HTML headings for headings only. Don't use headings to make text BIG or bold. Search engines use your headings to index the structure and content of your web pages. Since users may skim your pages by its headings, it is important to use headings to show the document structure. H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on. 7 P age

Don't Forget the End Tag Some HTML elements might display correctly even if you forget the end tag: <p>this is a paragraph <p>this is a paragraph The example above works in most browsers, because the closing tag is considered optional. Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag. Empty HTML Elements HTML elements with no content are called empty elements. <br> is an empty element without a closing tag (the <br> tag defines a line break). Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the proper way of closing empty elements in XHTML (and XML). HTML Tip: Use Lowercase Tags HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags. Use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML. 8 P age

HTML Lines The <hr> tag creates a horizontal line in an HTML page. The hr element can be used to separate content: Example <p>this is a paragraph.</p> <hr /> <p>this is a paragraph.</p> <hr /> <p>this is a paragraph.</p> HTML Tip - How to View HTML Source Have you ever seen a Web page and wondered "Hey! How did they do that?" To find out, right-click in the page and select "View Source" (IE) or "View Page Source" (Firefox), or similar for other browsers. This will open a window containing the HTML code of the page. HTML Tag Reference You will learn more about HTML tags and attributes later in this tutorial. Tag Description <html> Defines an HTML document <body> Defines the document's body <h1> to <h6> Defines HTML headings <hr> Defines a horizontal line <p> Defines a paragraph 9 P age

HTML Output - Useful Tips You cannot be sure how HTML will be displayed. Large or small screens, and resized windows will create different results. With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code. The browser will remove extra spaces and extra lines when the page is displayed. Any number of lines count as one line, and any number of spaces count as one space. EXERCISE Step 1: Open spaces.html in Notepad (spaces.html is located in the Class Files folder) Leave the spaces.html file open in Notepad. Step 2: Open spaces.html in a browser (The example demonstrates some HTML formatting problems) View the results and notice how spaces are virtually ignored by HTML. HTML Line Breaks Use the <br> tag if you want a line break (a new line) without starting a new paragraph: Example <p> My Bonnie lies over the ocean. <br /> My Bonnie lies over the sea. <br /> My Bonnie lies over the ocean. <br /> Oh, bring back my Bonnie to me. </p> 10 P age

EXERCISE Step 1: Add to spaces.html in Notepad Add line breaks to the file (see the previous example). Step 2: Add a Horizontal Line Add an <hr> tag below the paragraph as in the example below: Oh, bring back my Bonnie to me. </p> <hr /> Step 3: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 4: Open spaces.html in a browser View the results. 11 P age

HTML Text Formatting HTML Formatting Tags HTML uses tags like <b> and <i> for formatting output, like bold or italic text. These HTML tags are called formatting tags (look at the bottom of this page for a complete reference). Often <strong> renders as <b>, and <em> renders as <i>. However, there is a difference in the meaning of these tags: <b> or <i> defines bold or italic text only. <strong> or <em> means that you want the text to be rendered in a way that the user understands as "important". Today, all major browsers render strong as bold and em as italics. However, if a browser one day wants to make a text highlighted with the strong feature, it might be cursive for example and not bold! This text is bold This text is strong This text is italic This text is emphasized This is computer output Note: text_formatting.html displays the above example 12 P age

EXERCISE Step 1: Open text_formatting.html in a browser View the results in a browser Step 2: Open text_formatting.html Open text_formatting.html in Notepad Step 3: Add to the Page Add the following after the final paragraph in the document: <p>this is<sub> subscript</sub> and <sup>superscript</sup></p> Step 4: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 5: Refresh the page in a browser Refresh the page in the browser and view the results. 13 P age

HTML Comment Tags Comment tags <!-- and --> are used to insert comments in HTML. You can add comments to your HTML source by using the following syntax: <!-- Write your comments here --> Note: There is an exclamation point (!) in the opening tag, but not in the closing tag. Comments are not displayed by the browser, but they can help document your HTML. With comments you can place notifications and reminders in your HTML: Example <!-- This is a comment --> <p>this is a paragraph.</p> <!-- Remember to add more information here --> Comments are also great for debugging HTML, because you can comment out HTML lines of code, one at a time, to search for errors: Example <!-- Do not display this at the moment <p>this is a paragraph.</p> --> Software Program Tags HTML comments tags can also be generated by various HTML software programs. For example <!--webbot bot--> tags wrapped inside HTML comments by FrontPage and Expression Web. As a rule, let these tags stay, to help support the software that created them. 14 P age

HTML Hyperlinks (Links) The HTML <a> tag defines a hyperlink. A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document. When you move the cursor over a link in a Web page, the arrow will turn into a little hand. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. HTML Link Syntax The HTML code for a link is simple. It looks like this: <a href="url">link text</a> The href attribute specifies the destination of a link. Example <a href="http://www.manchestercc.edu/">visit MCC</a> which will display like this: Visit MCC Clicking on this hyperlink will send the user to MCC's homepage. Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element. HTML Links - The target Attribute The target attribute specifies where to open the linked document. The example below will open the linked document in a new browser window or a new tab: Example <a href="http://www.manchestercc.edu/" target="_blank">visit MCC</a> There are other target attributes, however in general you either use target= _blank or no target at all. 15 P age

Basic Notes - Useful Tips Note: Always add a trailing slash to subfolder references. If you link like this: href="http://www.manchestercc.edu/admissions", you will generate two requests to the server, the server will first add a slash to the address, and then create a new request like this: href="http://www.manchestercc.edu/admissions/". EXERCISE Step 1: Open links.html in a browser View the results in a browser and test the links Step 2: Open links.html for editing Open links.html in Notepad Step 3: Add a target to one of the links Change the link to MCC by adding a target attribute: <a href="http://www.manchestercc.edu/" target="_blank">visit MCC</a> Step 4: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 5: View the page in a browser Open links.html in a browser and view the results. 16 P age

HTML Head Elements The HTML <head> Element The <head> element is a container for all the head elements. Elements inside <head> can include scripts, instruct the browser where to find style sheets, provide meta information, and more. The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>. The HTML <title> Element The <title> tag defines the title of the document. The <title> element is required in all HTML/XHTML documents. The <title> element: defines a title in the browser toolbar provides a title for the page when it is added to favorites displays a title for the page in search-engine results A simplified HTML document: <!DOCTYPE html> <html> <head> <title>title of the document</title> </head> <body> The content of the document... </body> </html> The HTML <link> Element The <link> tag defines the relationship between a document and an external resource. 17 P age

The <link> tag is most used to link to style sheets: <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> The HTML <meta> Element Metadata is data (information) about data. The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable. Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata. The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services. <meta> tags always go inside the <head> element. <meta> Tags - Examples of Use Define keywords for search engines: <meta name="keywords" content= "Technology,Communication,Visual Arts"> Define a description of your web page: <meta name="description" content= "Community Learning"> Define the author of a page: <meta name="author" content="mcc Staff"> Refresh document every 30 seconds: <meta http-equiv="refresh" content="30"> Other Head elements will be covered later in this tutorial. 18 P age

EXERCISE Step 1: Open index.html Open index.html in Notepad Step 2: Add to existing HTML Add the <head> tag and the <title> element to the web page: <!DOCTYPE html> <html> <head> <title>title of the document</title> </head> Step 3: Add <meta> tags Add <meta> tags for keywords, description and author to the web page: <!DOCTYPE html> <html> <head> <title>title of the document</title> <meta name="keywords" content= "Technology,Communication,Visual Arts"> <meta name="description" content= "Community Learning"> <meta name="author" content="mcc Staff"> </head> Step 3: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 4: View HTML Page in Your Browser Double-click your saved HTML file. 19 P age

HTML Styles - CSS CSS (Cascading Style Sheets) is used to style HTML elements. CSS was introduced together with HTML 4, to provide a better way to style HTML elements. CSS can be added to HTML in the following ways: Inline - using the style attribute in HTML elements Internal - using the <style> element in the <head> section External - using an external CSS file The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files. However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples. It also makes it easier for you to edit the code and try it yourself. Inline Styles An inline style can be used if a unique style is to be applied to one single occurrence of an element. To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph: <p style="color:blue;margin-left:20px;">this is a paragraph.</p> 20 P age

HTML Style Example - Font, Color and Size The font-family, color, and font-size properties defines the font, color, and size of the text in an element: Example <!DOCTYPE html> <html> <body> <h1 style="font-family:arial;">a heading</h1> <p style="font-family:arial;color:red;font-size:20px;">a paragraph.</p> </body> </html> HTML Style Example - Text Alignment The text-align property specifies the horizontal alignment of text in an element: Example <!DOCTYPE html> <html> <body> <p style="text-align:center;">this is a center-aligned paragraph.</p> </body> </html> 21 P age

EXERCISE Step 1: Open styles_inline.html Open styles_inline.html in Notepad (leave styles_inline open in Notepad) Step 2: View styles_inline.html Open styles_inline.html in a browser Step 3: Add text alignment to the existing HTML Add the text-align property to a new paragraph: <p style="text-align:center;">this is a center-aligned paragraph.</p> Step 4: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 5: View HTML Page in Your Browser Double-click your saved HTML file. 22 P age

Internal Style Sheet An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section of an HTML page, by using the <style> tag, like this: <head> <style> body {background-color:lightgrey;} p {color:blue;} </style> </head> EXERCISE Step 1: Open styles_internal.html Open styles_internal.html in Notepad Step 2: Add text color to the internal style Add the color property inside the <style> tag for paragraphs on the page: <style> body {background-color:lightgrey;} h1 {color:red;} h2 {color:green;} p {color:blue;} </style> Step 3: Add a paragraph Add a paragraph to the body of the page: <p>all text in paragraphs will be blue.</p> 23 P age

Step 4: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. Step 5: View HTML Page in Your Browser Double-click your saved HTML file. 24 P age

External Style Sheet An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the <head> section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> 25 P age

HTML Images Example Norwegian Mountain Trip The <img> Tag and the Src Attribute In HTML, images are defined with the <img> tag. The <img> tag is empty, which means that it contains attributes only, and has no closing tag. To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display. Syntax for defining an image: <img src="url" alt="some_text"> The URL points to the location where the image is stored. An image named "pulpit.jpg", located in the "images" directory in the Class Files folder has the URL: images/pulpit.jpg 26 P age

The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph. HTML Images - The Alt Attribute The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The value of the alt attribute is an author-defined text: <img src="smiley.gif" alt="smiley face"> The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader). Set Height and Width of an Image The height and width attributes are used to specify the height and width of an image. The attribute values are specified in pixels by default: <img src="smiley.gif" alt="smiley face" width="42" height="42"> Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load). 27 P age

EXERCISE Step 1: Open images.html Open images.html in Notepad Step 2: Change image attributes Try changing the following attributes: (preview the changes in a browser after each change) Remove the images/ folder from the source attribute (return the images/folder back to the path of the image after previewing) Change the value of the border attribute from 0 to 5 Change the width and height attributes: from width="304" height="228" to width="608" height="456" Basic Notes - Useful Tips Note: If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is: Use images carefully. Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image. 28 P age

HTML Tables HTML Table Example: Tables are defined with the <table> tag. A table is divided into rows with the <tr> tag. (tr stands for table row) A row is divided into data cells with the <td> tag. (td stands for table data) A row can also be divided into headings with the <th> tag. (th stands for table heading) (By default, all major browsers display table headings as bold and centered) The <td> elements are the data containers in the table. The <td> elements can contain all sorts of HTML elements like text, images, lists, other tables, etc. The width of a table can be defined using CSS. Example <table style="width:50%"> <tr> </tr> <tr> <th>firstname</th> <th>lastname</th> <th>points</th> 29 P age

<td>jill</td> <td>smith</td> <td>50</td> </tr> <tr> <td>eve</td> <td>jackson</td> <td>94</td> </tr> </table> To add borders with CSS, use the border property Example <style> table,th,td { border:1px solid black; } </style> Remember you are defining borders for both the table and the table cells. EXERCISE Step 1: Open table_example.html Open table_example.html in Notepad Step 2: View table_example.html Open table_example.html in a browser 30 P age

Step 3: Add Cell Padding Cell padding specifies the space between the cell content and its borders. Add cell padding to the table by adding the following code in the <style> tag: th,td { padding:15px; } Step 4: Save the HTML Page Save the file on your computer. Select File -> Save in the Notepad menu. (leave the page open in Notepad) Step 5: View HTML Page in Your Browser Double-click your saved HTML file. Add Cell Spacing to a Table Cell spacing specifies the space between the cells. To set the cell spacing for the table, use the CSS border-spacing property: Example Table { border-spacing:5px; } 31 P age

32 P age

HTML Lists The most common HTML lists are ordered and unordered lists: HTML Lists An ordered list: 1. The first list item 2. The second list item 3. The third list item An unordered list: List item List item List item HTML Unordered Lists An unordered list starts with the <ul> tag. Each list item starts with the <li> tag. The list items are marked with bullets (typically small black circles). <ul> <li>coffee</li> <li>milk</li> </ul> How the HTML code above looks in a browser: Coffee Milk HTML Ordered Lists An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. The list items are marked with numbers. <ol> <li>coffee</li> <li>milk</li> </ol> How the HTML code above looks in a browser: 33 P age

1. Coffee 2. Milk HTML Description Lists A description list is a list of terms/names, with a description of each term/name. The <dl> tag defines a description list. The <dl> tag is used in conjunction with <dt> (defines terms/names) and <dd> (describes each term/name): <dl> <dt>coffee</dt> <dd>- black hot drink</dd> <dt>milk</dt> <dd>- white cold drink</dd> </dl> How the HTML code above looks in a browser: Coffee Milk - black hot drink - white cold drink EXERCISE Step 1: Open lists.html Open lists.html in Notepad Step 2: View lists.html Open lists.html in a browser 34 P age

HTML Layouts Web page layout is very important to make your website look good. Design your webpage layout very carefully. Website Layouts Using <div> Elements Most websites have put their content in multiple columns (formatted like a magazine or newspaper). Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages. Even though it is possible to create nice layouts with HTML tables, tables were designed for presenting tabular data - NOT as a layout tool! The div element is a block level element used for grouping HTML elements. The following example uses five div elements to create a multiple column layout: Example <!DOCTYPE html> <html> <body> <div id="container" style="width:500px"> <div id="header" style="background-color:#ffa500;"> <h1 style="margin-bottom:0;">main Title of Web Page</h1></div> <div id="menu" style="backgroundcolor:#ffd700;height:200px;width:100px;float:left;"> <b>menu</b><br> HTML<br> CSS<br> JavaScript</div> 35 P age

<div id="content" style="backgroundcolor:#eeeeee;height:200px;width:400px;float:left;"> Content goes here</div> <div id="footer" style="background-color:#ffa500;clear:both;textalign:center;"> Copyright MyWebsite.com</div> </div> <!-- This is the div container end tag --> </body> </html> The HTML code above will produce the following result: 36 P age

EXERCISE Step 1: Open layout.html Open layout.html in Notepad (Leave layout.html open in Notepad) Step 2: View layout.html Open layout.html in a browser Step 3: Change the <div> width and alignment Edit the container div as follows: <div id="container" style="width:960px; margin:auto;"> Step 4: View Changes Save and View layout.html in a browser HTML Layout - Useful Tips Tip: The biggest advantage of using CSS is that, if you place the CSS code in an external style sheet, your site becomes MUCH EASIER to maintain. You can change the layout of all your pages by editing one file. Tip: Because advanced layouts take time to create, a quicker option is to use a template. Search Google for free website templates (these are pre-built website layouts you can use and customize). 37 P age