







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Creating Web Pages with XHTML Introduction The HyperText Markup Language (HTML) is a language comprised of a series of coded tags that describe the structure of a document. The idea is that most documents have common elements, such as titles, paragraphs, etc. Because HTML is a markup language, you begin with the text of your page and add special tags around words and paragraphs. These tags indicate different parts of a page and produce different effects in the Web browser. HTML tags are the codes inside brackets (< >) that indicate the features of the page. A text editor can be used to create and edit HTML documents. You can see the HTML code of any Web page by choosing View > Source from the browser's menu bar. HTML tags are not case sensitive, although the newest version of HTML, called XHTML (Extensible Hypertext Markup Language), requires all tags to be written in lowercase. XHTML was designed to improve and standardize HTML. With all that is being put on the Web it will take a long time before most of the HTML on the Web is standardized. Although we will not be running our HTML as strict XHTML, we will start using the standards. Most HTML tags require a corresponding closing tag. The closing tags contain a backslash after the opening bracket. XHTML requires the backslash in the opening tag if a closing tag is not required. The tags can be on the same line with the text or on a line by themselves. When the Enter key is used in the text processor to move to the next line, a new-line character is created which is ignored by HTML. Since extra spaces and blank lines are ignored in HTML, use them to line up the opening and closing tags and to make your code easy to read so you can find errors. HTML does not produce error messages, as programming languages do. Many of the HTML tags can contain attributes. The attributes are listed inside the brackets with their values, . According to the XHTML standards, attribute values should be enclosed in quotes. The corresponding closing tag must not contain attributes. Each HTML tag has a default interpretation in terms of its display properties, which may slightly differ from one browser to the next. Attributes are used to change these default display properties and customize them. There are various ways to set attribute values for HTML tags. In this course we will set attribute values using cascading style sheets (CSS). Style sheets allow for efficient and flexible customization of HTML tags especially when the same tag attribute values are used repeatedly in order to maintain a uniform “look and feel” for multiple Web pages. Required HTML Tags There are three tags that are used to describe the overall structure of a page and provide simple header information. These are , , and . Let's explore each of these. **** - is the first structure tag in every HTML page. Your HTML page must begin with this tag and end with . The same tag with a backslash in front of it indicates to the browser that this particular section has concluded. **** - specifies that the lines between the beginning and end points of this tag are the prologue to the rest of the file. Title tags are placed inside the head tags as shown in the example below. The text between the title tags is the title of the Web page and will appear in the title bar of the browser window. Remember to close the head with .
insert the title here
**** - contains the remainder of your HTML page, which includes text, links, image tags, etc. Most of the important elements of the page are placed between and . You should have only one pair of opening and ending body tags.
Every basic HTML page, therefore, looks like the following code segment:
This is a simple HTML page
... rest of HTML page code including text and tags ...
The Heading Tags Inside the body, you may want to separate your text into headings and paragraphs. The tags used for headings are through , with the largest and the smallest. The largest can be used for headlines, and the smaller headings can be used for the copyright information at the bottom of a Web page. These all have corresponding end tags. Heading tags are rendered differently by different browsers. Here is an example of how to apply a heading tag to a text segment. This is text is a large (h1) heading. The Paragraph Tag The paragraph tag is specified with
. Although the corresponding
tag is optional in the early versions of HTML, it is required in the newest versions and should be used. The paragraph tag forces the text following the tag to drop down and leave a blank space, slightly larger than a blank line, creating a new paragraph. When consecutive paragraph tags are used, most browsers ignore all but the first. Thetag can appear anywhere in the text within the body tags. The following examples produce the same results. Example 1:
Paragraph Example
This is the first paragraph.
This text begins a new paragraph.
This text begins paragraph three.
Example 2: Paragraph Example
This is the first paragraph.
This text begins a new paragraph.
This text begins paragraph three.
The Break Tag The break tag,
, forces a line break. The closing break tag did not exist in early versions of HTML, but now the slash is included in the opening tag. Note that there is a space between the br and the slash in the tag. The space is required for reasons of backward compatibility with older browsers. Use consecutive break tags to create blank lines.
the size of the image in the BlackLab.jpg file will be displayed as half of the browser window's length and width and will change as the window size changes. NOTE: If you used a space before the percent sign and omitted the quotation marks, the code would not work. The quotation marks, although required in the standards, are not actually necessary in the older HTML unless the attribute value contains a space.
Resizing an Image by Specifying its Dimensions in Pixels The height and width attributes can also be set to the height and width of an image in pixels. A pixel, taken from the words "picture element," is the smallest unit on the screen that is capable of changing color. When the value of the height and width attributes are given in numbers without percent signs, the numbers represent number of pixels. In the example:
the image displayed from the file BlackLab.jpg will be quite small, 60 pixels across and 50 pixels down. You may want a much larger image, width="350" height="250", or even larger. Since you have specified the exact number of pixels, resizing the browser window will not change the image size. Experiment with both sizing methods to determine what size image looks best on your Web page.
Spacing the Image with the Paragraph Tag Surround the image tag with two paragraph tags to place the image by itself with a little space above and below the image. Example:
Aligning Images The align attribute can be used in the tag to help place an image where you want it in relation to the window's edge or the adjacent text. The values for the align attribute are left , right , top , bottom , and middle. Left and Right - Using the value left or right will align the image against the left or right edge of the browser window or against the previous image. The text then fills the remaining adjacent portion of the window. Setting the align attribute to left or right can also be used to create a row of images.
The three images will appear side by side across the screen with the top of the images aligned. If the window is resized smaller, the images displayed do not move. Using the same code, when align="left" is omitted in each line; the images will appear side by side aligned on the bottom edge of the images. If the window is not large enough or is resized too small, the images will wrap, one below another. **Top -** The top edge of the image will be aligned with the top of the current line of text. If there are other images in the current line of text, the text will be aligned with the top of the tallest image that came before it in the line. **Bottom -** The bottom edge of the text will be aligned with the bottom edge of the image. This is the default. **Middle** - Netscape will align the middle of the image to the bottom of the current text line even if the text line contains other images. **_More about the Break Tag_** The
Houston Los Angeles Miami New York City
The result in the browser will appear as follows: Large cities in the US Atlanta Chicago Houston Los Angeles Miami New York City Ordered Lists and Numbered Lists An ordered list in HTML creates a numbered list. The list item tag, , is used in front of each item in the list. The items are surrounded by the opening and closing ordered list tags, ... . Example: Largest cities in the US New York City Los Angeles Chicago Houston Atlanta Miami
The browser result will be as follows: Largest cities in the US
New York City
Los Angeles
Chicago
Houston
Atlanta
Miami Nested Lists Lists can be nested to create outlines by putting an ordered list tag, , or an unordered list tag, , after a list item, followed by the sublist items and the appropriate closing list tag ( or ). The browser will use different shaped bullets depending on the level of nesting. In the example below an unordered list is nested below each item of the ordered list. Large cities in the US New York City
1990 population-19,549,649 2000 population-21,199,865 Los Angeles
1990 population-14,531,529 2000 population-16,373,645
Chicago
1990 population-8,239,820 2000 population-9,157,540
The following will be the result in the browser window: Large cities in the US 1 1. New York City 1990 population-19,549, 2000 population-21,199,
HTML Hyper Text Markup Language XHTML Extensible Hyper Text Markup Language CSS Cascading Style Sheet
The following will be the result in the browser window: HTML Hyper Text Markup Language XHTML Extensible Hyper Text Markup Language CSS Cascading Style Sheets
…… rest of the code Text Formatting Attributes You may use the text formatting attributes for customizing any HTML element that could incorporate text such as the body, paragraphs, and headings. font-family: This attribute is used to set the font type. By default, text appears in Times New Roman on most browsers. You may set this attribute to other font names. Note that the way some fonts are displayed on the browsers may not be very appealing. Test the fonts you wish to use by viewing them on the browser and try to use common fonts. font-size: This attribute is used to set the font size. By default the text is displayed in 12-point font on most browsers. However, other settings, such as the Text Size property of the browser, factor into how large the text appears on the screen. To set the size of the font, assign the point value you want. For example, use 14pt to indicate 14-point font. You may also set the size to a percentage of the normal font size. For example, use 50% to display the font as half of the size of the normal (default) font size. Finally, the font-size attribute can be set to one of the following xx-small, x-small, smaller, small, medium, large, larger, x-large, xx-large. font-style: This attribute is used to set the style of the font. You may use the values italic , normal , or oblique for this attribute. font-weight: This attribute is used to set the weight (thickness) of the font. Common values for this attribute are bold, light, bolder, lighter, or normal. text-decoration: You may add decoration to text by using this attribute which can have values none, underline, overline, line-through, or blink. color: To set the color of the text, assign values such as the name of a color (e.g. red) or the hexadecimal representation of the color (e.g. #767676) to this attribute. There are many resources on Internal Style Sheet
the Web that provide browser compatible color names as well as hexadecimal color codes. Refer to your class Web site for some of these resources. When setting the color of the text for your Web pages, be sure to view them on a browser to see how they appear to viewers. Pick colors that are easily readable and visible on your pages’ background colors or images. text-align: You may align text within a Web page element (e.g. paragraph, header, etc.) by setting this attribute to the desired type of alignment. The possible values for this attribute are left, right, center, and justify. Background Attributes background-color: This attribute sets the background color of an HTML element. You may use this attribute with the body and paragraph tags. For example, setting the background color for the body tag determines the background color that will fill the browser window when displaying the Web page. The possible values for this attribute are the same as those for the color attribute. background-image: Use this attribute if you wish to set an image as the background of an element. The value for this attribute is url (---- ) , where the dashes should be replaced by the name of the image file (including the file extension). By default the image will be tiled in the background of the element. The background-repeat attribute discussed below will help in setting the manner in which the background image is displayed. background-repeat: This attribute sets if and how the background image is to be repeated within the element. The possible values for this attribute are repeat, repeat-x, repeat-y, or no-repeat. The first value is analogous to the default tiled setting. Repeat-x, repeats the background image along the x-axis (horizontal) direction only while repeat-y does the same but along the y-axis (vertical) instead. No- repeat simply places one copy of the image on the page without any repetition in the background. The final display of the background image not only depends on its repeat attribute but also where we position the image relative to the element. For example, if we place it on the top left of the element, then a repeat-y will result in tiling the image along the left edge of the element. If we place it on the top right, repeat-y will result in tiling the image along the right edge of the element instead. To set the position of the background image relative to the element use the background-position attribute discussed below. background-position: This attribute sets the starting position of the background image with respect to the element. Possible values for this attribute are top left, top center, top right, center left, center center, center right, bottom left, bottom center, and bottom right. Note that each value has two keywords; the first for setting the vertical position and the second for setting the horizontal position of the image within the element. Example: p { background-image: url(pic1.jpg); background-repeat: repeat-y; background-position: top left; background-color: yellow; } pic1.jpg is the image file representing a single light bulb as shown below. Using the paragraph tag in the HTML file will result in the following display in the browser window: Hyperlink Attributes By default, any hyperlinks you insert into your Web pages will appear in blue changing to purple when activated. Depending on your background color or image, these default colors may not be
font-size: 10pt; font-family: Arial; } p.summary { color: red; font-size: 12pt; font-family: Garamond; } To use the two styles created, we simply incorporate their class names in the paragraph tags of HTML documents as shown in the following example. Example:
This is a paragraph that displays the attributes of the p.intro class.
This is a paragraph that displays the attributes of the p.summary class.
This is a normal paragraph. No styles applied.
The three paragraphs will appear in the browser as follows: This is a paragraph that displays the attributes of the p.intro class.CSS also allows for creating generic classes that can be used with multiple HTML elements. For example, suppose that we want to create a class called “red_c” which sets the color attribute of an HTML element to red. So, our style definition would be:
. red_c {color: red;} Note that there is a period before the class name. This class can now be used with any HTML element that has a color attribute. Example: Red Header
This paragraph text is red.
This HTML code will appear in the browser as follows: