HTML | HTML 5 (Chapter - 4: Other HTML Elements)

Colors, Entities, Events, Music & Video Codes, Layouts

1. HTML Colors


Only 16 color names are recognized in valid HTML and CSS. The remaining colors are represented by a # sign plus 6 characters that make up a hexadecimal code.

Hexadecimal codes are formed from a combination of the primary colors: red, green and blue, or RGB. The first two digits of a hex code represent the amount of red in the color, the second two digits represent the amount of green in the color, and the third two digits represent the amount of blue in the color. The lowest value is 0 (hex 00) and the highest value is 255 (hex FF).

Hexadecimal codes can be complexing unless you study them in detail. There are approximately 16 million different colors that can be created from hexadecimal codes, only about fifteen-thousand of which will display correctly in the average browser. A standard of 256 "web safe" colors were developed years ago, and although many more colors are safe now for general use, the original 256 colors are still common.


HTML Color Names


Color Name HEX Color
Aqua #00FFFF  
Black #000000  
Blue #0000FF  
Fuchsia #FF00FF  
Gray #808080  
Green #008000  
Lime #00FF00  
Maroon #800000  
Navy #000080  
Olive #808000  
Purple #800080  
Red #FF0000  
Silver #C0C0C0  
Teal #008080  
White #FFFFFF  
Yellow #FFFF00  

216 Web Safe Colors


The following is a list of the 216 colors that were determined to be safe for use on the web (they appeared the same on all monitors). Any hexadecimal code that contains three sets of identical pairs, such as these 216 colors, can be abbreviated to 3 digits (example: #CC0000 = #C00).


#000000 #330000 #660000 #990000 #CC0000 #FF0000
#000033 #330033 #660033 #990033 #CC0033 #FF0033
#000066 #330066 #660066 #990066 #CC0066 #FF0066
#000099 #330099 #660099 #990099 #CC0099 #FF0099
#0000CC #3300CC #6600CC #9900CC #CC00CC #FF00CC
#0000FF #3300FF #6600FF #9900FF #CC00FF #FF00FF
#003300 #333300 #663300 #993300 #CC3300 #FF3300
#003333 #333333 #663333 #993333 #CC3333 #FF3333
#003366 #333366 #663366 #963366 #CC3366 #FF3366
#003399 #333399 #663399 #993399 #CC3399 #FF3399
#0033CC #3333CC #6633CC #9933CC #CC33CC #FF33CC
#0033FF #3333FF #6633FF #9933FF #CC33FF #FF33FF
#006600 #336600 #666600 #996600 #CC6600 #FF6600
#006633 #336633 #666633 #996633 #CC6633 #FF6633
#006666 #336666 #666666 #996666 #CC6666 #FF6666
#006699 #336699 #666699 #996699 #CC6699 #FF6699
#0066CC #3366CC #6666CC #9966CC #CC66CC #FF66CC
#0066FF #3366FF #6666FF #9966FF #CC66FF #FF66FF
#009900 #339900 #669900 #999900 #CC9900 #FF9900
#009933 #339933 #669933 #999933 #CC9933 #FF9933
#009966 #339966 #669966 #999966 #CC9966 #FF9966
#009999 #339999 #669999 #999999 #CC9999 #FF9999
#0099CC #3399CC #6699CC #9999CC #CC99CC #FF99CC
#0099FF #3399FF #6699FF #9999FF #CC99FF #FF99FF
#00CC00 #33CC00 #66CC00 #99CC00 #CCCC00 #FFCC00
#00CC33 #33CC33 #66CC33 #99CC33 #CCCC33 #FFCC33
#00CC66 #33CC66 #66CC66 #99CC66 #CCCC66 #FFCC66
#00CC99 #33CC99 #66CC99 #99CC99 #CCCC99 #FFCC99
#00CCCC #33CCCC #66CCCC #99CCCC #CCCCCC #FFCCCC
#00CCFF #33CCFF #66CCFF #99CCFF #CCCCFF #FFCCFF
#00FF00 #33FF00 #66FF00 #99FF00 #CCFF00 #FFFF00
#00FF33 #33FF33 #66FF33 #99FF33 #CCFF33 #FFFF33
#00FF66 #33FF66 #66FF66 #99FF66 #CCFF66 #FFFF66
#00FF99 #33FF99 #66FF99 #99FF99 #CCFF99 #FFFF99
#00FFCC #33FFCC #66FFCC #99FFCC #CCFFCC #FFFFCC
#00FFFF #33FFFF #66FFFF #99FFFF #CCFFFF #FFFFFF

Black, White & Shades of Grey


The following is a list of shades of grey between solid black and solid white.


HEX Color
#000000  
#080808  
#101010  
#181818  
#202020  
#282828  
#303030  
#383838  
#404040  
#484848  
#505050  
#585858  
#606060  
#686868  
#707070  
#787878  
#808080  
#888888  
#909090  
#989898  
#A0A0A0  
#A8A8A8  
#B0B0B0  
#B8B8B8  
#C0C0C0  
#C8C8C8  
#D0D0D0  
#D8D8D8  
#E0E0E0  
#E8E8E8  
#F0F0F0  
#F8F8F8  
#FFFFFF  

2. HTML Entities


So... if an HTML element, such as <html> </html> will be read by the browser and not shown on the webpage, how did I just get that element to show up on the webpage?!

There are five "reserved characters" in HTML. They are: " ' & < >. Despite being reserved for HTML, these characters can be made visible in a browser using HTML entities.

HTML entities represent symbols, or characters, such as those that you see on your keyboard, as well as many that are not included on your keyboard, such as the copyright © symbol. Each entity is identified by a short, unique code beginning with an ampersand & and ending with a semicolon ; with the entity name in between.

ASCII characters are the standard 128 characters used in languages and by computers and other devices, consisting of the numbers 0-9, the uppercase and lowercase English alphabet, and other standard English punctuations and characters. There are HTML entities for each ASCII character.

There are 256 HTML entities; we will only list some of them here. They can be displayed using their assigned name or a numerical code.


HTML Entities


Symbol Description Numerical Code Name Code
  space &#32; &nbsp;
! exclamation mark &#33;  
" quotation mark &#34; &quot;
# number sign &#35;  
$ dollar sign &#36;  
% percent sign &#37;  
& ampersand &#38;  
' apostrophe &#39;  
( left parenthesis &#40;  
) right parenthesis &#41;  
* asterisk &#42;  
+ plus sign &#43;  
, comma &#44;  
- hyphen &#45;  
. period &#46;  
/ slash &#47;  
0 digit 0 &#48;  
1 digit 1 &#49;  
2 digit 2 &#50;  
3 digit 3 &#51;  
4 digit 4 &#52;  
5 digit 5 &#53;  
6 digit 6 &#54;  
7 digit 7 &#55;  
8 digit 8 &#56;  
9 digit 9 &#57;  
: colon &#58;  
; semicolon &#59;  
< less-than &#60; &lt;
= equals-to &#61;  
> greater-than &#62; &gt;
? question mark &#63;  
@ at sign &#64;  
A uppercase A &#65;  
B uppercase B &#66;  
C uppercase C &#67;  
D uppercase D &#68;  
E uppercase E &#69;  
F uppercase F &#70;  
G uppercase G &#71;  
H uppercase H &#72;  
I uppercase I &#73;  
J uppercase J &#74;  
K uppercase K &#75;  
L uppercase L &#76;  
M uppercase M &#77;  
N uppercase N &#78;  
O uppercase O &#79;  
P uppercase P &#80;  
Q uppercase Q &#81;  
R uppercase R &#82;  
S uppercase S &#83;  
T uppercase T &#84;  
U uppercase U &#85;  
V uppercase V &#86;  
W uppercase W &#87;  
X uppercase X &#88;  
Y uppercase Y &#89;  
Z uppercase Z &#90;  
[ left square bracket &#91;  
\ backslash &#92;  
] right square bracket &#93;  
^ caret &#94;  
_ underscore &#95;  
` grave accent &#96;  
a lowercase a &#97;  
b lowercase b &#98;  
c lowercase c &#99;  
d lowercase d &#100;  
e lowercase e &#101;  
f lowercase f &#102;  
g lowercase g &#103;  
h lowercase h &#104;  
i lowercase i &#105;  
j lowercase j &#106;  
k lowercase k &#107;  
l lowercase l &#108;  
m lowercase m &#109;  
n lowercase n &#110;  
o lowercase o &#111;  
p lowercase p &#112;  
q lowercase q &#113;  
r lowercase r &#114;  
s lowercase s &#115;  
t lowercase t &#116;  
u lowercase u &#117;  
v lowercase v &#118;  
w lowercase w &#119;  
x lowercase x &#120;  
y lowercase y &#121;  
z lowercase z &#122;  
{ left curly brace &#123;  
| vertical bar &#124;  
} right curly brace &#125;  
~ tilde &#126; &sim;
¡ Inverted Exclamation &#161; &iexcl;
¢ Cent &#162; &cent;
£ English Pound &#163; &pound;
¤ Currency &#164; &curren;
¥ Yen &#165; &yen;
¦ Broken Vertical Bar &#166; &brvbar;
§ Section &#167; &sect;
¨ Double Dot &#168; &uml;
© Copyright &#169; &copy;
ª Feminine Ordinal Indicator &#170; &ordf;
« Left Angle Quotation Mark &#171; &laquo;
» Right Angle Quotation Mark &#187; &raquo;
¬ Negation &#172; &not;
® Registered Trademark &#174; &reg;
¯ Spacing Macron &#175; &macr;
° Degree(s) &#176; &deg;
± Plus or Minus &#177; &plusmn;
² Superscript 2 &#178; &sup2;
³ Superscript 3 &#179; &sup3;
´ Spacing Acute &#180; &acute;
µ Micro &#181; &micro;
Paragraph &#182; &para;
· Middle Dot &#183; &middot;
¸ Spacing Cedilla &#184; &cedil;
¹ Superscript 1 &#185; &sup1;
º Masculine Ordinal Indicator &#186; &ordm;
¼ � Fraction &#188; &frac14;
½ � Fraction &#189; &frac12;
¾ � Fraction &#190; &frac34;
¿ Inverted Question Mark &#191; &iquest;
À Grave Accent-Captial A &#192; &Agrave;
Á Acute Accent-Capital A &#193; &Aacute;
 Circumflex Accent-Capital A &#194; &Acirc;
à Tilde-Capital A &#195; &Atilde;
Ä Umlaut Mark-Capital A &#196; &Auml;
Å Ring-Capital A &#197; &Aring;
Æ Capital ae &#198; &AElig;
Ç Cedilla-Capital C &#199; &Ccedil;
È Grave Accent-Capital E &#200; &Egrave;
É Acute Accent-Capital E &#201; &Eacute;
Ê Circumflex Accent-Capital E &#202; &Ecirc;
Ë Umlaut Mark-Capital E &#203;  
Ì Grave Accent-Capital I &#204; &Igrave;
Í Acute Accent-Capital I &#205; &Iacute;
Î Circumflex Accent-Capital I &#206; &Icirc;
Ï Umlaut Mark-Capital I &#207; &Iuml;
Ð Capital eth &#208; &ETH;
Ñ Tilde-Capital N &#209; &Ntilde;
Ò Grave Accent-Capital O &#210; &Ograve;
Ó Acute Accent-Capital O &#211; &Oacute;
Ô Circumflex Accent-Capital O &#212; &Ocirc;
Õ Tilde-Capital O &#213; &Otilde;
Ö Umlaut Mark-Capital O &#214;  
× Multiplication &#215; &times;
Ø Slash-Capital O &#216; &Oslash;
Ù Grave Accent-Capital U &#217; &Ugrave;
Ú Acute Accent-Captital U &#218; &Uacute;
Û Circumflex Accent-Capital U &#219; &Ucirc;
Ü Umlaut Mark-Capital U &#220; &Uuml;
Ý Acute Accent-Capital Y &#221; &Yacute;
Þ Thorn &#222; &THORN;
ß Small Sharp &#223; &szlig;
æ Small ae &#230; &aelig;
ð Small eth &#240; &eth;
ø Slash-Small o &#248; &oslash;
þ Small Thorn &#254; &thorn;
ΠCapital Ligature &#338; &OElig;
œ Small Ligature &#339; &oelig;
ˆ Modifier Circumflex Accent &#710; &circ;
˜ Small Tilde &#732; &tilde;
En Dash &#8211; &ndash;
Em Dash &#8212; &mdash;
Left Single Quote &#8216; &lsquo;
Right Single Quote &#8217; &rsquo;
Single Low Quote &#8218; &sbquo;
Left Double Quote &#8220; &ldquo;
Right Double Quote &#8221; &rdquo;
Double Low Quote &#8222; &bdquo;
Dagger &#8224; &dagger;
Double Dagger &#8225; &Dagger;
Per Mile &#8240; &permil;
Left Single Arrow Quote &#8249; &lsaquo;
Right Single Arrow Quote &#8250; &rsaquo;
Euro Mark &#8364; &euro;
TradeMark &#8482; &trade;

3. HTML Events


Events are actions that take place in your browser, normally triggered by a visitor's use of the keyboard or mouse. Events are processed by a script, usually Javascript, that is written to perform a specific action when the event occurs. Most events require some knowledge of Javascript or the ability to copy and paste Javascript code that is offered freely on the web.

Events can be used to switch one image with another when your mouse hovers over it, or to validate forms when the submit button is pressed. The possibilities are endless... well, almost.

Let's take a look at the events available.


Window Events


Window events work inside of the body element.


Attribute Value When Is Event Triggered?
onload Script Event Happens (Script is Executed) When A Document Loads
onunload Script Event Happens (Script is Executed) When A Document Unloads

Keyboard Events


Keyword events work on of all of the basic HTML elements inside the body of the document.


Attribute Value When Is Event Triggered?
onkeyup Script Event Happens (Script is Executed) When A Key Is Released
onkeydown Script Event Happens (Script is Executed) When A Key Is Pressed
onkeypress Script Event Happens (Script is Executed) When A Key Is Pressed & Released

Mouse Events


Mouse events work on of all of the basic HTML elements inside the body of the document.


Attribute Value When Is Event Triggered?
onmouseover Script Event Happens (Script is Executed) When Mouse Pointer Is Moved Over An Element
onmouseout Script Event Happens (Script is Executed) When Mouse Pointer Is Moved Out of An Element
onclick Script Event Happens (Script is Executed) When Mouse Is Clicked
ondblclick Script Event Happens (Script is Executed) When Mouse Is Double-Clicked
onmouseup Script Event Happens (Script is Executed) When Mouse Button Is Released
onmousedown Script Event Happens (Script is Executed) When Mouse Button Is Pressed
onmousemove Script Event Happens (Script is Executed) When Mouse Button Is Moved

Form Events


Form events only work inside of form elements.


Attribute Value When Is Event Triggered?
onsubmit Script Event Happens (Script is Executed) When Form Is Submitted
onreset Script Event Happens (Script is Executed) When Form Is Reset
onselect Script Event Happens (Script is Executed) When Element Is Selected
onblur Script Event Happens (Script is Executed) When Element Loses Focus
onfocus Script Event Happens (Script is Executed) When Element Gets Focus
onchange Script Event Happens (Script is Executed) When Element Changes

Events in Action




If you resisted clicking on the button above, click on it anyway for an example of an event in action. Let's pick apart the code that made it possible.


<input type="button" value="Don't Click Here" onclick="alert('You just couldn\'t resist, could you?');">

You might not have learned much about forms yet. They are the elements of HTML that allow your visitors to interact with the website. The form button in this example includes the "onclick" attribute with a value of "alert('');", which is a Javascript function that pops up a little alert box with text in it.




Notice what happens when you move your mouse over the image, and then back off of it? The code to trigger these actions comes in two parts.


<script type="text/javascript">
    if (document.images) {
         image1 = new Image
        image2 = new Image
        image1.src = 'images/duck.gif'
        image2.src = 'images/snake.gif'
    }
</script>

<span onMouseOver="document.rollover.src=image2.src" onMouseOut="document.rollover.src=image1.src">
<img src="images/duck.gif" name="rollover">
</span>

Both the javascript code and the image and span tags can be placed between the HTML document's body tags. You can replace the image names and paths with your own images and be switching images like a pro in no time at all.

4. HTML Music Codes


HTML provides the <embed> tag as a method of embedding music in your HTML file. It is an empty element, meaning that it does not have a closing tag. The "src", or source attribute points to the location and name of the file that is to be embedded. The file types supported by this element are MIDI (.mid), MP3 (.mp3) and WAV (.wav).


<embed src="http://www.phpforkids.com/music/file-name.mp3" />

You can control the size and other display aspects of the player that is embedded in your webpage.


width="" Numeric Value Indicating the Width of the Player
height="" Numeric Value Indicating the Height of the Player
hidden="true" Hides the Play/Pause/Stop Controls
hidden="false" Shows the Play/Pause/Stop Controls

Several additional attributes are available.


autostart="true" Causes the Music to Play When Page Is Fully Loaded
autostart="false" Prevents the Music From Playing Until "Play" Is Pressed
loop="true" Loops/Repeats the Music Continuously
loop="false" Loops/Repeats the Music Once
volume="" Numeric Value (0-100) Controls the Starting Volume

Most visitors will not appreciate music being played on a webpage unless maybe they can immediately see a method of stopping it. Use this feature wisely (and sparingly)!

5. HTML Video Codes


HTML provides the <embed> tag as a method of embedding a video in your HTML file. It is an empty element, meaning that it does not have a closing tag.

The "src", or source attribute points to the location and name of the file that is to be embedded. The file types supported by this element are AVI (.avi), MOV (.mov), MPEG (.mpeg) and flash (.swf).


<embed src="http://www.phpforkids.com/videos/file-name.mp3" />

Several additional attributes are available.


autostart="true" Causes the Video to Play When Page Is Fully Loaded
autostart="false" Prevents the Video From Playing Until "Play" Is Pressed
hidden="true" Hides the Play/Pause/Stop Controls
hidden="false" Shows the Play/Pause/Stop Controls
loop="true" Loops/Repeats the Video Continuously
loop="false" Loops/Repeats the Video Once
playcount="5" Loops/Repeats the Video As Many Times As Indicated By Value
volume="" Numeric Value (0-100) Controls the Starting Volume

YouTube


YouTube make your job easier by providing a line of code for each video (as long as the owner of the video allows this feature) that you can copy and paste directly into your HTML document, without modifying, in order to embed a video on your webpage.

Now you can add as many cute little puppy and kitten videos to your site as you want!

6. HTML Layouts


Laying out your webpage is a process which should begin with a sheet of paper or a graphical computer program, as you decide what you want your website to look like, because the design itself can "make or break" a website all on its own.

Once you decide on a design, transferring it to HTML becomes the next step in the process. There are two main methods available to complete this next step: tables and CSS.

HTML tables have been used for years as the only layout method available, but CSS-based layouts are becoming increasingly popular as browser support for CSS has improved, causing many developers to consider table layouts antiquated. CSS layouts are said to load faster (by milliseconds), cut down on messy HTML code and be easier to maintain, however both options are supported by modern browsers.

Our example is a simple two-column layout with a header, a footer and a width of 100%, which expands and contracts according to the size of your screen:


Header
Navigation

Contents


Footer

This, and most other layouts, can be produced by either tables or CSS.


Table Layout


Our two-column layout with header and footer can be brought to life as a table using the following code:


<html>
<head>
     <title>An HTML Table Webpage Layout</title>
</head>
<body style="margin: 0; border: 0;">

     <table style="border: 0; width: 100%;">
    <tr> <td colspan="2" style="background: #006DA6;">Header</td> </tr>
    <tr>
        <td style="width: 25%; background: #658C00;">Navigation</td>
        <td style="width: 75%; background: #FFA100;"> <br /><br />Contents<br /><br /><br /> </td>
    </tr>
    <tr> <td colspan="2" style="background: #006DA6;">Footer</td> </tr>
    </table>

</body>
</html>

Background colors are added so that the results are visible, so copy and paste this code to your HTML file and try it out!


CSS Layout


Our two-column CSS layout with header and footer can be brought to life using the following code:


<html>
<head>
     <title>An HTML And CSS Webpage Layout</title>
</head>
<body style="margin: 0; border: 0;">

     <div style="width: 100%; background: #006DA6;">Header</div>

    <div style="float: left; width: 100%;">
        <div style="margin-left: 280px;">
            <div style="margin-top: 0; background: #FFA100;">
                <br /> <br /> Contents <br /> <br /> <br />
            </div>
        </div>
        </div>

        <div style="float: left; width: 280px; margin-left: -100%;">
            <div style="margin-top: 0; background: #658C00;">
                <br /> <br /> Navigation <br /> <br /> <br />
            </div>
        </div>

        <div style="width: 100%; background: #006DA6;">Footer</div>

</body>
</html>

Background colors are added so that the results are visible, so copy and paste this code to your HTML file and try it out!

Continue to Index

Welcome to HoneyBee - The Learning Platform

By Binit Patel

HoneyBee is a learning platform which is an integrated set of informative online services that enable learners involved in education with information, tools and resources to support and enhance Teaching, Learning and Management.

Contact With Me