HTML Forms: Input Elements
HTML Forms: Input Elements
HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. The <form> tag is used to create an HTML form: <form> . input elements . </form>
Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into: <form> First name: <input type="text" name="firstname" /><br /> Last name: <input type="text" name="lastname" /> </form> How the HTML code above looks in a browser: First name: Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Password Field
<input type="password" /> defines a password field: <form> Password: <input type="password" name="pwd" /> </form> How the HTML code above looks in a browser: Password: Note: The characters in a password field are masked (shown as asterisks or circles).
Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY ONE one of a limited number of choices: <form> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female </form> How the HTML code above looks in a browser: Male Female
Checkboxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or MORE options of a limited number of choices. <form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> <input type="checkbox" name="vehicle" value="Car" /> I have a car </form> How the HTML code above looks in a browser: I have a bike I have a car
Submit Button
<input type="submit" /> defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input: <form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> How the HTML code above looks in a browser: Username:
Submit
If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.
Color Values
HTML colors are defined using a hexadecimal notation (HEX) for the combination of Red, Green, and Blue color values (RGB). The lowest value that can be given to one of the light sources is 0 (in HEX: 00). The highest value is 255 (in HEX: FF). HEX values are specified as 3 pairs of two-digit numbers, starting with a # sign.
Color Values
Color Color HEX #000000 #FF0000 #00FF00 #0000FF #FFFF00 #00FFFF #FF00FF #C0C0C0 #FFFFFF Color RGB rgb(0,0,0) rgb(255,0,0) rgb(0,255,0) rgb(0,0,255) rgb(255,255,0) rgb(0,255,255) rgb(255,0,255) rgb(192,192,192) rgb(255,255,255)
CC6600 CC9900 CCCC00 CCFF00 FF0000 FF3300 FF6600 FF9900 FFCC00 FFFF00
CC6633 CC9933 CCCC33 CCFF33 FF0033 FF3333 FF6633 FF9933 FFCC33 FFFF33
CC6666 CC9966 CCCC66 CCFF66 FF0066 FF3366 FF6666 FF9966 FFCC66 FFFF66
CC6699 CC9999 CCCC99 CCFF99 FF0099 FF3399 FF6699 FF9999 FFCC99 FFFF99
CC66CC CC99CC CCCCCC CCFFCC FF00CC FF33CC FF66CC FF99CC FFCCCC FFFFCC
CC66FF CC99FF CCCCFF CCFFFF FF00FF FF33FF FF66FF FF99FF FFCCFF FFFFFF
</html>
Heading Elements
<h1>Largest Heading</h1>
<h2> . . . </h2> <h3> . . . </h3> <h4> . . . </h4> <h5> . . . </h5> <h6>Smallest Heading</h6>
Text Elements
<p>This is a paragraph</p> <br /> (line break) <hr /> (horizontal rule) <pre>This text is preformatted</pre> Logical Styles <em>This text is emphasized</em> <strong>This text is strong</strong> <code>This is some computer code</code> Physical Styles <b>This text is bold</b> <i>This text is italic</i>
Links
Ordinary link: <a href="http://www.example.com/">Link-text goes here</a> Image-link: <a href="http://www.example.com/"><img src="URL" alt="Alternate Text" /></a> Mailto link: <a href="mailto:[email protected]">Send e-mail</a>
A named anchor: <a name="tips">Tips Section</a> <a href="#tips">Jump to the Tips Section</a>
Unordered list
<ul> <li>Item</li> <li>Item</li> </ul>
Ordered list
<ol> <li>First item</li> <li>Second item</li> </ol>
Definition list
<dl> <dt>First term</dt>
Tables
<table border="1"> <tr> <th>Tableheader</th> <th>Tableheader</th> </tr> <tr> <td>sometext</td> <td>sometext</td> </tr> </table>
Frames
<frameset cols="25%,75%"> <frame src="page1.htm" /> <frame src="page2.htm" /> </frameset>
Forms
<form action="http://www.example.com/test.asp" method="post/get">
<input type="text" name="email" size="40" maxlength="50" /> <input type="password" /> <input type="checkbox" checked="checked" /> <input type="radio" checked="checked" /> <input type="submit" value="Send" /> <input type="reset" /> <input type="hidden" /> <select> <option>Apples</option> <option selected="selected">Bananas</option> <option>Cherries</option> </select>
Entities
< is the same as < > is the same as > © is the same as
Other Elements
<!-- This is a comment --> <blockquote> Text quoted from a source. </blockquote> <address> Written by W3Schools.com<br /> <a href="mailto:[email protected]">Email us</a><br /> Address: Box 564, Disneyland<br /> Phone: +12 34 56 78 </address>
This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> HTML 4.01 Transitional
This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> HTML 4.01 Frameset
This DTD is equal to HTML 4.01 Transitional, but allows the use of frameset content:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
Inline Styles
An inline style can be used if a unique style is to be applied to one single occurrence of an element. To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph: <p style="color:blue;margin-left:20px">This is a paragraph.</p> To learn more about style sheets, visit our CSS tutorial.
defines a title in the browser toolbar provides a title for the page when it is added to favorites displays a title for the page in search-engine results
A simple HTML document, with the minimum of required tags: <html> <head> <title>Title of the document</title> </head> <body> The content of the document...... </body> </html>
The <style> tag is used to define style information for an HTML document. Inside the style element you specify how HTML elements should render in a browser: <head> <style type="text/css"> body {background-color:yellow} p {color:blue} </style> </head>
Example
<script type="text/javascript"> document.write("Hello World!") </script>