Docsity

Chapter 3 HTML - Hyper Text Markup Language (HTML) - Study and lecture notes, Study notes of Java Programming

Toggle sidebar
bg1
CHAPTER 3
Hyper Text Markup Language (HTML)
3.1 Introduction
Hyper Text Markup Language (HTML) is a markup language designed for the
creation of web pages with hypertext and other information to be displayed in a web
browser. HTML is used to structure the information denoting certain text as headings,
paragraphs, lists and so on and can be used to describe the appearance and semantics of a
document. An HTML file is a text file containing predefined tags(<..>). The attributes
can be set through the HTML tags and it must be written only in the start tag.
HTML was originally defined by Tim Berners-Lee, HTML is now an
international standard (ISO/IEC 15445:2000). Later HTML specifications are maintained
by the World Wide Web Consortium (W3C). One can write the HTML in a plain text
editor, such as Note Pad, or use an HTML editor.The markup tags tell the Web browser
how to display the page.An HTML file must have an .htm or .html file extension.
3.2 Basic HTML Document Structure
The structure of HTML is as follows.
<HTML>
<HEAD>
<TITLE>Your Page Title</TITLE>
</HEAD>
<BODY>
This area will contain everything that will be visible through a web browser,
such as text and graphics. All of the information will be HTML coded.
</BODY>
</HTML>
<HTML> - Begins the HTML document.
<HEAD> - Contains information about the page such as the TITLE, META tags for
proper Search Engine indexing, STYLE tags, which determine the page layout, and
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f

Partial preview of the text

Download Chapter 3 HTML - Hyper Text Markup Language (HTML) - Study and lecture notes and more Study notes Java Programming in PDF only on Docsity!

CHAPTER 3

Hyper Text Markup Language (HTML)

3.1 Introduction

Hyper Text Markup Language (HTML) is a markup language designed for the creation of web pages with hypertext and other information to be displayed in a web browser. HTML is used to structure the information denoting certain text as headings, paragraphs, lists and so on and can be used to describe the appearance and semantics of a document. An HTML file is a text file containing predefined tags(<..>). The attributes can be set through the HTML tags and it must be written only in the start tag.

HTML was originally defined by Tim Berners-Lee, HTML is now an international standard (ISO/IEC 15445:2000). Later HTML specifications are maintained by the World Wide Web Consortium (W3C). One can write the HTML in a plain text editor, such as Note Pad, or use an HTML editor.The markup tags tell the Web browser how to display the page.An HTML file must have an. htm or. html file extension.

3.2 Basic HTML Document Structure

The structure of HTML is as follows.

Your Page Title

This area will contain everything that will be visible through a web browser, such as text and graphics. All of the information will be HTML coded.

**** - Begins the HTML document. **** - Contains information about the page such as the TITLE, META tags for proper Search Engine indexing, STYLE tags, which determine the page layout, and

JavaScript coding for special effects. **** - The TITLE of the page. This will be visible in the title bar of the viewers’ browser. **** - Closes the tag. It is the end tag of title tag. </HEAD> - Closes the <HEAD> tag.

<BODY> - This is where you will begin writing your document and placing your HTML codes. </BODY> - Closes the <BODY> tag. </HTML> - Closes the <HTML> tag.

3.3 Basic HTML Tags

HTML elements are defined using HTML tags.

  • HTML tags are used to mark-up HTML elements
  • HTML tags are surrounded by the two characters < and >
  • The surrounding characters are called angle brackets
  • HTML tags normally come in pairs like <b> and </b>, except a few like <br>
  • The first tag in a pair is the start tag, the second tag is the end tag
  • The text between the start and end tags is the element content
  • HTML tags are not case sensitive, for example <b> means the same as <B>

HTML Elements

HTML documents are text files made up of HTML elements.

Example

<b>This text is bold</b> The HTML element starts with a start tag <b>. The content of the HTML element is: This text is bold. The HTML element ends with an end tag: </b>.The

far the glyph for the lowercase "o" extends below the baseline, and subtract that value from the top of its bounding box. In the cases where it is impossible or impractical to determine the x-height, a value of 0.5em should be used.

The rule: h1 { line-height: 1.2em } means that the line height of "h1" elements will be 20% greater than the font size of the "h1" elements. On the other hand: h1 { font-size: 1.2em } means that the font-size of "h1" elements will be 20% greater than the font size inherited by "h1" elements. Pixel units are relative to the resolution of the viewing device, i.e., most often a computer display. It is recommended that the pixel unit refer to the whole number of device pixels that best approximates the reference pixel.

In the following rules, the computed 'text-indent'^ value of "h1" elements will be 36px, not 45px, if "h1" is a child of the "body" element.

body { font-size: 12px; text-indent: 3em; /* i.e., 36px */ } h1 { font-size: 15px }

Absolute length units are only useful when the physical properties of the output medium are known. The absolute units are:

  • in : inches — 1 inch is equal to 2.54 centimeters.
  • cm : centimeters
    • mm : millimeters
    • pt : points — the points used by CSS 2.1 are equal to 1/72nd of an inch.
  • pc : picas — 1 pica is equal to 12 points.

h1 { margin: 0.5in } /* inches / h2 { line-height: 3cm } / centimeters / h3 { word-spacing: 4mm } / millimeters / h4 { font-size: 12pt } / points / h4 { font-size: 1pc } / picas */ Percentages The format of a percentage value (denoted by ^ in this specification) is a ^ immediately followed by '%'.

Percentage values are always relative to another value, for example a length. Each property that allows percentages also defines the value to which the percentage refers. The value may be that of another property for the same element, a property for an ancestor element, or a value of the formatting context (e.g., the width of a containing block). When a percentage value is set for a property of the root element and the percentage is defined as referring to the inherited value of some property, the resultant value is the percentage times the initial value of that property.

Since child elements (generally) inherit the computed values of their parent, in the following example, the children of the P element will inherit a value of 12px for 'line- height', not the percentage value (120%):

p { font-size: 10px } p { line-height: 120% } /* 120% of 'font-size' */

3.3.2 Formatting Tags

Header Tags

Headings are defined with the to tags. defines the largest heading. defines the smallest heading. HTML automatically adds an extra blank line before and after a heading.

Example

This is a heading

- The paragraph will be aligned in the right.

Break Tag

The
tag is used when one want to end a line, but don't want to start a new paragraph. The
tag forces a line break wherever it will be needed. The
tag is an empty tag. It has no closing tag.

Example



To break
lines
in a
paragraph,
use the br tag.



Output

To break lines in a paragraph, use the br tag.

Comment Tag

The comment tag is used to insert a comment in the HTML source code. The browser will ignore a comment. One can use comments to explain the code, which can help us when the editing is needed in the source code at a later stage. In this an exclamation point should be included after the opening bracket, but not before the closing bracket.

Example

**Horizontal rule** tag is used to draw a horizontal line. **Table 3.2 Attributes of Hr tag**

Attribute Value Description

align left center right

Use styles instead. Specifies the alignment of a hr element

noshade noshade Use styles instead. Specifies that a hr element should render in one solid color (noshaded), instead of a shaded color size pixels Use styles instead. Specifies the height of a hr element width pixels %

Use styles instead. Specifies the width of a hr element Example

The hr tag defines a horizontal rule:

This is a paragraph

This is a paragraph

This is a paragraph

This is a paragraph

Output The hr tag defines a horizontal rule:

Defines teletype text

Defines a variable

Defines preformatted text

Table 3.5 Citations, Quotations, and Definition Tags

Tag Description

Defines an abbreviation

Defines an acronym

Defines an address element

Defines the text direction

Defines a long quotation

Defines a short quotation

Defines a citation

Defines a definition term

Example ** This text is bold
This text is strong

This text is big **



This text is emphasized



This text is italic



This text is small



This text contains


subscript



This text contains


superscript




Output

This is preformatted text. It preserves both spaces and line breaks. The pre tag is good for displaying computer code: for i = 1 to 10 print i next i

Address Tag

It demonstrates how to write an address in an HTML document.

Example

Donald Duck

BOX 555

Disneyland

USA

The Output is

Donald Duck BOX 555

Disneyland USA Font Tag The tag is used to give the size, color etc of font. It is deprecated. It is supposed to be removed in a future version of HTML. Example

This is a paragraph.

This is another paragraph.

Output: This is a paragraph. This is another paragraph. **Table 3.6 Attributes of Font Tag**

Attribute Example Purpose

size="number" size="2" Defines the font size

size="+number" size="+1" Increases the font size

size="-number" size="-1" Decreases the font size

face="face-name" face="Times" Defines the font-name

color="color-value" color="#eeff00" Defines the font color

color="color-name" color="red" Defines the font color

This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it.

** tag**

The tag in HTML is a tag that defines logical divisions within the content of a page. It means is that a tag defines sections of a Web page to make it easier to manage, style, and manipulate. You can use the tag when you want to center a block of content or position a content block on the page. The tag is a very powerful tool for Web developers.

The tag is a block-level element. The tag can contain nearly any other tag. The tag cannot be inside

tags. The

tag gives you the ability to name certain sections of your documents so that you can affect them with style sheets or Dynamic HTML. It breaks paragraphs. It acts as a paragraph end/beginning, and while you can have paragraphs within a you can't have a inside a paragraph. Example This is a header

This is a paragraph.

This is a header This is a paragraph The tag supports the following standard attributes: Table 3.7 Attributes of div Tag

Attribute Value Description

class classname Specifies a classname for an element

dir rtl ltr

Specifies the text direction for the content in an element id id Specifies a unique id for an element

lang language_code Specifies a language code for the content in an element style style_definition Specifies an inline style for an element

title text Specifies extra information about an element

xml:lang language_code Specifies a language code for the content in an element, in XHTML documents ** tag** The tag is a tag that groupings of inline content within the content of a page. This means that, a tag defines portions of Web elements to make them easier to manage, style, and manipulate. You can use the tag when you want to change the color of a single word. The tag is a very powerful tool for Web developers because it is so open-ended. The span tag can do anything you want it to do. The tag is an inline-level element. The tag can only contain other inline elements like abbr, strong, or tt. The tag can be inside

tags or

tags. The tag has very similar properties to the tag, in that it changes the style of the text it encloses. But without any style attributes, the tag won't change the enclosed items at all. The primary difference between the and tags is that doesn't do any formatting of it's own. The tag acts includes a paragraph break, because it is defining a logical division in the document. The tag simply tells the browser to apply the style rules to whatever is within the .

Use when you want to change the style of elements without placing them in a new block-level element in the document. For example, if you had a Level 3 Heading () that you wanted the second word to be red, you could surround that word with span.

Example: National Engineering College

9 of them. To add spaces to our text, use the character entity. The most common entities are given in the table below.

Table 3.8 Character Entities Result Description Entity Name Entity Number non-breaking space
< less than < < > greater than > > & ampersand & & " quotation mark " " ' apostrophe ' (does not work in IE) ' Result Description Entity Name Entity Number ¢ cent ¢ ¢ £ pound £ £ ¥ yen ¥ ¥ § section § § © copyright © © ® registered trademark ® ® × multiplication × × ÷ division ÷ &#

3.4 HTML Images

HTML images are defined with the tag. Example

GIF & JPG

Computers store images in several different ways. Some storage methods focus on compressing the size of the image as much as possible. A major problem with using images on websites is that images take much longer to load than text. To reduce

download times as much as possible two of the best image compressing formats used on the web is:

Table 3.9 Difference between GIF and JPG

GIF JPG

256 colors Unlimited colors

Can handle transparent areas Can't handle transparent areas

This format is not good at compressing photographs

Excellent for compressing photographs and complex images In general, it is excellent for banners, buttons and clipart

In general, it is not good for banners, buttons and clipart.

This means that:

  • Banners, buttons, dividers, clipart and other simple images usually work best as GIF's.
  • Photographs and other complex images usually work best as JPG's. If you want to use an image that is in a format other than JPG or GIF, you will need to load the image into a graphics program and save it as either JPG or GIF.

Image Resizing

You can change the size of an image using the width and height attributes. In general, it is not advisable to reduce image size using these settings, since the image will be transferred over the internet in its original size no matter what reduction is set for it. This will slow the loading of your webpage. This means, that if you have an image that is bigger in size than you want it to be on your page, you should reduce the size in a graphics program, rather than reducing the size on the webpage using the width and height attributes. On the contrary, sometimes, it can be wise to enlarge images using this technique. Below are two presentations of the exact same image - with different settings for width and height.