HTML and Css
HTML and Css
1
Table of Content
2
Chapter 1
Structure
Hypertext Markup Language (HTML) is the standard markup language for
creating web pages and web applications. With Cascading Style Sheets (CSS) .
Web browsers receive HTML documents from a web server or from local storage
and render the documents into multimedia web pages. HTML describes the structure of a
web page.
HTML can embed programs written in a scripting language such as JavaScript, which
affects the behavior and content of web pages. Inclusion of CSS defines the look and
layout of content. The World Wide Web Consortium (W3C), maintainer of both the
HTML and the CSS standards, has encouraged the use of CSS over explicit
presentational HTML since 1997.
< P >
left-angle bracket
(less-than sign)
RIGHT -angle bracket
(MORE -than sign)
3
Body, Head & Title
<!DOCTYPE html>
The doctype is not actually a tag, but a declaration, telling the browser what
kind of html you are using. The doctype above declares HTML 5.
<html></html>
<head></head>
The <head> element contains special elements that instruct the browser
where to find stylesheets, provide meta info, and more.
<title></title>
The contents of the <title> element are either shown in the
top of the browser, above where you usually type in the URL of
the page you want to visit, or on the tab for that page (if your
browser uses tabs to allow you to view multiple pages at the same time).
<body></body>
The <body> element contains the document content (what is shown inside
the browser window).
4
HOW TO START
</body>
</html>
5
Step 3: Save the HTML Page
Save the file on your computer. Select File > Save as in the Notepad menu.
Name the file "index.htm“ or "index.html“ ).
Open the saved HTML file in your favorite browser (double click on the
file, or right-click - and choose "Open with").
6
Chapter 2
Text
1. The Heading Element
HTML has six "levels" of headings:
<h1><h2><h3><h4><h5><h6>.
<h1> is used for main headings <h2> is used for subheadings
If there are further sections under the subheadings then the
<h3> element is used, and soon...
Html Results
7
1. Paragraphs
<p>
To create a paragraph, surround the words that make up the
paragraph with an opening <p> tag and closing </p> tag.
By default, a browser will show each paragraph on a new line
with some space between it and any subsequent paragraphs.
Html Result
<p>A paragraph consists of
one or more sentences that
form a self-contained unit of
discourse. The start of a
paragraph is indicated by a new
line. </p>
<p>Text is easier to understand
when it is split up into units of text.
For example, a book may have
chapters. Chapters can have
subheadings. Under each heading
there will be one or more
paragraphs. </p>
Html Result
<b>This text is Bold</b>
Html Result
<big>This text is big</big>
8
4. Emphasized text format
By enclosing words in the tags <em> and </em>
we can make characters appear Emphasized text.
Html Result
<em>This text is Emphasized</em>
Html Result
<i>This text is Italic</i>
Html Result
<small>This text is Small</small>
9
8. Strong text format
By enclosing words in the tags <strong> and </strong>
we can make characters appear strong text.
Html Result
<strong>This text is Strong</strong>
Html Result
This is<sub> Subscript</sub>
Html Result
This is <sup>Superscript</sup>
10
8. Underline text format
By enclosing words in the tags <u> and </u>
we can make characters appear underlined text.
Html Result
<u>This text is Underline</u>
11
Chapter 3
Lists
1. Unordered lists
<ul>
The unordered list is created with the <ul> element.
<li>
Each item in the list is placed between an opening <li> tag and a closing </li>
tag. (The li stands for list item.)
Html Result
<h4>Disc bullets list:</h4>
<ul type="disc">
<li>Jones</li>
<li>Smith</li>
<li>Hayes</li>
<li>Jackson</li></ul>
<h4>Circle bullets list:</h4>
<ul type="circle">
<li>Jones</li>
<li>Simth</li>
<li>Hayes</li>
<li>Jackson</li>
</ul>
<h4>Square bullets list:</h4>
<ul type="square">
<li>Jones</li>
<li>Smith</li>
<li>Hayes</li>
12
<li>Jackson</li>
</ul>
2. Ordered List
<ol>
Contains the ordered list type attribute determines numbering scheme of list
default is numerals.
<li>
Each item in the list is placed between an opening <li> tag and a closing </li>
tag. (The li stands for list item.)
Html Result
<h4>Numbered list:</h4>
<ol>
<li>Jones</li>
<li>Smith</li>
<li>Hayes</li>
<li>Jackson</li></ol>
<h4>Letters list:</h4>
<ol type="A">
<li>Jones</li>
<li>Smith</li>
<li>Hayes</li>
<li>Jackson</li>
</ol>
<h4>Roman numbers list:</h4>
<ol type="I">
<li>Jones</li>
<li>Smith</li>
<li>Hayes</li>
13
<li>Jackson</li></ol>
3. Definition lists
⚫ Uses:
⚫ Display a list of terms and descriptions
⚫ Display a list of FAQ and answers
⚫ The Description List element
⚫ <dl>
The definition list is created with he <dl> element and usually consists
of a series of terms and their definitions. Inside the <dl> element you
will usually see pairs of <dt> and <dd> elements.
⚫ <dt>
This is used to contain the term being defined (the definition term).
⚫ <dd>
This is used to contain the definition. Sometimes you might see a list
where there are two terms used for the same definition or two different
definitions for the same term.
Html Result
<dl>
<dt>IP</dt>
<dd>Internet Protocol</dd>
<dt>TCP</dt>
<dd>Transmission
Control Protocol</dd>
</dl>
14
Chapter 4
Links
Links are created using the <a> element. Users can click on anything
between the opening <a> tag and the closing </a> tag. You specify which
page you want to link to using the href attribute.
<a href="http://www.Horseedmedia.net">Horseed</a>
The text between the opening <a> tag and closing </a> tag
is known as link text. Where possible, your link text should
explain where visitors will be taken if they click on it (rather
than just saying "click here"). Below you can see the link to
Horseed that was created on the previous lesson.
15
• More on links
Absolute link
– Link to other websites
<a href="http://yahoo.com">Yahoo</a>
Relative link
– Link to pages on your own site
– Relative to the current page
<a href="index.html">Home</a>
Value Description
If you want a link to open in a new window, you can use the target attribute
on the opening <a> tag. The value of this attribute should be _blank.
Html Result
16
Email Links
mailto:
To create a link that starts up the user's email program and
addresses an email to a specified email address, you use the <a>
element. However, this time the value of the href attribute starts
with mailto: and is followed by the email address you want the
email to be sent to.
Html Result
<a href="mailto:[email protected]">
Linking to Fragment Identifiers
17
Chapter 5
Images, Audio and Videos
1. Image
• 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 on your page.
• It is empty tag.
<IMG SRC ="url">
<IMG SRC="picture.gif">
<IMG SRC="picture.gif" Height="30" width="50">
Defines an image
<img>
<Src> display an image on a page, Src stands for "source".
<Alt> Define "alternate text" for an image
<Width> Defines the width of the image
<Height>
Defines the height of the image
<Border>
Defines border
<Align>
Align an image within the text
<background>
Image use background of site.
18
Code & Result of the Image
Align an image
Html Result
<p><img src="after/wagad.jpg" align="left"
width="48" height="48"> </p>
<p><img src="after/wagad2.jpg" align="right"
width="48" height="48"></p>
Image size
Html Result
<html><body>
<p><img src="after/wagad.jpg "
align="bottom" width="20" height="20"> </p>
<p><img src =" after/wagad.jpg"
align="middle" width="40" height="40"></p>
<p><img src ="after/wagad.jpg "
align="top" width="60" height="60"></p>
<p><img src =" after/wagad.jpg "
width="80" height="80"> </p>
<p><img src =" after/wagad.jpg"
width="100" height="100"> </p></body></html>
19
Image with text
Html Result
<html>
<body>
<p>An image
<img src="after/wagad2.jpg" align="bottom"
width="48" height="48"> in the text</p>
<p>An image
<img src ="after/wagad2.jpg" align="middle"
width="48" height="48"> in the text</p>
<p>An image
<img src ="after/wagad2.jpg" align="top"
width="48" height="48"> in the text</p>
<p>Note that bottom alignment is the default alignment</p>
<p><img src ="after/wagad2.jpg" width="48" height="48">
An image before the text</p>
<p>An image after the text
<img src ="after/wagad2.jpg" width="48" height="48"> </p>
</body></html>
Background Image
Html Result
<HTML>
<body background="after/wagad2.jpg" text="white">
<br><br><br>
<h2> Background Image!</h2>
</body></HTML>
20
2. Audio
HTML5 introduced the <audio> element to include audio files in your pages.
As with HTML5 video, browsers expect different formats for the audio. The
<audio> element has a number of attributes which allow you to control audio
playback:
Src
This attribute specifies the path to the audio file.
Controls
This attribute indicates whether the player should display controls. If you do
not use this attribute, no controls will be shown by default.
Autoplay
The presence of this attribute indicates that the audio should start playing
automatically. (It is considered better practice to let visitors choose to play
audio.)
Html Result
<html>
<body>
<audio controls>
<source src="gabay.mp3" type="audio/mpeg">
</audio>
</body></html>
21
3. Videos
<video>
The <video> element has a number of attributes which allow you to control
video playback:
<source>
To specify the location of the file to be played, you can use the <source>
element inside the <video> element. (This should replace the src attribute on
the opening <video> tag.)
Src
This attribute specifies the path to the video
Poster
This attribute allows you to specify an image to show while the video is
downloading or until the user tells the video to play.
Width, height
These attributes specify the size of the player in pixels.
Controls
When used, this attribute indicates that the browser should supply its own
controls for playback.
Autoplay
When used, this attribute specifies that the file should play automatically.
22
The HTML <video> Element
To show a video in HTML, use the <video> element:
Html Result
<html>
<body>
<video width="320" height="240" controls>
<source src="cashar.mp4" type="video/mp4">
<source src="cashar.ogg" type="video/ogg">
</video>
</body>
</html>
23
Chapter 6
Table
<table>
The <table> element is used to create a table. The contents of the table are
written out row by row.
<tr>
You indicate the start of each row using the opening <tr> tag. (The tr stands
for table row.) It is followed by one or more <td> elements (one for each cell
in that row). At the end of the row you use a closing </tr> tag.
<th>
The <th> element is used just like the <td> element but its purpose is to
represent the heading for either a column or a row. (The th stands for table
heading.)
<td>
Each cell of a table is represented using a <td> element. (The td stands for
table data.) At the end of each cell you use a closing </td> tag.
t
a
b
l
e
f
o
o
t
e
r
25
<Cellspacing> amount of space between table cells.
<Cellpadding> space around the edges of each cell No of
<Colspan> column working with will span
<rowspan> No of rows working with will span
<Border> attribute takes a number
Html Result
<html>
<body>
<h3>Table without border</h3>
<table>
<tr> <td>MILK</td>
<td>TEA</td>
<td>COFFEE</td> </tr>
<tr> <td>400</td>
<td>500</td>
<td>600</td> </tr>
</table>
</body>
</html>
Horizontal Header
Html Result
<html><body>
<h4>Horizontal Header:</h4>
<table border="1">
<tr> <th>Name</th>
<th>Loan No</th>
<th>Amount</th> </tr>
<tr> <td>Jones</td>
<td>L-1</td>
<td>5000</td></tr> </table>
</body></html>
26
Vertical Header
Html Result
< html><body>
<h4>Vertical Header:</h4>
<table border="5">
<tr> <th>Name</th>
<td>Jones</td> </tr>
<tr> <th>Loan No</th>
<td>L-1</td> </tr>
<tr> <th>Amount</th>
<td>5000</td></tr> </table>
</body></html>
27
Table Code with Caption & ColSpacing
Html Result
<html>
<body>
<table border="1">
<caption>My Caption</caption>
<tr> <td>Milk</td>
<td>Tea</td></tr>
<tr> <td></td>
<td>Coffee</td> </tr></table>
</body></html>
Cellpadding,Image & Backcolor Code
Html Result
<html><body>
<h3>Without cellpadding:</h3>
<table border="2" bgcolor="green">
<tr> <td>Jones</td>
<td>Smith</td></tr>
<tr> <td>Hayes</td>
<td>Jackson</td></tr></table>
<h4>With cellpadding:</h4>
<table border="8"cellpadding="10"
background="wagad1.jpg ">
<tr> <td>Jones</td>
<td>Smith</td></tr>
<tr> <td>Hayes</td>
<td>Jackson</td></tr></table>
</body></html>
28
Chapter 7
Forms
1. <form>
Form controls live inside a <form> element. This element should always carry
the action attribute and will usually have a method and id attribute.
action
Every <form> element requires an action attribute. Its value is the URL for the
page on the server that will receive the information in the form when it
is submitted.
method
Forms can be sent using one of two methods: get or post.
2. <input>
The <input> element is used to create several different form
controls. The value of the type attribute determines what kind
of input they will be creating.
Name
When users enter information into a form, the server needs to know which form
control each piece of data was entered into. (For example, in a login form, the
server needs to know what has been entered as the username and what has been
given as the password.) Therefore, each form control requires a name attribute.
The value of this attribute identifies the form control and is
sent along with the information they enter to the server
Checked
The checked attribute can be used to indicate which value (if any) should be
selected when the page loads. The value of this attribute is checked.
.
Type="password"
When the type attribute has a value of password it creates a text box that acts
just like a single-line text input, except the characters are blocked out. They are
hidden in this way so that if someone is looking over the user's shoulder, they
cannot see sensitive data such as passwords.
29
Type="text"
When the type attribute has a value of text, it creates a single-line text input.
Type="radio"
Radio buttons allow users to pick just one of a number of options.
Type="checkbox"
Checkboxes allow users to select (and unselect) one or more options in
answer to a question.
Type="file"
This type of input creates a box that looks like a text input followed by
a browse button. When the user clicks on the browse button, a window opens
up that allows them to select a file from their computer to be uploaded to the
website.
Type="submit"
The submit button is used to send a form to the server.
Type=”Email”
When the type attribute has a value of email, it creates a single line text
input.
3. <textarea>
The <textarea> element is used to create a mutli-line text input. Unlike other
input elements this is not an empty element. It should therefore have an
opening and a closing tag. Any text that appears between the opening
<textarea> and closing </textarea> tags will appear in the text box when the
page loads.
4. <select>
A drop down list box (also known as a select box) allows users to select one
option from a drop down list. The <select> element is used to create a drop
down list box. It contains two or more <option> elements.
30
Form Structure
There are several types of form controls that you can use to collect information
from visitors to your site.
ADDING TEXT:
Password input Text area (multi-line)
Text input (single-line) For longer areas of text,
Used for a single line of text Like a single line text box
but it masks the characters such as messages and
such as email addresses and
entered. comments.
names.
Making Choices:
31
Code of the HTML Form
Html
<html><body><form>
<h1>Create a Internet Mail Account</h1>
First Name <input type="text" name="fname" size="30"><br><br>
Last Name <input type="text" name="lname" size="30"><br><br>
Email @mail.com<input type="email" name="email" size="20"><br><br>
Password <input type="password" name="password" size="20"><br><br>
<input type="radio" checked="checked" name="sex" value="male" /> Male<br><br>
<input type="radio" name="sex" value="female" /> Female
<p>Birthday <input type="text" name="birth" size="05">
<select size="1" name="select"> <option>-Select One-</option> <option>January</option>
<option>February</option> <option>March</option> </select>
<input type="text" name="year" size="10"></p> TypeYourself
<textarea rows="4" name="textarea" cols="20"></textarea>
<br><input type="submit" value="Sign Up" name="signup"> </form></body></html>
Result
32
<fieldset>
You can group related form controls together inside the <fieldset> element.
This is particularly helpful for longer forms. Most browsers will show the
fieldset with a line around the edge to show how they are related. The
appearance of these lines can be adjusted using CSS.
<legend>
The <legend> element can come directly after the opening <fieldset> tag and
contains a caption which helps identify the purpose of that group of form
controls.
Html Result
<fieldset>
<legend>Contact details</legend>
<label>Email:<br />
<input type="text" name="email" />
</label><br />
<label>Mobile:<br />
<input type="text" name="mobile" />
</label><br /> <label>Telephone:<br />
<input type="text" name="telephone" /></label>
</fieldset>
You have probably seen forms on the web that give users messages if the form
control has not been filled in correctly; this is known as form validation.
Html Result
<form action="http://www.example.com/login/"
method="post"> <label for="username">Username:</label>
<input type="text" name="username"
required="required" /></title><br />
<label for="password">Password:</label>
<input type="password" name="password"
required="required" /><input type="submit" value="Submit" /></form>
33
Chapter 8
Introduction to CSS
What Is CSS?
CSS Syntax
selector/element {property: value;}
A CSS rule has two main parts: a selector, and one or more declarations (property
and value) as shown in the following diagram.
Each declaration includes a CSS property name and a value, separated by a colon.
34
CSS Selectors
1) Type selector 2) Id selector
3) Class selector 4) Group selector
Type Selector
It is used to apply the style using tag name. The type selector selects an element by
its type, it represents the element or HTML tag to style.
Html tag
<p This is my introduction text</p>
Css
H1 {font-size: 18px;}
P {color: blue;}
Id Selector
Matches an element whose id attribute has a value that matches the one specified
after the pound or hash symbol.
Html
<p id=“intro”> This is my introduction text</p>
Css
#intro {border-bottom: 2px dashed #fff;}
Class Selector
Matches an element whose class attribute has a value that matches the one
specified after the period (or full stop) symbol.
Html
Css
. intro {font-family: verdana, sans-serif; margin: 10px;}
Group Selector
• Multiple selectors can be grouped in a single style declaration by using,
h1, h2, h3, h4, h5, h6 {font-family: sans-serif;}
35
Chapter 9
Types of Style Sheets
There are three ways of inserting a style sheet:
1. In-line styles
2. Internal style sheets (embedded)
3. External style sheets (linked)
1. In-Line Styles
An in-line style is included with the tag it affects. The formatting or layout
instruction used is then limited to the contents of just that individual tag. To create
an in-line style, simply add the STYLE attribute right into the attribute list of the
tag. For example, take the following HTML document:
36
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.
Html
<html>
<head><title> Internal Style Sheets</title></head>
<style>
H1 { font-family : Arial; font-size : 24px; font-style : italic; text-align : center; }
P { font-family : Tahoma; font-size : 16px; }
LI { font-family : Tahoma; font-size : 16px; font-weight : bold; }
</style><body>
<h1>Internet style sheet</h1>
<p>Subjects:</p>
<ul><li>HTML</li>
<li style = "font-weight : normal;">CSS</li>
<li>BOOTSTRAP</li>
<li style = "font-weight : normal;">PHP</li></ul>
</body></html>
Result
37
3. External Style Sheets
Html Result
<html>
<head><title> Internal Style Sheets</title>
<link rel = "stylesheet"
href = "style.css" type = "text/css">
</head>
<style>
</style><body>
<h1>Internet style sheet</h1>
<p>Subjects:</p>
<ul><li>HTML</li>
<li style = "font-weight: normal;">CSS</li>
<li>BOOTSTRAP</li>
<li style = "font-weight: normal;">PHP</li></ul>
</body></html>
38
Chapter 10
Formatting and Layout
In this chapter you will be introduced to many of the properties (attributes) that
apply to the formatting and layout of your HTML document.
The properties have been broken down into the following categories:
Font attributes
Color attributes
Links attributes
Background attributes
Margins and Alignment
1. Font attributes
CSS offers many attributes to replace and extend many of the font and text
formatting tags that exist within the HTML markup language. Listed below are
some most common font-formatting attributes of CSS:
39
2. Color Attributes
Attribute Description
Colors
Aqua Gray Navy Silver
Black Green Olive Teal
Blue Lime Purple White
40
Hexadecimal color
Color Hexadecimal Value
Red #FF0000
Green #00FF00
Blue #0000FF
Gray #808080
Yellow #FFFF00
Fuchsia #FF00FF
Cyan #00FFFF
Black #000000
White #FFFFFF
RGB Colors
rgb(255, 0, 0) red
rgb(0, 255, 0) green
rgb(0, 0, 255) blue
Example
body{
background-color: rgb(0, 191, 255);
color: rgb(255, 255, 255);
}
41
4. Link attributes
a:link {
color: blue; background-color: blue; text-decoration: none;
}
a:visited {
color: white; background-color: red; text-decoration: none;
}
a:hover {
background-color:green; text-decoration: underline;
}
a:active {
color: yellow; background-color: transparent;
}
4. Background attributes
Background Color
Sets the background color for the element.
Example
42
Background Image
Background repeater
BODY {
background-image: url(“wagad.jpg");
background-repeat: repeat-x;
/* repeat-y; or no-repeat; */
}
5. Alignment
H1 { text-align: center; }
H2 { text-align: right; }
H3 { text-align: left; }
P { text-align: justify; }
43
Chapter 11
Positioning
The CSS positioning properties allow you to position an element. It can also
place an element behind another, and specify what should happen when an
element's content is too big. Elements can be positioned using the top,
bottom, left, and right properties. However, these properties will not work
unless the position property is set first. They also work differently depending
on the positioning method.
There are four different positioning methods.
Static Positioning
HTML elements are positioned static by default. A static positioned element
is always positioned according to the normal flow of the page.
Static positioned elements are not affected by the top, bottom, left, and right
properties.
Fixed Positioning
An element with fixed position is positioned relative to the browser window.
It will not move even if the window is scrolled:
Example
44
Relative Positioning
A relative positioned element is positioned relative to its normal position.
Example
Absolute Positioning
An absolute position element is positioned relative to the first parent element
that has a position other than static. If no such element is found, the
containing block is :
Example
References
1. http://www.w3c.org
2. http://www.w3schools.com.
3. John Wiley & Sons, 2011, HTML & CSS Design and build Websites
45