In HTML, colors can be added by using the
This results in:
This results in:
This results in:
Hexadecimal values are a combination of letters and numbers. The numbers go from 0 - 9 and the letters go from A to F. When using hexadecimal color values in your HTML/CSS, you preceed the value with a hash (#). Although hexadecimal values may look a little weird at first, you'll soon get used to them.
There are 16 color names (as specified in the HTML 4.0 specification). The chart below shows these color names and their corresponding hexadecimal value.
You can make up your own colors by simply entering any six digit hexadecimal value (preceeded by a hash). In the following example, we're using the same code as above. The only difference is that, instead of using "blue" as the value, we're using its hexadecimal equivalent (which is #0000ff):
This results in:
If we wanted to change to a deeper blue, we could change our hexadecimal value slightly, like this:
This results in:
Links, otherwise known as hyperlinks, are defined using the
To create a hyperlink, you use the a tag in conjunction with the href attribute (href stands for Hypertext Reference). The value of the href attribute is the URL, or, location of where the link is pointing to.
Example HTML Code:
This results in:
Hypertext references can use absolute URLS, relative URLs, or root relative URLs.
The target attribute can have the following possible values:
Example HTML Code:
This results in:
To use named anchors, you need to create two pieces of code - one for the hyperlink (this is what the user will click on), and one for the named anchor (this is where they will end up).
This page uses a named anchor. I did this by performing the steps below:
This results in:
When you click on the above link, this page should jump up to the "Link Targets" section (above). You can either use your back button, or scroll down the page to get back here.
You're back? Good, now lets move on to email links.
Example HTML Code:
This results in:
Clicking on this link should result in your default email client opening up with the email address already filled out.
You can go a step further than this. You can auto-complete the subject line for your users, and even the body of the email. You do this appending
Example HTML Code:
This results in:
Example HTML Code:
This can be used to produce some nice layout effects, especially if you have a lot of text, and it runs right past the image.
This results in:
This results in:
Comments always start with
This results in:
As you can see, the comment is invisible to the user viewing the page in the browser. It is there, simply for the HTML coder's benefit.
Well, we have now finished the first part of this tutorial. We have covered a lot, and by now, you have learned enough to build a website.
If you'd like to learn some of the more advanced HTML techniques, such as, how to create tables, frames, forms etc, please continue!
style
attribute. You can specify a color name (eg, blue), a hexadecimal value (eg, #0000ff), or an RGB value (eg rgb(0,0,255)). Syntax
Foreground Color
To add color to an HTML element, you usestyle="color:{color}"
, where {color} is the color value. For example:<h3 style="color:blue">HTML Colors</h3>
HTML Colors
Background Color
To add a background color to an HTML element, you usestyle="background-color:{color}"
, where {color} is the color value. For example:<h3 style="background-color:blue">HTML Colors</h3>
HTML Colors
Border Color
To add a colored border to an HTML element, you usestyle="border:{width} {color} {style}"
, where {width} is the width of the border, {color} is the color of the border, and {style} is the style of the border. For example:<h3 style="border:1px blue solid;">HTML Colors</h3>
HTML Colors
Color Names
The most common methods for specifying colors are by using the color name or the hexadecimal value. Although color names are easier to remember, the hexadecimal values and RGB values provides you with more color options.Hexadecimal values are a combination of letters and numbers. The numbers go from 0 - 9 and the letters go from A to F. When using hexadecimal color values in your HTML/CSS, you preceed the value with a hash (#). Although hexadecimal values may look a little weird at first, you'll soon get used to them.
There are 16 color names (as specified in the HTML 4.0 specification). The chart below shows these color names and their corresponding hexadecimal value.
Color | Color Name | Hexadecimal Value | Color | Color Name | Hexadecimal Value | |
---|---|---|---|---|---|---|
Black | #000000 | Green | #008000 | |||
Silver | #c0c0c0 | Lime | #00ff00 | |||
Gray | #808080 | Olive | #808000 | |||
White | #ffffff | Yellow | #ffff00 | |||
Maroon | #800000 | Navy | #000080 | |||
Red | #ff0000 | Blue | #0000ff | |||
Purple | #800080 | Teal | #008080 | |||
Fushia | #ff00ff | Aqua | #00ffff |
You can make up your own colors by simply entering any six digit hexadecimal value (preceeded by a hash). In the following example, we're using the same code as above. The only difference is that, instead of using "blue" as the value, we're using its hexadecimal equivalent (which is #0000ff):
<h3 style="color:#0000ff">HTML Colors</h3>
HTML Colors
<h3 style="color:#000069">HTML Colors</h3>
HTML Colors
Choosing Colors - The Easy Way
By using hexadecimal or RGB color values, you have a choice of over 16 million different colors. You can start with 000000 and increment by one value all the way up to FFFFFF. Each different value represents a slightly different color.Links, otherwise known as hyperlinks, are defined using the
<a>
tag - otherwise known as the anchor element.To create a hyperlink, you use the a tag in conjunction with the href attribute (href stands for Hypertext Reference). The value of the href attribute is the URL, or, location of where the link is pointing to.
Example HTML Code:
Visit the <a href="http://www.graafix.blogspot.com/">Natural Environment Blog</a>
This results in:
Visit the Graafix.blogspot.com
Hypertext references can use absolute URLS, relative URLs, or root relative URLs.
- absolute
- This refers to a URL where the full path is provided. For example, http://www.worldwebdesigner.blogspot.com/html/tutorial/index.html
- relative
- This refers to a URL where only the path, relative to the current location, is provided. For example, if we want to reference the http://www.worldwebdesigner.blogspot.com/html/tutorial/index.html URL, and our current location is http://www.worldwebdesigner.blogspot.com/html, we would use tutorial/index.cfm
- root relative
- This refers to a URL where only the path, relative to the domain's root, is provided. For example, if we want to reference the http://www.worldwebdesigner.blogspot.com/html/tutorial/index.cfm URL, and the current location is http://www.worldwebdesigner.blogspot.com/html, we would use /html/tutorial/index.cfm. The forward slash indicates the domain's root. This way, no matter where your file is located, you can always use this method to determine the path, even if you don't know what the domain name will eventually be.
Link Targets
You can nominate whether to open the URL in a new window or the current window. You do this with thetarget
attribute. For example, target="_blank"
opens the URL in a new window.The target attribute can have the following possible values:
_blank | Opens the URL in a new browser window. |
_self | Loads the URL in the current browser window. |
_parent | Loads the URL into the parent frame (still within the current browser window). This is only applicable when using frames. |
_top | Loads the URL in the current browser window, but cancelling out any frames. Therefore, if frames were being used, they aren't any longer. |
Example HTML Code:
Visit the <a href="http://www.graafix.blogspot.com.com" target="_blank">Natural Environment</a>
This results in:
Visit the Graafix.blogspot.com
Named Anchors
You can make your links "jump" to other sections within the same page. You do this with named anchors.To use named anchors, you need to create two pieces of code - one for the hyperlink (this is what the user will click on), and one for the named anchor (this is where they will end up).
This page uses a named anchor. I did this by performing the steps below:
- I created the named anchor first (where the user will end up) Example HTML Code:
<h2>Link Targets<a name="link_targets"></a></h2>
- I then created the hyperlink (what the user will click on). This is done by linking to the name of the named anchor. You need to preceed the name with a hash (#) symbol. Example HTML Code:
<a href="#link_targets">Link Targets</a>
This results in:
When you click on the above link, this page should jump up to the "Link Targets" section (above). You can either use your back button, or scroll down the page to get back here.
You're back? Good, now lets move on to email links.
Email Links
You can create a hyperlink to an email address. To do this, use themailto
attribute in your anchor tag.Example HTML Code:
<a href="mailto:king_kong@example.com">Email King Kong</a>
This results in:
Clicking on this link should result in your default email client opening up with the email address already filled out.
You can go a step further than this. You can auto-complete the subject line for your users, and even the body of the email. You do this appending
subject
and body
parameters to the email address. Example HTML Code:
<a href="mailto:king_kong@example.com?subject=Question&body=Hey there">Email King Kong</a>
This results in:
Base href
You can specify a default URL for all links on the page to start with. You do this by placing thebase
tag (in conjunction with the href
attribute) in the document's head.Example HTML Code:
<head> <base url=http://www.worldwebdesigner.blogspot.com> </head>
Images make up a large part of the web - most websites contain images. HTML makes it very easy for you to embed images into your web page. To embed an image into a web page, the image first needs to exist in either .jpg, .gif, or .png format. You can create images in an image editor (such as Adobe Photoshop) and save them in the correct format. Once you've created an image, you need to embed it into your web page. To embed the image into your web page, use the<img />
tag, specifying the actual location of the image.Example of Image Usage
HTML Code:This results in:<img src="smile.gif" width="100" height="100" alt="Smile" />
Theimg
above contains a number of attributes. These attributes tell the browser all about the image and how to display it. Here's an explanation of these attributes:
src | Required attribute. This is the path to the image. It can be either an absolute path, or a relative path (remember these terms from our last lesson?) |
width | Optional attribute (but recommended). This specifies the width to display the image. If the actual image is wider, it will shrink to the dimensions you specify here. Likewise, if the actual image is smaller it will expand to your dimensions. I don't recommend specifying a different size for the image, as it will lose quality. It's better to make sure the image is the correct size to start with. |
height | Optional attribute (but recommended). This specifies the height to display the image. This attribute works similar to the width. |
alt | Alternate text. This specifies text to be used in case the browser/user agent can't render the image. |
Image Alignment
You can determine how your images will be aligned, relative to the other content on the page (such as a paragraph of text). You do this using thealign
attribute.
HTML Code:
<p> <img src="smile.gif" width="100" height="100" alt="Smile" align="right"/> Here is a paragraph of text to demonstrate HTML images and how they can be aligned to the right of a paragraph (or paragraphs) if you so desire.</p> </p>This can be used to produce some nice layout effects, especially if you have a lot of text, and it runs right past the image.</p><p> Otherwise, the image will just hang below the text and may look funny.</p>
This results in:
Here is a paragraph of text to demonstrate HTML images and how they can be aligned to the right of a paragraph (or paragraphs) if you so desire.
This can be used to produce some nice layout effects, especially if you have a lot of text, and it runs right past the image.
Otherwise, the image will just hang below the text and may look funny.
Image Links
You can make your images "clickable" so that when a user clicks the image, it opens another URL. You do this by simply wrapping the image with hyperlink code.
HTML Code:
<a href=http://www.worldwebdesigner.blogspot.com> <img src="smile.gif" width="100" height="100" alt="Smile" /> </a>
Removing the Border
You might notice that this has created a border around the image. This is default behaviour for most browsers. If you don't want the border, specifyborder="0"
.
HTML Code:
<a href=http://www.worldwebdesigner.blogspot.com> <img src="smile.gif" width="100" height="100" alt="Smile" border="0" /> </a>
Creating Images
The above examples assumed that you already had an image to embed into your web page. To learn about Meta tags allow you to provide metadata about your HTML pages. This can be very useful for search engines and can assist the "findability" of the information on your website.What is Metadata?
Metadata is information about, or that describes, other data or information. If we relate this to a web page, if you think about it for a moment, you could probably come up with a lot more information about a web page than what you're actually displaying to the reader. For example, there could be a number of keywords that are related to the page. You could probably give the page a description. The page also has an author - right? All these could be examples of metadata.Metadata on the Web
Metadata is a very important part of the web. It can assist search engines in finding the best match when a user performs a search. Search engines will often look at any metadata attached to a page - especially keywords - and rank it higher than another page with less relevant metadata, or with no metadata at all.Adding Meta Tags to Your Documents
You can add metadata to your web pages by placing<meta>
tags between the <head>
and </head>
tags. The can include the following attributes:
Attribute | Description |
---|---|
Name | Name for the property. Can be anything. Examples include, keywords, description, author, revised, generator etc. |
content | Specifies the property's value. |
scheme | Specifies a scheme to use to interpret the property's value (as declared in the content attribute). |
http-equiv | Used for http response message headers. For example http-equiv can be used to refresh the page or to set a cookie. Values include content-type, expires, refresh and set-cookie. |
Example HTML Code:
Keywords:
<meta name="keywords" content="HTML, meta tags, metadata" />
Description:
<meta name="description" content="Contains info about meta tags" />
Revision date (last time the document was updated):
<meta name="revised" content="Quackit, 6/12/2002" />
Refresh the page every 10 seconds:
The above examples are some of the more common uses for the meta tag.
Before we go any further, I'd like to introduce the concept of comments. Although comments are optional, they can assist you greatly.
Comments are a part of the HTML code and is used to explain the code. This can be helpful for other HTML coders when trying to interpret someone elses code. It can also be useful for yourself if you have to revisit your code in many months, or even years time. Comments aren't displayed in the browser - they are simply there for the programmer's benefit.
You write comments like this:
<meta http-equiv="refresh" content="10" />
<!-- Write your comment here -->
<!--
and end with -->
. This tells the browser when a comment begins and ends.
Example HTML Code:
<-- Display a happy image ---> <img src="smile.gif" width="100" height="100" alt="Smile" />
<<--Previous Next-->>
No comments:
Post a Comment