HTML ELEMENTS/ HTML ATTRIBUTE

View previous topic View next topic Go down

HTML ELEMENTS/ HTML ATTRIBUTE

Post by Admin on Thu Jul 23, 2015 4:23 pm

Hi guys, hope we have learnt alot so far? aways remember that anypart of this tutorial giving you hard times, you should probably take a rest and a nice shower, then continue..

I have taken my time to make it simple for all of us so be calm, and never give up.

I know what i know today because of this large web designing website called "W3SCHOOLS.COM". OK Now back to business.

HTML documents are made up by HTML elements.

HTML Elements

HTML elements are written with a start tag, with an end tag, with the content in between:

content
The HTML element is everything from the start tag to the end tag:

My first HTML paragraph.



Start tag Element content End tag

My First Heading


My first paragraph.




Note Some HTML elements do not have an end tag.
Nested HTML Elements

HTML elements can be nested (elements can contain elements).

All HTML documents consist of nested HTML elements.

This example contains 4 HTML elements:

Example

Code:



<!DOCTYPE html>


<html>





<body>


 <h1>My First Heading</h1>


 <p>My first paragraph.</p>


</body>





</html>



Try it  »
HTML Example Explained

The element defines the whole document.

It has a start tag and an end tag .

The element content is another HTML element (the element).


Code:
<html>





<body>


 <h1>My First Heading</h1>


 <p>My first paragraph.</p>


</body>





</html>


The element defines the document body.

It has a start tag and an end tag .

The element content is two other HTML elements (

and

).


Code:
<body>


 <h1>My First Heading</h1>


 <p>My first paragraph.</p>


</body>


The

element defines a heading.

It has a start tag

and an end tag

.

The element content is: My First Heading.

My First Heading


The

element defines a paragraph.

It has a start tag

and an end tag

.

The element content is: My first paragraph.

My first paragraph.


Don't Forget the End Tag

Some HTML elements will display correctly, even if you forget the end tag:

Example


Code:
<html>





<body>


 <p>This is a paragraph


 <p>This is a paragraph


</body>





</html>



Try it »
The example above works in all browsers, because the closing tag is considered optional.

Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.

Empty HTML Elements

HTML elements with no content are called empty elements.


is an empty element without a closing tag (the
tag defines a line break).

Empty element can be "closed" in the opening tag like this:
.

HTML5 does not require empty elements to be closed. But if you need stricter validation, and make your document readable by XML parsers, please close all HTML elements.

HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive:

means the same as

.

The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.
HTML Attributes

HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
The lang Attribute

The document language can be declared in the tag.

The language is declared in the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines:

Example


Code:
<!DOCTYPE html>


<html lang="en-US">


<body>





<h1>My First Heading</h1>





<p>My first paragraph.</p>





</body>


</html>


The first two letters specify the language (en). If there is a dialect, use two more letters (US).

The title Attribute

HTML paragraphs are defined with the

tag.

In this example, the

element has a title attribute. The value of the attribute is "About Developer":

Example

Code:



<p title="About developers">


droid.1talk.net is a web developer's site.


It provides tutorials and references covering


many aspects of web programming,


including HTML, CSS, JavaScript, XML, SQL, PHP, ASP, etc.


</p>



Try it Yourself »
Note When you move the mouse over the element, the title will be displayed as a tooltip.
The href Attribute

HTML links are defined with the tag. The link address is specified in the href attribute:

Example

Code:



<a href="http://www.droid.1talk.net">This is a link</a>




Try it Yourself »
You will learn more about links and the
tag later in this tutorial.

Size Attributes

HTML images are defined with the tag.

The filename of the source (src), and the size of the image (width and height) are all provided as attributes:

Example


Code:
<img src="developer.jpg" width="104" height="142">




Try it Yourself »
The image size is specified in pixels: width="104" means 104 screen pixels wide.

You will learn more about images and the tag later in this tutorial.

The alt Attribute

The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed.

The value of the attribute can be read by "screen readers". This way, someone "listening" to the webpage, i.e. a blind person, can "hear" the element.

Example

Code:



<img src="developer-forums.jpg" alt="developer-forum.com" width="104" height="142">



Try it Yourself »
We Suggest: Always Use Lowercase Attributes

The HTML5 standard does not require lower case attribute names.

The title attribute can be written with upper or lower case like Title and/or TITLE.

I recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.

Note Lower case is the most common. Lower case is easier to type.
At W3Schools we always use lower case attribute names.
We Suggest: Always Quote Attribute Values

The HTML5 standard does not require quotes around attribute values.

The href attribute, demonstrated above, can be written as:

Example

Code:



<a href=http://www.droid.1talk.net>




Try it Yourself »
I recommends quotes in HTML4, and demands quotes for stricter document types like XHTML.

Sometimes it is necessary to use quotes. This will not display correctly, because it contains a space:

Example



Try it Yourself »
Note Using quotes are the most common. Omitting quotes can produce errors.
At W3Schools we always use quotes around attribute values.
Single or Double Quotes?

Double style quotes are the most common in HTML, but single style can also be used.

In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:

Example


Or vice versa:

Example


Chapter Summary

All HTML elements can have attributes
The HTML title attribute provides additional "tool-tip" information
The HTML href attribute provides address information for links
The HTML width and height attributes provide size information for images
The HTML alt attribute provides text for screen readers

Test Yourself with Exercises!

HTML Attributes

Below is an alphabetical list of some attributes often used in HTML:

Attribute Description
alt Specifies an alternative text for an image
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element
title Specifies extra information about an element (displayed as a tool tip)
value Specifies the value (text content) for an input element.
A complete list, of all legal attributes for each HTML element, is listed in our: HTML Tag Reference.

avatar
Admin
Admin
Admin

Posts : 83
Points : 7847
Reputation : 3
Join date : 2015-07-22

View user profile http://droid.1talk.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum