Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Tutorials > HTML Tags and attributes > Page 3

Bypass main content

HTML Tags and attributes (page 3)

Pages:<123
Bypass main content

Practice

We're going to build a nice paragraph with a link inside of it, so later we can change their properties.

The first step is to build the paragraph with its content. Paragraphs are inserted in HTML documents through the HTML p tag. We can do it as follows:

Code
<p>This is a nice paragraph.</p>
View

This is a nice paragraph.

Now let's put the link inside of it, through the insertion of the HTML a tag. At the begining, we'll just place the element with its content ("nice link") and no attributes or events:

Code
<p>This is a nice paragraph with a <a>nice link</a> in the middle.</p>
View

This is a nice paragraph with a nice link in the middle.

As you may see, there is no link yet, so we should consider that adding an HTML a tag doesn't mean a link has been stablished (the "href" attribute does). We'll keep calling it like that because we know it will become a link soon or later.

This is the time where we start using attributes. The first attribute we're adding is "lang". With this particular attribute we're telling the procesing agent (browser, search engine robot, etc.) which language is this paragraph written in. The values for this attribute can be obtained from the list of Language codes.

Code
<p lang="en">This is a nice paragraph with a <a>nice link</a> in the middle.</p>
View

This is a nice paragraph with a nice link in the middle.

There we go. We are now showing a piece of text and giving an extra hint about it. This type of attributes are most times hidden attributes, because we are not able to see them in traditional web browsers. However, many user agents use this information at some level (e.g. spoken browsers, commonly used by blind people, speak this text in english instead of the language of the document, for example, spanish).

Other attributes, like the one we're using next, are clearly visible. The "href" attribute works only in the HTML a tag and specifies a resource to which this document is making a reference to. It's value must be the address of the referenced resource, in this case, the HTML a tag's URL.

Code
<p lang="en">This is a nice paragraph with a <a href="http://www.htmlquick.com/reference/tags/a.html">nice link</a> in the middle.</p>
View

This is a nice paragraph with a nice link in the middle.

So far, we've learned to use tags and attributes in HTML documents. To end with this practice, we're adding an event.

Events are a jump beyond HTML, given that they're useless without a client-side language. Basicly, what an event does, is to trigger a program written in a client-side language. So, as this is an HTML tutorial, we'll limit to show how to trigger the script, not to build it.

In this example, we'll trigger two scripts named "do_something_click()" and "do_something_mouse_over()", in the same paragraph we've been using. The argument "this" will tell the script, which element it should affect.

The events we've picked are "onclick" and "onmouseover". These events are triggered when the visitor clicks or passes the mouse over the content of the element. To check what other accions can trigger events, see this list of HTML events.

As we'll use this events in the paragraph, they will trigger the scripts when the visitor clicks or passes the mouse over the paragraph. To make it visible, we're using basic scripts to change the color of the text: red when the mouse passes over the text and green when it's clicked.

Code
<p lang="en" onclick="do_something_click(this)" onmouseover="do_something_mouse_over(this)">This is a nice paragraph with a <a href="http://www.htmlquick.com/reference/tags/a.html">nice link</a> in the middle.</p>
View

This is a nice paragraph with a nice link in the middle.

Congratulations! the practice is done. Get ready to take the next tutorial.

Pages:<123

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate