This is a HTML practice exercise
The heading above is aligned to the center of this page. The heading above is aligned to the center of this page. The heading above is aligned to the center of this page.
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
This is heading 5
This is heading 6
14 trang |
Chia sẻ: hachi492 | Ngày: 06/01/2022 | Lượt xem: 471 | Lượt tải: 0
Bạn đang xem nội dung tài liệu Lab 1: Basic HTML, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Lab 1: Basic HTML
1.1. HTML Elements
1.1.1. HTML Elements
An HTML element is everything from the start tag to the end tag:
Start tag *
Element content
End tag *
This is a paragraph
This is a link
* The start tag is often called the opening tag. The end tag is often called the closing tag.
1.1.2. HTML Element Syntax
An HTML element starts with a start tag / opening tag
An HTML element ends with an end tag / closing tag
The element content is everything between the start and the end tag
Some HTML elements have empty content
Empty elements are closed in the start tag
Most HTML elements can have attributes
1.1.3. Nested HTML Elements
Most HTML elements can be nested (can contain other HTML elements).
HTML documents consist of nested HTML elements.
1.1.4. HTML Document Example
This is my first paragraph
The example above contains 3 HTML elements.
1.2. HTML Basic
1.2.1. HTML Headings
HTML headings are defined with the to tags.
Example
This is a heading
This is a heading
This is a heading
* Headings Are Important
Use HTML headings for headings only. Don't use headings to make text BIG or bold.
Search engines use your headings to index the structure and content of your web pages.
Since users may skim your pages by its headings, it is important to use headings to show the document structure.
H1 headings should be used as main headings, followed by H2 headings, then less important H3 headings, and so on.
* HTML Rules (Lines)
The tag is used to create an horizontal rule (line).
Example
This is a paragraph
This is a paragraph
This is a paragraph
* HTML Comments
Comments can be inserted in the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed.
Comments are written like this:
Example
1.2.2. HTML Paragraphs
HTML paragraphs are defined with the tag.
Example
This is a paragraph
This is another paragraph
* Don't Forget the End Tag
Most browsers will display HTML correctly even if you forget the end tag:
Example
This is a paragraph
This is another paragraph
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected results or errors.
* HTML Line Breaks
Use the tag if you want a line break (a new line) without starting a new paragraph:
Example
This isa paragraph with line breaks
The element is an empty HTML element. It has no end tag.
1.2.3. HTML Links
HTML links are defined with the tag.
Example
This is a link
1.2.4. HTML Images
HTML images are defined with the tag.
Example
1.3. HTML Attributes
1.3.1. HTML Attributes
HTML elements can have attributes
Attributes provide additional information about the element
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
Attribute Example
HTML links are defined with the tag. The link address is provided as an attribute:
Example
This is a link
1.3.2. Always Quote Attribute Values
Attribute values should always be enclosed in quotes.
Double style quotes are the most common, but single style quotes are also allowed.
In some rare situations, like when the attribute value itself contains quotes, it is necessary to use single quotes:
name='John "ShotGun" Nelson'
1.3.3. HTML Tip: Use Lowercase Attributes
Attribute names and attribute values are case-insensitive.
However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation
Newer versions of (X)HTML will demand lowercase attributes.
1.4. HTML Links
1.4.1. Hyperlinks, Anchors, and Links
In web terms, a hyperlink is a reference (an address) to a resource on the web.
Hyperlinks can point to any resource on the web: an HTML page, an image, a sound file, a movie, etc.
An anchor is a term used to define a hyperlink destination inside a document.
The HTML anchor element , is used to define both hyperlinks and anchors.
We will use the term HTML link when the element points to a resource, and the term HTML anchor when the elements defines an address inside a document..
1.4.2. An HTML Link
Link syntax:
Link text
The start tag contains attributes about the link.
The element content (Link text) defines the part to be displayed.
Note: The element content doesn't have to be text. You can link from an image or any other HTML element.
1.4.3. The href Attribute
The href attribute defines the link "address".
This element defines a link to W3Schools:
Visit W3Schools!
The code above will display like this in a browser:
Visit W3Schools!
1.4.4. The target Attribute
The target attribute defines where the linked document will be opened.
The code below will open the document in a new browser window:
Example
<a href=""
target="_blank">Visit W3Schools!
1.4.5. The name Attribute
When the name attribute is used, the element defines a named anchor inside a HTML document.
Named anchor are not displayed in any special way. They are invisible to the reader.
Named anchor syntax:
Any content
The link syntax to a named anchor:
Any content
The # in the href attribute defines a link to a named anchor.
1.5. HTML Tables
1.5.1. Tables
Tables are defined with the tag. A table is divided into rows (with the tag), and each row is divided into data cells (with the tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc.
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
How it looks in a browser:
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
1.5.2. Tables and the Border Attribute
If you do not specify a border attribute the table will be displayed without any borders. Sometimes this can be useful, but most of the time, you want the borders to show.
To display a table with borders, you will have to use the border attribute:
Row 1, cell 1
Row 1, cell 2
1.5.3. Headings in a Table
Headings in a table are defined with the tag.
Heading
Another Heading
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
How it looks in a browser:
Heading
Another Heading
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
1.5.4. Empty Cells in a Table
Table cells with no content are not displayed very well in most browsers.
row 1, cell 1
row 1, cell 2
row 2, cell 1
How it looks in a browser:
row 1, cell 1
row 1, cell 2
row 2, cell 1
Note that the borders around the empty table cell are missing (NB! Mozilla Firefox displays the border).
To avoid this, add a non-breaking space ( ) to empty data cells, to make the borders visible:
row 1, cell 1
row 1, cell 2
row 2, cell 1
How it looks in a browser:
row 1, cell 1
row 1, cell 2
row 2, cell 1
1.6. HTML Styles
1.6.1. The HTML Style Attribute
The purpose of the style attribute is:
To provide a common way to style all HTML elements.
Styles was introduced with HTML 4, as the new and preferred way to style HTML elements. With HTML styles, styles can be added to HTML elements directly by using the style attribute, or indirectly by in separate style sheets (CSS files).
You can learn everything about styles and CSS in our CSS tutorial.
1.6.2. HTML Style Examples
Look! Styles and colors
This text is in Verdana and red
This text is in Times and green
This text is 30 pixels high
1.6.3. Deprecated Tags and Attributes
In HTML 4, some tags and attributes are defined as deprecated. Deprecated means that they will not be supported in future versions of HTML and XHTML.
The message is clear: Avoid the use of deprecated tags and attributes.
These tags and attributes should be avoided:
Tags
Description
Defines centered content
and
Defines HTML fonts
and
Defines strikeout text
Defines underlined text
Attributes
Description
align
Defines the alignment of text
bgcolor
Defines the background color
color
Defines the text color
For all the above: Use styles instead.
1.7. HTML Lists
1.7.1. Unordered Lists
An unordered list is a list of items. The list items are marked with bullets (typically small black circles).
An unordered list starts with the tag. Each list item starts with the tag.
Coffee
Milk
Here is how it looks in a browser:
Coffee
Milk
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.
1.7.2. Ordered Lists
An ordered list is also a list of items. The list items are marked with numbers.
An ordered list starts with the tag. Each list item starts with the tag.
Coffee
Milk
Here is how it looks in a browser:
Coffee
Milk
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.
1.7.3. Definition Lists
A definition list is not a list of single items. It is a list of items (terms), with a description of each item (term).
A definition list starts with a tag (definition list).
Each term starts with a tag (definition term).
Each description starts with a tag (definition description).
Coffee
Black hot drink
Milk
White cold drink
Here is how it looks in a browser:
Coffee
Black hot drink
Milk
White cold drink
Inside the tag you can put paragraphs, line breaks, images, links, other lists, etc.
1.8. HTML Text Formatting
1.8.1. HTML Formatting Tags
HTML uses tags like and for formatting output, like bold or italic text.
These HTML tags are called formatting tags.
1.8.2. Text Formatting Tags
Tag
Description
Defines bold text
Defines big text
Defines emphasized text
Defines italic text
Defines small text
Defines strong text
Defines subscripted text
Defines superscripted text
Defines inserted text
Defines deleted text
Deprecated. Use instead
Deprecated. Use instead
Deprecated. Use styles instead
1.8.3. 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
* HTML Tag
The tag defines a short quotation.
The browser will insert quotation marks around the quotation.
A short quotation is marked up as follows:
Here is a short quotation here is a short quotation
* HTML Tag
The tag defines a long quotation.
A browser inserts white space before and after a blockquote element. It also insert margins for the blockquote element.
A long quotation is marked up as follows:
Here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation.
1.9. Exercises
Ex1.
- Create a simple HTML page as this below webpage:
This is a HTML practice exercise
The heading above is aligned to the center of this page. The heading above is aligned to the center of this page. The heading above is aligned to the center of this page.
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
This is heading 5
This is heading 6
- You should modify each tag by yourself and watch the effect of that modification.
Ex2.
- Create a simple HTML page as your personal webpage.
- Below are the suggested layout:
Personal Details
Image
Education process
Working process
Society activities
Skills
Experiences
Certifications
Hobbies
Desire
REFERENCES
[1]
Các file đính kèm theo tài liệu này:
- lab_1_basic_html.doc