"HTML TUTORIAL"
- They are a low-cost and easy way to spread information to a large audience.
- The provide yet another medium you can use to market your business!
- They serve as a platform to let the world know about you!
- Tag - Used to tag or "mark-up" pieces of text. Once tagged, the text becomes HTML code to be interpreted by a web browser. Tags look like this: <tag>
- Element - A complete tag, having an opening <tag> and a closing </tag>.
- Attribute - Used to modify the value of the HTML element. Elements will often have multiple attributes.
HTML - Elements
When you land on a website, all the items you see in front of you -- the paragraph texts, the page banners, and the navigation links are all elements of the web page. The term element is a just a name given to any piece of a web page. Many HTML elements are actually invisible to visitors and work quietly behind the scenes to provide web crawlers and search engines useful information about the site.An element consists of three essential pieces: an opening tag, the content, and a closing tag.
- <p> - opening paragraph tag
- Element Content - "Once upon a time..."
- </p> - closing tag
A Complete HTML Element:
<p>Once upon a time...</p>A single page can contain hundreds or thousands of elements, but when all is said and done, every HTML page should have a bare minimum of four critical elements: the HTML, head, title, and body elements.
HTML - <html> Element...</html>
<html> is the element that begins and ends each and every web page. Its sole purpose is to hold each web element nicely in position and serves the role of book cover; all other HTML elements are encapsulated within the <html> element. The tag also lets web browsers know, "Hey, I'm an HTML web page!", so that the browser knows how to render it. Remember to close your HTML documents with the corresponding </html> tag to signify the end of the HTML document.If you haven't already, it is time to open up Notepad, Notepad++, or Crimson Editor and have a new, blank document ready to go. Copy the following HTML code into your text editor.
HTML Element Code:
<html>
</html>Now save your file by selecting - Menu and then Save. Click on the Save as Type drop down box and select the option All Files. When you're asked to name your file, name it - index.html. Double-check that you did everything correctly and then press - Save. Now open your file in a new web browser so that you have the ability to refresh the page and see any new changes.
If you opened up your index.html document, you should be staring at your very first blank (white) web page!
HTML - <head> Element
The <head> is usually the first element contained inside the <html> element. While it is also an element container that encapsulates other HTML elements, these elements are not directly displayed by a web browser. Instead they function behind the scenes, providing more descriptive information about the HTML document, like its page title and other meta data. Other elements used for scripting (JavaScript) and formatting (CSS) are also contained within the <head> element, and we will eventually introduce how to utilize those languages. For now, the head element will continue to lay empty except for the title element, which will be introduced next.Here's a sample of the initial setup.
HTML Head Element Code:
<html>
<head>
</head>
</html>If you've made the code changes and refreshed the browser page, you will notice that we still have nothing happening on the page. So far, all we've done is add a couple of necessary elements that describe the web page document to the web browser. Content -- the stuff you can see -- will come next!
HTML - <title> Element
The <title> element adds a title to a web page. Web page titles are displayed at the top of any browser window or at the top of browser tabs. They are probably the first thing seen by web surfers as pages are loaded, and web pages you bookmark are saved using the web pages' titles.A proper title makes a good first impression, and any page caught without a title is considered unprofessional, at best.
HTML Title Element Code:
<html>
<head>
<title>My Web Page!</title>
</head>
</html>Save the file and refresh the browser. You should see "My Web Page!" in the upper-left bar of your browser window.
Name your webpage as you please. Just keep in mind that the best titles are brief and descriptive.
HTML - <body> Element
The element that encapsulates all the visual elements (paragraphs, pictures, tables, etc.) of a web page is the <body> element. We will be looking at each of these elements in greater detail as the tutorial progresses, but for now, it's only important to understand that the body element is one of the four critical web page elements, and it contains all of the page's viewable content.HTML Body Element Code:
<html>
<head>
<title>My Web Page!</title>
</head>
<body>
<p>Once upon a time...</p>
</body>
</html>Go ahead and view your first complete web page.
HTML - Elements Reviewed
To recap quickly: we've laid out a set of four essential elements that are used to create a strong foundation and structure for your web page. The <html> element encapsulates all page content and elements, including two special elements: the <head> and <body> elements. The <head> element is a smaller container for elements that work behind the scenes of web pages, while the <body> element houses content elements such as web forms, text, images, and web video.From here on out, the examples we provide will assume that you have a firm understanding of these key elements and know to place the majority of your HTML code inside of the <body> element.
HTML - Tags
A web browser reads an HTML document from top to bottom, left to right. Each time the browser finds a tag, the tag is rendered accordingly. Paragraph tags render paragraph text, image tags render images, etc. By adding tags to an HTML document, you are not only coding HTML, but also signaling to the browser, "Hey look, this is paragraph text; now treat it as such!"Do you recall that HTML elements are comprised of three major parts: the opening tag, the content, and the closing tag? As you will learn, there are infinite combinations of HTML tags/elements, including those used for forms, images, and lists. Everything displayed on an web page requires the use of a tag or two.
HTML Tag Code:
<tag>Content</tag>
<p>This text will be rendered like a paragraph.</p>Tags should always be written in lowercase letters if you plan on publishing the page online, as this is the web standard for XHTML and Dynamic HTML.
HTML More Tag Code:
<body>Body Tag
<p>Paragraph Tag</p>
<h2>Heading Tag</h2>
<b>Bold Tag</b>
<i>Italic Tag</i>
</body>
HTML - Elements Without Closing Tags
There are a few elements that do not require formal closing tags. In a way, they still have the 3 parts (opening/closing and content), but they are consolidated into one tag. The reason for this is that these tags do not really require any content to be placed within them, but sometimes may require attributes such as source URLs for images.One prime, easy example of an HTML tag that does not require a closing tag is the line break tag.
HTML Line Break Code:
<br />To tell the browser we want to place a line break (carriage return) onto the site, it is not necessary to type <br>linebreak</br>. This would require a tremendous amount of effort,and if every line break tag needed all three components as other tags do, life would become redundant real quick. The better solution is to combine the opening and closing tags into a single format and shorten the number of characters needed to render a line break. Other tags, such as image tags and input tags, have also been modified in such a manner.
HTML Code:
<img src="../mypic.jpg" /> -- Image Tag
<br /> -- Line Break Tag
<input type="text" size="12" /> -- Input Field
Display:
HTML - Text
Text is the backbone of any web page. It plays an double role; it provides content for web surfers to enjoy as they skim through articles and articles of information, but it also gives Search Engines and Spiders keywords and meta data. It is because of text on web pages that we have a network of seemingly endless information available at our fingers.HTML Text is probably the first element most HTML beginners learn to add to any web page, and this is generally achieved through a classic, "Hello, World!" example.
HTML Text Code:
<html>
<head>
<title>My Web Page!</title>
</head>
<body>
Hello World!
</body>
</html>
HTML - Paragraph Text
Any text containing more than a few lines (or sometimes even more) should exist inside of a paragraph tag <p>. This tag is reserved specifically for blocks of text, such as those you would expect to find inside your favorite novel.HTML <p> Tag Code:
<html>
<head>
<title>My Web Page!</title>
</head>
<body>
<p>Avoid losing floppy disks with important school...</p>
<p>For instance, let's say you had a HUGE school...</p>
</body>
</html>
HTML Paragraph Text:
Well written HTML documents can gain popularity through Search Engine Optimization and careful coding of your HTML elements.Precision is important when writing your code. Web spiders are a little forgiving when it comes to malformed HTML elements. For best results, do your best to ensure your code is complete and accurately constructed.
HTML - Headings 1:6
HTML has heading tags which can be used as headers or subheaders. By placing text inside of an <h1> heading tag, for example, the text displays bold and the size of the text increases to a 24pt font size. Heading tags are numbered 1 through 6, and they change size depending on which tag you choose, with 1 being the largest font size at 24pt, and 6 being the smallest font size at 8pt.HTML Heading Element:
<body>
<h1>Headings</h1>
<h2>are</h2>
<h3>great</h3>
<h4>for</h4>
<h5>titles</h5>
<h6>and subtitles</h6>
</body>Place these lines into your HTML file and you should see results similar to what you see below.
HTML Heading Tags:
Headings
are
great
for
titles
and subtitles
Notice that each heading has a line break (a blank line) rendered before and after it. This is a built-in attribute associated with the heading tag. Each time you place a heading tag, your web browser automatically places a line break in front of your beginning tag and after your ending tag, just like it does with <p> tags. This is expected behavior, and as a designer you need to take these line breaks into consideration when designing a layout. Later on, CSS code can be used to remove these extra line breaks or manipulate the amount of spacing, if needed.HTML - Formatting Text Elements w/ Tags
As you begin to place more and more text elements onto your website, you may find yourself wanting to incorporate bold or italic properties ing your text elements. HTML offers a handful of special tags that can be utilized to do just that:HTML Text Formatting Tags:
<p>An example of <b>Bold Text</b></p>
<p>An example of <em>Emphasized Text</em></p>
<p>An example of <strong>Strong Text</strong></p>
<p>An example of <i>Italic Text</i></p>
<p>An example of <sup>superscripted Text</sup></p>
<p>An example of <sub>subscripted Text</sub></p>
<p>An example of <del>struckthrough Text</del></p>
<p>An example of <code>Computer Code Text</code></p>
HTML Formatting Text:
An example of Emphasized Text
An example of Strong Text
An example of Italic Text
An example of superscripted Text
An example of subscripted Text
An example of
An example of
Computer Code Text
HTML - About Formatting Text Elements
Formatting elements such as <b> should be used sparingly, and what we mean by that is that you should only use them to bold or italicize one or two words at a time. If you wish to bold an entire paragraph, the better solution would involve Cascading Style Sheets (CSS) and adjust the element's font-weight property. You may consult how to do that in our CSS Tutorial. Ultimately, the decision is in the hands of the web designer, but generally, it's best to keep the use of these tags quick and sparse.HTML - Line Breaks
A line break is used in HTML text elements, and it is the equivalent of pressing Enter or Return on your keyboard. In short, a line break ends the line you are currently on and resumes on the next line. Earlier, we mentioned that each paragraph element begins and ends with a line break, which creates an empty space between the start of a paragraph element and the end of a paragraph element.As we've mentioned, line break elements are a little different from most of the tags we have seen so far because they do not require a closing tag. Instead, their opening and closing tags are combined into a single line break element. Placing <br /> within the code is the same as pressing the return key in a word processor. Use the <br /> tag within other elements such as paragraphs (<p>).
HTML Format Text:
<p>
Will Mateson<br />
Box 61<br />
Cleveland, Ohio<br />
</p>
Address:
Box 61
Cleveland, Ohio
HTML Text Format:
<p>Lovely,<br />
<br />
<br />
Arya place<br />
Director</p>
Closing Letter:
Arya place
Director
HTML - <pre> Preformatting
A web browser interprets your HTML document as being one long line. Sure, you may have tabs and line breaks in Notepad which align your content so it's easier for you to read, but your browser ignores those tabs and line breaks.We showed you that you can get around this problem by using the <br /> tag, but tabs and spacing are quite different from one another and can be absolutely annoying at times. One simpler solution might be to use the <pre> tag, which stands for previously formatted text.
Use the <pre> tag for any special circumstances where you wish to have the text appear exactly as it is typed. Spaces, tabs, and line breaks that exist in your actual code will be preserved with the <pre> tag.
HTML Pre Code:
<pre>
Roses are Red,
Violets are blue,
I may sound crazy,
But I love you!
</pre>
HTML Preformatted Text:
Roses are Red,
Violets are blue,
I may sound crazy,
But I love you!
HTML - Attributes
Web page customization begins with HTML attributes. Attributes are like blue print schematics informing the browser how to render an HTML element. As an HTML tag is processed, the web browser looks to these attributes as guides for the construction of web elements. Without any attribute values specified, the browser will render the element using the default setting(s) (usually very boring).HTML attributes are responsible for customizing web elements. As a web surfer, you've probably seen a vast assortment of color schemes, fonts, and styles -- all of which are brought to you by HTML and CSS element attributes.
HTML - Title Attribute
The title attribute titles an HTML element and adds a tiny text pop-up to any HTML element, offering your web viewers a tool-tip mechanism where information can be found or where a better description of an HTML element can be seen.Much like the tool tips found in word processing programs, this attribute can add spice to any page while offering the user priceless interactivity. As the mouse hovers over the element, a tool tip is displayed, giving the viewer just one extra piece of information.
HTML Title Attribute:
<h2 title="Hello There!">Titled Heading Tag</h2>
Hover your mouse over the display heading and watch the title
attribute in action!HTML Title Attribute:
Titled Heading Tag
The title attribute is one that has not deprecated and should be used often. Many search engines are capable of identifying this attribute inside your HTML elements, granting increased search rankings based on the relevance of the title attribute text.HTML - Align Attribute
If you wish to change the horizontal alignment of your elements, you may do so using the align attribute. It allows you to align things left, right, or center. By default, most elements are automatically aligned left, unless otherwise specified.HTML Align Attribute:
<h2 align="center">Centered Heading</h2>
HTML Align Attribute Display:
Centered Heading
HTML Align Attribute Code:
<h2 align="left">Left-aligned heading</h2>
<h2 align="center">Centered Heading</h2>
<h2 align="right">Right-aligned heading</h2>
HTML Align Attribute Display:
Left-aligned heading
Centered heading
Right-aligned heading
HTML attributes, including align, used to be the primary source for the customization of web elements, but they have now lost their market share to Cascading Style Sheets (CSS). Since most HTML attributes are now deprecated, they should ultimately be avoided in professional-level web design. Nonetheless, having an understanding of HTML attributes will prove to be a tremendous aid for anybody looking to move into professional web development using Cascading Style Sheets.If you would like to get started now with Cascading Style Sheets, please feel free to move along to our CSSTutorial.
HTML - Font
The <font> tag provides no real functionality by itself, but with the help of a few attributes, this tag is used to change the style, size, and color of HTML text elements. The size, color, and face attributes can be used all at once or individually, providing users with the ability to create dynamic font styles for any HTML element.Note: The <font> and <basefont> tags are deprecated and should not be used for published work. Instead, use CSS styles to manipulate your font. See our CSS Tutorial for more information.
HTML - Font Size
Set the size of your font with size. The range of accepted values goes from 1 -- the smallest, to 7 -- the largest. The default size of a font is 3.HTML Font Size Code:
<p>
<font size="5">Here is a size 5 font</font>
</p>
HTML Font Size Attribute:
HTML - Font Color
Set the color of your font with color.HTML Font Color Code:
<font color="#990000">This text is hex color #990000</font>
<br />
<font color="red">This text is red</font>
HTML Font Color Attribute:
This text is red
HTML - Font Face
Choose a different font face by specifying any font you have installed. Font face is synonymous with font type. As a web designer, be aware that if you specify a custom font type and users viewing the page don't have the exact same font installed, they will not be able to see it. Instead the chosen font will default to Times New Roman. To reduce the risk of running into this situation, you may provide a list of several fonts with the face attribute, such as outlined below.HTML Font Face Code:
<p>
<font face="Georgia, Arial, Garamond">This paragraph
has had its font...</font>
</p>
HTML Font Face Attribute:
HTML Font - Attribute Review
HTML Font Attributes:
Attribute=
|
"Value"
|
Description
|
size=
|
"Num. Value 1-7"
|
Size of your text, with 7 being biggest
|
color=
|
"rgb,name,or hexidecimal"
|
Font color
|
face=
|
"name of font"
|
Font type
|
Beautiful First Letter Style
Customize your fonts to achieve any desired look.HTML Code:
<p><font size="7" face="Georgia, Arial" color="maroon">C</font>ustomize
your font to achieve a desired look.</p>
Beauty & Grace:
HTML - Text Links (Anchors)
The World Wide Web got its spidery name from the plentiful connections (links) that link websites together with the click of a button. What most people don't know is that HTML links are actually HTML anchors constructed using anchor tags (<a>).HTML Text Link:
<a>I am a text link!</a>
HTML Text Link:
HTML - Hypertext Reference (href)
A Hypertext Reference (href) is an HTML attribute of an anchor (link) tag that requires a valid URL in order to properly direct a user to a different location. In other words, this Hypertext Reference is where users will navigate to if they do click on this link. Use the demonstration below as a reference.HTML Text Link Code:
<a href="http://www.tizag.com/" target="_blank">Tizag Home</a>
<br />
<a href="http://www.espn.com/" target="_blank">ESPN Home</a>
<br />
<a href="http://www.yahoo.com/" target="_blank">Yahoo Home</a>
HTML Text Links:
The address of a website is called a Uniform Resource Locator (a URL), and it acts like a street address for a website as a user is directed from one site to another. There are different types of URLs, and each has a slightly different look. The examples above link to what are known as Global URLs, since they are external web addresses that do not reside on the Tizag.com domain. Here's a look at the different types of URLs.HTML Text Link Code:
Global - href="http://www.cnn.com/" Links to other domains outside your website domain.
Local - href="../internal/mypage2.html" Links to other pages within your website domain.
Internal - href="#anchorname" Links to anchors embedded in the current web page.
HTML - Link Targets
The target attribute defines how each link will open when clicked. Will each one open in a new window, or will each one open in the current browser window? As the web designer, you call the shots as to how a user navigates from page to page, so long as you know how to handle the target attribute.Link Targets:
Target=
|
Description
|
_blank
|
Opens new page in a new
browser window
|
_self
|
Loads the new page in the
current window
|
_parent
|
Loads new page into a
parent frame
|
_top
|
Loads new page into the
current browser window, cancelling all frames
|
The code below shows how you would link to ESPN.com, a popular sports website. The target attribute is added to allow the browser to open ESPN in a new window, so that the viewer can have a window that remains opened to our website. Here's the example.
HTML Link Target Code:
<a href="http://www.ESPN.com" target="_blank">ESPN.COM</a>
_blank Target:
Links are a big part of the user experience for any website. Always try to keep that in mind when working on a site's navigation. A web page that opens a new web browser window each time a user clicks a link is not the greatest way to entice users to stick around.HTML - Email Links
Creating an email link is simple. If you want people to mail you about your site, a good way to do it is place an email link with a subject line already filled out for them.HTML Email Link Code:
<a href="mailto:email@tizag.com?subject=Feedback" >Email@tizag.com</a>
Email Links:
HTML Email Link Code:
<a href="mailto:email@tizag.com?subject=Feedback&body=Sweet site!">
Email@tizag.com</a>
Complete Email:
HTML - Download Links
Placing files available for download is done in exactly the same fashion as placing text links. However, things become complicated if we want to place image links for download. The best solution for images is to use a thumbnail links, which we will discuss in the next lesson.HTML Download Link Code:
<a href="http://www.tizag.com/pics/htmlT/blanktext.zip">Text Document</a>
Download a Text Document:
HTML - Default Links; Base
Use the <base> tag in the head element to set a default URL for all links on a page to go to. It's always a good idea to set a base tag just in case your links become bugged somewhere down the line. Usually, you should set your base to your home page.HTML Base Link Code:
<head>
<base href="http://www.tizag.com/" />
</head>
HTML - Comments
Comments are a great asset to new developers and a great way to place little notes to yourself reminding yourself what pieces of code are doing what. Comments are also great ways to troubleshoot bugs and code errors, as they give you the ability to comment out lines of code one at a time to search for the exact line causing problems.- Comment out elements temporarily rather than removing them, especially if they've been left unfinished.
- Write notes or reminders to yourself inside your actual HTML documents.
- Create notes for other scripting languages like JavaScript which requires them.
Comment Tags:
-- > Closing Comment Tag
HTML Comment Code:
<!--Note to self: This is my banner image! Don't forget -->
<img src="http://www.tizag.com/pics/tizagSugar.jpg" height="100" width="400" />
Comment to self:
Placing notes and reminders to yourself is a great way to remember your thoughts and to keep track of elements embedded inside the web page. Also, your code may exist for many, many years, and these notes to yourself are a great way to remember what was going on, since you may not remember five or more years down the road.All combinations of text placed within the comment tags will be ignored by the web browser. This includes any HTML tags, scripting language(s), etc.
HTML - <!-- Commenting Existing Code -->
As a web designer, you may sometimes have different websites in progress at once, and it might be easy to leave some HTML elements unfinished. In this case, you may comment out an element until it is 100% ready for the site. Below, we have commented out an input form element, since we are not quite ready to receive input from our users.HTML Code:
<!-- <input type="text" size="12" /> -- Input Field -->
Now when we are ready to show that element, we can simply remove the comment
tags, and our browser will readily display the element!HTML Code:
<input type="text" size="12" />
Input Field:
HTML - Lists
HTML lists appear in web browsers as bulleted lines of text. There are actually three different types of HTML lists, including unordered lists (bullets), ordered lists (numbers), and definition lists (think: dictionaries). Each list type utilizes its own unique list tag, which we'll demonstrate below.HTML List Item Code:
<body>
<ul>
<li>I am a list item!>
<li>I am a list item too!>
<li>I am a list item also!>
</ul>
</body>
HTML List Items:
- I am a list item!
- I am a list item too!
- I am a list item also!
HTML - Unordered Lists
An unordered list (<ul>) signifies to a web browser that all list items contained inside the <ul> tag should be rendered with a bullet preceding the text. The default bullet type for most web browsers is a full disc (black circle), but this can be adjusted using an HTML attribute called type.HTML Default Bullet List Code:
<h4 align="center">Shopping List</h4>
<ul>
<li>Milk</li>
<li>Toilet Paper</li>
<li>Cereal</li>
<li>Bread</li>
</ul>
HTML Default Disc Bullets:
Shopping List
- Milk
- Toilet Paper
- Cereal
- Bread
HTML Unordered List Type Code:
<ul type="square">
<ul type="disc">
<ul type="circle">
HTML Unordered List Types:
type="square"
|
type="disc"
|
type="circle"
|
|
|
|
HTML - Ordered Lists
An ordered list is defined using the <ol> tag, and list items placed inside of an ordered list are preceded with numbers instead of bullets.HTML Numbered/Ordered List:
<h4 align="center">Goals</h4>
<ol>
<li>Find a Job</li>
<li>Get Money</li>
<li>Move Out</li>
</ol>
HTML Numbered List:
Goals
- Find a Job
- Get Money
- Move Out
HTML Code:
<ol type="a">
<ol type="A">
<ol type="i">
<ol type="I">
Ordered List Types:
Lower-Case Letters
|
Upper-Case Letters
|
Lower-Case Numerals
|
Upper-Case Numerals
|
|
|
|
|
HTML Numbered List Start Attribute:
<h4 align="center">Goals</h4>
<ol start="4" >
<li>Buy Food</li>
<li>Enroll in College</li>
<li>Get a Degree</li>
</ol>
HTML Numbered List Start - 4:
Goals
- Buy Food
- Enroll in College
- Get a Degree
HTML - Definition Term Lists
HTML definition lists (<dl>) are list elements that have a unique array of tags and elements; the resulting listings are similar to those you'd see in a dictionary.- <dl> - opening clause that defines the start of the list
- <dt> - list item that defines the definition term
- <dd> - definition of the list item
HTML Definition List Code:
<dl>
<dt><b>Fromage</b></dt>
<dd>French word for cheese.</dd>
<dt><b>Voiture</b></dt>
<dd>French word for car.</dd>
</dt>
</dl>
HTML Definition List Display:
French word for cheese.
Voiture
French word for car.
HTML - Images & Pictures
Images are a staple of any web designer, so it is very important that you understand how to use them properly. In order to place an image onto a website, one needs to know where the image file is located within the file tree of the web server -- the URL (Unified Resource Locator).Use the <img /> tag to place an image on your webpage. Like the <br /> tag, <img /> tag does not require a formal ending tag. Instead, all we need to do to close this tag out with a slash (/) placed just inside the ending bracket (/>).
HTML Image Code:
<img src="http://www.tizag.com/pics/htmlT/sunset.gif" />
HTML Image:
So that you can follow along with us, we've provided a global URL of an image we have stored on Tizag's web server. If you have an active connection to the internet, you should be able to use the URL in the example to render this image on your own web page. If not, you will have to download (right click the image and Save As...on a PC, control-click and Save on a Mac). Once saved to your local computer, point the image src attribute to the recently downloaded image file. It might help to save the image file in the same folder as your web page.HTML - Image src Attribute
The source attribute (src) is what makes an image tag display an image. An image source is a URL value and should point to the directory location of an image file. Let's take one more look at the code from our first HTML image example.HTML Image Code:
<img src="http://www.tizag.com/pics/htmlT/sunset.gif" />An image source value is essentially the URL of a picture file and tells the web browser where the image is located so that it can then display the image correctly.
HTML - Source URLs
Image source URLs can be either local or global, meaning that the picture files you wish to display on your website can be either hosted locally on your machine (local) or hosted elsewhere on some other web site domain (global).- Global: http://www.tizag.com/pics/htmlT/sunset.gif
- Local: pics/sunset.gif
Local URLs Explained:
Local Src
|
Location Description
|
src="sunset.gif"
|
picture file resides in same directory as .html file
|
src="pics/sunset.gif"
|
picture file resides in the pics directory
|
src="../sunset.gif"
|
picture resides one folder "up" from the .html
file
|
src="../pics/sunset.gif"
|
picture file resides in the pics directory, one
folder "up" from the .html file.
|
Each URL format has its pros and cons. Using the URL of pictures on other sites poses a problem if the other site happens to change the physical location of the picture file. Copying the file directly to your web server solves this problem. However, as you continue to upload picture files to your system, you may eventually run short on hard drive space. Use your best judgment based upon your situation.
HTML - Image Height and Width Attributes
Height and width are HTML attributes that define an element's height and width properties. These values can either be percentage-based (%) or rely on pixel sizes.HTML Height and Width Attributes:
<img src="sunset.gif" height="50" width="100" />
HTML Height and Width (Pixels):
Above, we've used hard-coded pixel values for the height and width of the sunset image to ensure that this image will always render 50 pixels high by 100 pixels wide. By hard-coding these values, we are ensuring that the image will only display 50 pixels high by 100 pixels wide, even if the picture file itself happens to be much larger. If the dimensions of the picture are much larger, then we risk some severe skewing as the browser tries to shrink our image into our small box.Height and width values can also be a percentage. Percentage values are relative to the parent HTML element (usually the body), which means if you have a parent element like a <body> element that is the whole screen (1024x768), then an image with a height and width of 100% will take up that entire body element (1024x768). In our example below, we have placed the image in a table element that is about 400 pixels wide by 200 pixels tall.
HTML Height and Width Code:
<table height='200' width='400'>
<tr>
<td>
<img src="sunset.gif" height="100%" width="100%">
</td>
</tr>
</table>
0 comments:
Post a Comment