Java Unit4
Java Unit4
HTML: use of commenting, headers, text styling, images, formatting text with ,
special characters, horizontal rules, line breaks, table, forms, image maps, tags,
tags, file formats including image formats.
What is HTML?
HTML is a markup language for describing web documents (web pages).
Example
<!DOCTYPE html>
.in
hi
<html>
at
<head>
ss
<title>Page Title</title>
</head>
pu
<body>
m
</body>
</html>
The start tag is also called the opening tag, and the end tag the closing tag.
.in
hi
Web Browsers
at
ss
The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML
pu
The browser does not display the HTML tags, but uses them to determine how
to display the document:
ca
HTML Page Structure .in
hi
at
ss
<html>
<head>
m
<title>Page title</title>
ca
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Note: Only the content inside the <body> section (the white area above) is
displayed in a browser.
It must only appear once, at the top of the page (before any HTML tags).
There are different document types. To display a web page correctly, the
browser must know both type and version.
The doctype declaration is not case sensitive. All cases are acceptable:
<!DOCTYPE html>
<!doctype HTML>
HTML Versions
Since the early days of the web, there have been many versions of HTML:
.in
Version Year hi
HTML 1991
at
XHTML 2000
HTML5 2014
Name the file "index.htm" and set the encoding to UTF-8 (which is the
preferred encoding for HTML files).
View the HTML Page in Your Browser
Open the saved HTML file in your favorite browser (double click on the file, or
right-click - and choose "Open with").
.in
hi
at
ss
pu
m
ca
HTML Headings
HTML 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 heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="http://www.w3schools.com">This is a link</a>
<br> is an empty element without a closing tag (the <br> tag defines a line
pu
break).
m
Empty elements can be "closed" in the opening tag like this: <br />.
ca
HTML5 does not require empty elements to be closed. But if you want stricter
validation, or if you need to make your document readable by XML parsers, you
must close all HTML elements properly.
Example
<p title="I'm a tooltip">
This is a paragraph.
</p>
The href Attribute
HTML links are defined with the <a> tag. The link address is specified in
the href attribute:
Example
<a href="http://www.w3schools.com">This is a link</a>
Size Attributes
HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and height)
are all provided as attributes:
Example
.in
hi
<img src="w3schools.jpg" width="104" height="142">
at
The alt attribute specifies an alternative text to be used, when an image cannot
m
be displayed.
ca
The value of the attribute can be read by screen readers. This way, someone
"listening" to the webpage, e.g. a blind person, can "hear" the element.
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
The <hr> element is used to separate content (or define a change) in an HTML
page:
Example
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
HTML Display
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.
.in
The browser will remove any extra spaces and extra lines when the page is
hi
displayed:
at
Example
ss
pu
<p>
m
This paragraph
contains a lot of lines
ca
<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
Example
<p>This is<br>a paragraph<br>with line breaks.</p>
Example
<pre>
My Bonnie lies over the ocean.
.in
hi
My Bonnie lies over the sea.
at
ss
</pre>
ca
Example
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
HTML Text Color
The color property defines the text color for an HTML element:
Example
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
HTML Fonts
The font-family property defines the font to be used for an HTML element:
Example
.in
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
hi
HTML Text Size
at
ss
The font-size property defines the text size for an HTML element:
pu
Example
m
ca
Example
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
Example
<b>This text is bold</b>
The HTML <strong> element defines strong text, with added semantic
"strong" importance.
Example
<strong>This text is strong</strong>
Example .in
hi
at
<h2>HTML <small>Small</small> Formatting</h2>
ss
Example
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
Notice that there is an exclamation point (!) in the opening tag, but not in the
closing tag.
Note: Comments are not displayed by the browser, but they can help document
your HTML source code.
With comments you can place notifications and reminders in your HTML:
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:red">
.in
hi
Background-color set by using red
at
ss
</h2>
pu
<h2 style="background-color:orange">
m
</h2>
<h2 style="background-color:yellow">
</h2>
<h2 style="background-color:blue;color:white">
</h2>
<h2 style="background-color:cyan">
</h2>
</body>
</html>
CSS saves a lot of work. It can control the layout of multiple web pages all at
once.
External CSS
m
ca
An external style sheet is used to define the style for many HTML pages.
With an external style sheet, you can change the look of an entire web
site, by changing one file!
To use an external style sheet, add a link to it in the <head> section of the
HTML page:
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor. The file must not
contain any HTML code, and must be saved with a .css extension.
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
.in
color: red;
}
hi
CSS Fonts
at
ss
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Border
The CSS border property defines a border around an HTML element:
Example
p {
border: 1px solid powderblue;
}
The CSS padding property defines a padding (space) between the text and the
ss
border:
pu
Example
m
ca
p {
border: 1px solid powderblue;
padding: 30px;
}
ca
m
pu
ss
at
hi
.in