HTML
HTML
0731213
LECTURE 1
WHAT IS HTML?
WHAT IS HTML?
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
EXAMPLE EXPLAINED
• The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML
documents and display them.
• The browser does not display the HTML tags, but uses them to determine how to
display the document:
HTML PAGE STRUCTURE
Follow the four steps below to create your first web page with Notepad/Notepad++ or
TextEdit.
• Step 1: Open Notepad/Notepad++ or TextEdit
• Step 2: Write Some HTML into Notepad/Notepad++ or TextEdit
STEPS TO CREATE A WEB PAGE
Follow the four steps below to create your first web page with Notepad/Notepad++ or
TextEdit.
• Step 3: Save the HTML Page
STEPS TO CREATE A WEB PAGE
Follow the four steps below to create your first web page with Notepad or TextEdit.
• Step 4: View the HTML Page in Your Browser
LECTURE 2
HTML TAGS (1)
HTML DOCUMENTS
• All HTML documents must start with a document type declaration: <!DOCTYPE
html>.
• The HTML document itself begins with <html> and ends with </html>.
• The visible part of the HTML document is between <body> and </body>.
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML BASIC TAGS
HTML Headings
• HTML headings are defined with the <h1> to <h6> tags.
• <h1> defines the most important heading. <h6> defines the least important heading.
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
HTML BASIC TAGS
HTML Paragraphs
• HTML paragraphs are defined with the <p> tag.
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML BASIC TAGS
HTML Images
• HTML images are defined with the <img> tag.
• The source file (src), alternative text (alt), width, and height are provided as attributes.
• The alt attribute specifies an alternative text to be used, when an image cannot be displayed.
<img src="image.jpg" alt="This is an image" width="104" height="142">
<img src="images/image.jpg" alt="This is an image" width="104" height="142">
HTML BASIC TAGS
HTML button
• HTML button defines a clickable button.
<button type="button">Click Me!</button>
• Inside a <button> element you can put content, like text or images. This is the
difference between this element and buttons created with the <input> element.
• Tip: Always specify the type attribute for a <button> element. Different browsers use
different default types for the <button> element.
HTML BASIC TAGS
HTML div
• HTML div defines a division or a section in an HTML document.
• The <div> tag is used to group block-elements to format them with CSS.
<div id="myId">
<h3>This is a heading</h3>
<p>This is a paragraph.</p>
</div>
Tip: The <div> element is very often used together with CSS, to layout a web page.
Note: By default, browsers always place a line break before and after the <div>
element. However, this can be changed with CSS.
HTML BASIC TAGS
HTML span
• HTML span is used to group inline-elements in a document.
• The <span> tag provides no visual change by itself.
• The <span> tag provides a way to add a hook to a part of a text or a part of a
document.
<p>My mother has <span style="color:blue">blue</span> eyes.</p>
Tip: When a text is hooked in a <span> element, you can style it with CSS, or
manipulate it with JavaScript.
LECTURE 3
HTML TAGS (2)
NESTED HTML ELEMENTS
• You can add comments to your HTML source by using the following syntax
<!-- Write your comments here -->
• Notice that 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
source code.
<!-- This is a comment -->
<p>This is a paragraph.</p>
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
THE <FORM> ELEMENT
• The HTML <form> element defines a form that is used to collect user input
• An HTML form contains form elements.
• Form elements are different types of input elements, like text fields, checkboxes,
radio buttons, submit buttons, and more.
<form>
.
form elements
.
</form>
THE <INPUT> ELEMENT
Type Description
>"input type="text< Defines a one-line text input field
>"input type="radio< Defines a radio button (for selecting one of many choices)
>"input type="submit< Defines a submit button (for submitting the form)
TEXT INPUT
<form>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
</form>
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters.
PASSWORD INPUT
<form>
User name:<br>
<input type="text" name="username"><br>
User password:<br>
<input type="password" name="psw">
</form>
RADIO BUTTON INPUT
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters.
CHECKBOX INPUT
<form>
<input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle2" value="Car"> I have a car
</form>
THE VALUE ATTRIBUTE
The value attribute specifies the initial value for an input field
<form action="">
First name:<br>
<input type="text" name="firstname" value="John">
</form>
THE SUBMIT BUTTON
<input type="submit"> defines a button for submitting the form data to a form-
handler.
• The form-handler is typically a server page with a script for processing input data.
• The form-handler is specified in the form's action attribute
<form action="action_page.php">
First name:<br><input type="text" name="firstname" value="Mickey"><br>
Last name:<br><input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
THE <SELECT> ELEMENT
• The action attribute defines the action to be performed when the form is submitted.
• Normally, the form data is sent to a web page on the server when the user clicks on
the submit button.
• In the example above, the form data is sent to a page on the server called
"action_page.php". This page contains a server-side script that handles the form data
• If the action attribute is omitted, the action is set to the current page.
<form action="action_page.php">
THE METHOD ATTRIBUTE
The method attribute specifies the HTTP method (GET or POST) to be used when
submitting the form data
<form action="action_page.php" method="get">
<form action="action_page.php" method="post">
GET VS. POST