HTML Introduction

 


What is HTML?

  • HTML stands for Hyper text Markup language.

  • HTML is he standard markup language for creating web pages.

  • HTML describe the structure of a web page.

  • HTML consists of a series of elements .

  • HTML elements tell the browser how to display the content.

  • HTML elements label pieces of content such as “this is a heading”,”this is a paragraph”,”this is a ink” ,etc.


A simple HTML Document

The <!DOCTYPE html> Declaration define that this document is an HTM5 document.

The <html>element is the root element of an HTML page.

The <head>element contains meta information about the HTML page.

The <title>element specifies a title fro the HTML page (which is shown in the brewser’s title bar or in the page’s tab).

The <body>element define the document’s body,and is contain for all the visibe contents such as heading,paragraph,images,hyperlinks,tables,lists etc.

The <h1> elements defines a large heading.

The<p>elements defines a paragraph.

E.g:-


<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>Heading</h1>
<p>paragraph.</p>


</body>

</html>

What is an HTML Element?

An HTML elements is defined by a Tag ,Some Content and an End tag:

<tagname>Content here...</tagname>

The html Element is everything from the start tag to the end tag.

<h1> Heading</h1>

<p> paragraph</p>

Start tag

Element content

End tag

<h1>

Heading

</h1>

<title>

Title name(Bar )

</title>

<body>

Content

</body>

<p>

Paragraph

</p>

<br>

None

-





Learn HTML using Notepad or Text editor


Notepad++

Text edit(Atom)


HTML Documents

The HTML document itself begins with <html> and ends with </html>.

The visible part of the HTML document is between <body> and </body>.

Example 

<!DOCTYPE html>

<html>

<body>


<h1>My First Heading</h1>


<p>My first paragraph.</p>


</body>

</html>

Output:-

My First Heading

My first paragraph.


HTML Headings

HTML headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the least important heading:

Example 


<!DOCTYPE html>
<html>
<body>

<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>

</body>
</html>

Output:-

This is heading 1

This is heading 2

This is heading 3

This is heading 4

This is heading 5
This is heading 6

HTML Paragraphs

HTML paragraphs are defined with the <p> tag:

Example 
<!DOCTYPE html>
<html>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>
 
Output:-

This is a paragraph.

This is another paragraph.


HTML Images

HTML images are defined with the <img> tag.

The source file (src), alternative text (alt), width, and height are provided as attributes:


Example 

<!DOCTYPE html>

<html>

<body>


<h2>HTML Images</h2>

<p>HTML images are defined with the img tag:</p>


<img src="1.jpg" alt="kangaru" width="104" height="142">


</body>

</html>


 
Output:-

HTML Images

HTML images are defined with the img tag:



HTML Styles

The HTML style attribute is used to add styles to an element, such as color, font, size...

Example 

<!DOCTYPE html>
<html>
<body>

<p>I am normal</p>
<p style="color:red;">I am red</p>
<p style="color:blue;">I am blue</p>
<p style="font-size:50px;">I am big</p>

</body>
</html>

 
Output:-

I am normal

I am red

I am blue

I am big

Background Color

The CSS background-color property defines the background color for an HTML element.

Example 

<!DOCTYPE html>

<html>

<body style="background-color:powderblue;">


<h1>This is a heading</h1>

<p>This is a paragraph.</p>


</body>

</html>

Text Color

The CSS color property defines the text color for an HTML element:

Example 

<!DOCTYPE html>

<html>

<body>


<h1 style="color:blue;">This is a heading</h1>

<p style="color:red;">This is a paragraph.</p>


</body>

</html>

Fonts

The CSS font-family property defines the font to be used for an HTML element:

Example 

<!DOCTYPE html>

<html>

<body>


<h1 style="font-family:verdana;">This is a heading</h1>

<p style="font-family:courier;">This is a paragraph.</p>


</body>

</html>


Text Size

The CSS font-size property defines the text size for an HTML element:

Example 

<!DOCTYPE html>
<html>
<body>

<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>

</body>
</html>

Text Alignment

The CSS text-align property defines the horizontal text alignment for an HTML element:

Example 

<!DOCTYPE html>
<html>
<body>

<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>

</body>
</html>

HTML Text Formatting

Example 

<!DOCTYPE html>
<html>
<body>

<p><b>This text is bold</b></p>
<p><i>This text is italic</i></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>

</body>
</html>

HTML Formatting Elements

Formatting elements were designed to display special types of text:

  • <b> - Bold text
  • <strong> - Important text
  • <i> - Italic text
  • <em> - Emphasized text
  • <mark> - Marked text
  • <small> - Smaller text
  • <del> - Deleted text
  • <ins> - Inserted text
  • <sub> - Subscript text
  • <sup> - Superscript text

Example

<!DOCTYPE html>
<html>
<body>

<p>This text is normal.</p>

<p><b>This text is bold.</b></p>

</body>
</html>


HTML Colors

Color Names

Example

<!DOCTYPE html>

<html>

<body>


<h1 style="background-color:Tomato;">Tomato</h1>

<h1 style="background-color:Orange;">Orange</h1>

<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>

<h1 style="background-color:MediumSeaGreen;">MediumSeaGreen</h1>

<h1 style="background-color:Gray;">Gray</h1>

<h1 style="background-color:SlateBlue;">SlateBlue</h1>

<h1 style="background-color:Violet;">Violet</h1>

<h1 style="background-color:LightGray;">LightGray</h1>


</body>

</html>

Background Color

You can set the background color for HTML elements:

Example

<!DOCTYPE html>

<html>

<body>


<h1 style="background-color:DodgerBlue;">Hello World</h1>


<p style="background-color:Tomato;">

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

</p>


</body>

</html>


Text Color

You can set the color of text:

Example

<!DOCTYPE html>

<html>

<body>


<h3 style="color:Tomato;">Hello World</h3>


<p style="color:DodgerBlue;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>


<p style="color:MediumSeaGreen;">Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>


</body>

</html>

Border Color

You can set the color of borders:

Example

<!DOCTYPE html>

<html>

<body>


<h1 style="border: 2px solid Tomato;">Hello World</h1>


<h1 style="border: 2px solid DodgerBlue;">Hello World</h1>


<h1 style="border: 2px solid Violet;">Hello World</h1>


</body>

</html>

Color Values

Example

<!DOCTYPE html>
<html>
<body>

<p>Same as color name "Tomato":</p>

<h1 style="background-color:rgb(255, 99, 71);">rgb(255, 99, 71)</h1>
<h1 style="background-color:#ff6347;">#ff6347</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">hsl(9, 100%, 64%)</h1>

<p>Same as color name "Tomato", but 50% transparent:</p>
<h1 style="background-color:rgba(255, 99, 71, 0.5);">rgba(255, 99, 71, 0.5)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">hsla(9, 100%, 64%, 0.5)</h1>

<p>In addition to the predefined color names, colors can be specified using RGB, HEX, HSL, or even transparent colors using RGBA or HSLA color values.</p>

</body>
</html>

HTML Links - Hyperlinks

HTML links are hyperlinks.

You can click on a link and jump to another document.

When you move the mouse over a link, the mouse arrow will turn into a little hand.

HTML Links - Syntax

The HTML <a> tag defines a hyperlink. It has the following syntax:

<a href="url">link text</a>

Example

<!DOCTYPE html>

<html>

<body>


<h1>HTML Links</h1>


<p><a href="https://www.google.com/">Visit google.com!</a></p>


</body>

</html>

HTML Page Title

Every web page should have a page title to describe the meaning of the page.

Example

<!DOCTYPE html>
<html>
<head>
  <title>HTML Tutorial</title>
</head>
<body>

The content of the document......

</body>
</html>

HTML Tables

Example

<!DOCTYPE html>
<html>
<style>
table, th, td {
  border:1px solid black;
}
</style>
<body>

<h2>A basic HTML table</h2>

<table style="width:100%">
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
</table>

<p>To understand the example better, we have added borders to the table.</p>

</body>
</html>


Table Cells

Each table cell is defined by a <td> and a </td> tag.

Example

<!DOCTYPE html>

<html>

<style>

table, th, td {

  border:1px solid black;

}

</style>

<body>


<h2>TD elements define table cells</h2>


<table style="width:100%">

  <tr>

    <td>Emil</td>

    <td>Tobias</td>

    <td>Linus</td>

  </tr>

</table>


<p>To understand the example better, we have added borders to the table.</p>


</body>

</html>

Table Rows

Each table row starts with a <tr> and ends with a </tr> tag.

Example

<!DOCTYPE html>
<html>
<style>
table, th, td {
  border:1px solid black;
}
</style>
<body>

<h2>TR elements define table rows</h2>

<table style="width:100%">
  <tr>
    <td>Emil</td>
    <td>Tobias</td>
    <td>Linus</td>
  </tr>
  <tr>
    <td>16</td>
    <td>14</td>
    <td>10</td>
  </tr>
</table>

<p>To understand the example better, we have added borders to the table.</p>

</body>
</html>

Table Headers

Sometimes you want your cells to be table header cells. In those cases use the <th> tag instead of the <td> tag:

Example

<!DOCTYPE html>

<html>

<style>

table, th, td {

  border:1px solid black;

}

</style>

<body>


<h2>TH elements define table headers</h2>


<table style="width:100%">

  <tr>

    <th>Person 1</th>

    <th>Person 2</th>

    <th>Person 3</th>

  </tr>

  <tr>

    <td>Emil</td>

    <td>Tobias</td>

    <td>Linus</td>

  </tr>

  <tr>

    <td>16</td>

    <td>14</td>

    <td>10</td>

  </tr>

</table>


<p>To understand the example better, we have added borders to the table.</p>


</body>

</html>


HTML Table Borders

How To Add a Border

To add a border, use the CSS border property on tableth, and td elements:

   
   
   


Example

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>

<h2>Table With Border</h2>

<p>Use the CSS border property to add a border to the table.</p>

<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

</body>
</html>


Collapsed Table Borders

To avoid having double borders like in the example above, set the CSS border-collapse property to collapse.

This will make the borders collapse into a single border:

Example

 <!DOCTYPE html>

<html>

<head>

<style>

table, th, td {

  border: 1px solid black;

  border-collapse: collapse;

}

</style>

</head>

<body>


<h2>Collapsed Borders</h2>

<p>If you want the borders to collapse into one border, add the CSS border-collapse property.</p>


<table style="width:100%">

  <tr>

    <th>Firstname</th>

    <th>Lastname</th> 

    <th>Age</th>

  </tr>

  <tr>

    <td>Jill</td>

    <td>Smith</td>

    <td>50</td>

  </tr>

  <tr>

    <td>Eve</td>

    <td>Jackson</td>

    <td>94</td>

  </tr>

  <tr>

    <td>John</td>

    <td>Doe</td>

    <td>80</td>

  </tr>

</table>


</body>

</html>


Style Table Borders

If you set a background color of each cell, and give the border a white color (the same as the document background), you get the impression of an invisible border:

   
   
   


Example

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid white;
  border-collapse: collapse;
}
th, td {
  background-color: #96D4D4;
}
</style>
</head>
<body>

<h2>Table With Invisible Borders</h2>

<p>Style the table with white borders and a background color of the cells to make the impression of invisible borders.</p>

<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

</body>
</html>


Round Table Borders

With the border-radius property, the borders get rounded corners:

   
   
   

Example


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
  border-radius: 10px;
}
</style>
</head>
<body>

<h2>Table With Rounded Borders</h2>

<p>Use the CSS border-radius property to add rounded corners to the borders.</p>

<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

</body>
</html>

HTML Lists

<!DOCTYPE html>
<html>
<body>

<h2>An Unordered HTML List</h2>

<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>  

<h2>An Ordered HTML List</h2>

<ol>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol> 

</body>
</html>


HTML Description Lists


<!DOCTYPE html>
<html>
<body>

<h2>A Description List</h2>

<dl>
  <dt>Coffee</dt>
  <dd>- black hot drink</dd>
  <dt>Milk</dt>
  <dd>- white cold drink</dd>
</dl>

</body>
</html>

HTML List Tags

TagDescription
<ul>Defines an unordered list
<ol>Defines an ordered list
<li>Defines a list item
<dl>Defines a description list
<dt>Defines a term in a description list
<dd>Describes the term in a description list

Using The class Attribute

The class attribute is often used to point to a class name in a style sheet. It can also be used by a JavaScript to access and manipulate elements with the specific class name.

In the following example we have three <div> elements with a class attribute with the value of "city". All of the three <div> elements will be styled equally according to the .city style definition in the head section:

<!DOCTYPE html>

<html>

<head>

<style>

.city {

  background-color: tomato;

  color: white;

  border: 2px solid black;

  margin: 20px;

  padding: 20px;

}

</style>

</head>

<body>


<div class="city">

<h2>London</h2>

<p>London is the capital of England.</p>

</div> 


<div class="city">

<h2>Paris</h2>

<p>Paris is the capital of France.</p>

</div>


<div class="city">

<h2>Tokyo</h2>

<p>Tokyo is the capital of Japan.</p>

</div>


</body>

</html>




Iframe - Set Height and Width

Use the height and width attributes to specify the size of the iframe.

The height and width are specified in pixels by default:

Example 

<!DOCTYPE html>

<html>

<body>


<h2>HTML Iframes</h2>

<p>You can use the height and width attributes to specify the size of the iframe:</p>


<iframe src="demo_iframe.htm" height="200" width="300" title="Iframe Example"></iframe>


</body>

</html>


Iframe - Remove the Border

By default, an iframe has a border around it.

To remove the border, add the style attribute and use the CSS border property:

Example 

<!DOCTYPE html>

<html>

<body>


<h2>Remove the Iframe Border</h2>

<p>To remove the default border of the iframe, use CSS:</p>


<iframe src="demo_iframe.htm" style="border:none;" title="Iframe Example"></iframe>


</body>

</html>


HTML Layout Elements

HTML has several semantic elements that define the different parts of a web page:

  • header> - Defines a header for a document or a section
  • <nav> - Defines a set of navigation links
  • <section> - Defines a section in a document
  • <article> - Defines an independent, self-contained content
  • <aside> - Defines content aside from the content (like a sidebar)
  • <footer> - Defines a footer for a document or a section
  • <details> - Defines additional details that the user can open and close on demand
  • <summary> - Defines a heading for the <details> element you can read more about sematic element  in our html semantics chapter.






CSS Float Layout

Example



<html >
<head>
<title>CSS Template</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, Helvetica, sans-serif;
}

/* Style the header */
header {
  background-color: #666;
  padding: 30px;
  text-align: center;
  font-size: 35px;
  color: white;
}

/* Create two columns/boxes that floats next to each other */
nav {
  float: left;
  width: 30%;
  height: 300px; /* only for demonstration, should be removed */
  background: #ccc;
  padding: 20px;
}

/* Style the list inside the menu */
nav ul {
  list-style-type: none;
  padding: 0;
}

article {
  float: left;
  padding: 20px;
  width: 70%;
  background-color: #f1f1f1;
  height: 300px; /* only for demonstration, should be removed */
}

/* Clear floats after the columns */
section::after {
  content: "";
  display: table;
  clear: both;
}

/* Style the footer */
footer {
  background-color: #777;
  padding: 10px;
  text-align: center;
  color: white;
}

/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */
@media (max-width: 600px) {
  nav, article {
    width: 100%;
    height: auto;
  }
}
</style>
</head>
<body>

<h2>CSS Layout Float</h2>
<p>In this example, we have created a header, two columns/boxes and a footer. On smaller screens, the columns will stack on top of each other.</p>
<p>Resize the browser window to see the responsive effect (you will learn more about this in our next chapter - HTML Responsive.)</p>

<header>
  <h2>Cities</h2>
</header>

<section>
  <nav>
    <ul>
      <li><a href="#">London</a></li>
      <li><a href="#">Paris</a></li>
      <li><a href="#">Tokyo</a></li>
    </ul>
  </nav>
  
  <article>
    <h1>London</h1>
    <p>London is the capital city of England. It is the most populous city in the  United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
    <p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
  </article>
</section>

<footer>
  <p>Footer</p>
</footer>

</body>
</html>


HTML <input type="radio">

Example


<html>
<body>

<h1>Display Radio Buttons</h1>

<form action="/action_page.php">
  <p>Please select your favorite Web language:</p>
  <input type="radio" id="html" name="fav_language" value="HTML">
  <label for="html">HTML</label><br>
  <input type="radio" id="css" name="fav_language" value="CSS">
  <label for="css">CSS</label><br>
  <input type="radio" id="javascript" name="fav_language" value="JavaScript">
  <label for="javascript">JavaScript</label>

  <br>  

  <p>Please select your age:</p>
  <input type="radio" id="age1" name="age" value="30">
  <label for="age1">0 - 30</label><br>
  <input type="radio" id="age2" name="age" value="60">
  <label for="age2">31 - 60</label><br>  
  <input type="radio" id="age3" name="age" value="100">
  <label for="age3">61 - 100</label><br><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>


Text  Box

Example

<label for="Name">Name:</label>
<input type="text" id="Name" name="Name" placeholder="Jane Doe">


Example


<label for="Name">Name:</label>
<input type="text" id="Name" name="Name" minlength="2">



 Drop down Box

Example


<html>
<body>

<h1>The select element</h1>

<p>The select element is used to create a drop-down list.</p>

<form action="/action_page.php">
  <label for="cars">Choose a car:</label>
  <select name="cars" id="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
  </select>
  <br><br>
  <input type="submit" value="Submit">
</form>

<p>Click the "Submit" button and the form-data will be sent to a page on the 
server called "action_page.php".</p>

</body>
</html>

Input Date value Property

Example


<html>
<body>

Birthday: <input type="date" id="myDate">

<p>Click the button to set a date for the date field.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  document.getElementById("myDate").value = "2014-02-09";
}
</script>

</body>
</html>



HTML <input type="month">



Example


<html>
<body>

<h1>Display a Month Input Control</h1>

<p>If the browser supports it, a date picker pops up when entering the input field.</p>

<form action="/action_page.php">
  <label for="bdaymonth">Birthday (month and year):</label>
  <input type="month" id="bdaymonth" name="bdaymonth">
  <input type="submit">
</form>

</body>
</html>



HTML Styles - CSS

What is CSS?

Cascading Style Sheets (CSS) is used to format the layout of a webpage.

With CSS, you can control the color, font, the size of text, the spacing between elements, how elements are positioned and laid out, what background images or background colors are to be used, different displays for different devices and screen sizes, and much more!


Example

<html>
<head>
<style>
body {background-color: powderblue;}
h1   {color: blue;}
p    {color: red;}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>


CSS Colors, Fonts and Sizes

Here, we will demonstrate some commonly used CSS properties. You will learn more about them later.

The CSS color property defines the text color to be used.

The CSS font-family property defines the font to be used.

The CSS font-size property defines the text size to be used.

Example

<html>

<head>
<style>
h1 {
  color: blue;
  font-family: verdana;
  font-size: 300%;
}
{
  color: red;
  font-family: courier;
  font-size: 160%;
}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>



CSS Padding

The CSS padding property defines a padding (space) between the text and the border.

Example

<html>

<head>

<style>

p {

  border: 2px solid powderblue;

  padding: 30px;

}

</style>

</head>

<body>


<h1>This is a heading</h1>


<p>This is a paragraph.</p>

<p>This is a paragraph.</p>

<p>This is a paragraph.</p>


</body>

</html>



The <input> Element

The HTML <input> element is the most used form element.

An <input> element can be displayed in many ways, depending on the type attribute.

Here are some examples:

TypeDescription
<input type="text">Displays a single-line text input field
<input type="radio">Displays a radio button (for selecting one of many choices)
<input type="checkbox">Displays a checkbox (for selecting zero or more of many choices)
<input type="submit">Displays a submit button (for submitting the form)
<input type="button">Displays a clickable button

Example

<html>

<body>


<h2>Radio Buttons</h2>


<p>Choose your favorite Web language:</p>


<form>

  <input type="radio" id="html" name="fav_language" value="HTML">

  <label for="html">HTML</label><br>

  <input type="radio" id="css" name="fav_language" value="CSS">

  <label for="css">CSS</label><br>

  <input type="radio" id="javascript" name="fav_language" value="JavaScript">

  <label for="javascript">JavaScript</label>

</form> 


</body>

</html>


Checkboxes

The <input type="checkbox"> defines a checkbox.

Example

<html>

<body>


<h2>Checkboxes</h2>

<p>The <strong>input type="checkbox"</strong> defines a checkbox:</p>


<form action="/action_page.php">

  <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">

  <label for="vehicle1"> I have a bike</label><br>

  <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">

  <label for="vehicle2"> I have a car</label><br>

  <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">

  <label for="vehicle3"> I have a boat</label><br><br>

  <input type="submit" value="Submit">

</form> 


</body>

</html>

The Submit Button

The <input type="submit"> defines a button for submitting the form data to a form-handler.

Example

<html>

<body>


<h2>HTML Forms</h2>


<form action="/action_page.php">

  <label for="fname">First name:</label><br>

  <input type="text" id="fname" name="fname" value="John"><br>

  <label for="lname">Last name:</label><br>

  <input type="text" id="lname" name="lname" value="Doe"><br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

Display a Reset Button

<html>
<body>

<h1>Display a Reset Button</h1>

<p>Click on the reset button to reset the form.</p>

<form action="/action_page.php">
  <label for="email">Enter your email:</label>
  <input type="email" id="email" name="email"><br><br>

  <label for="pin">Enter a PIN:</label>
  <input type="text" id="pin" name="pin" maxlength="4"><br><br>  

  <input type="reset" value="Reset">
  <input type="submit" value="Submit">
</form>

</body>
</html>

The textarea form attribute

<html>
<body>

<h1>The textarea form attribute</h1>

<form action="/action_page.php" id="usrform">
  Name: <input type="text" name="usrname">
  <input type="submit">
</form>
<br>
<textarea rows="4" cols="50" name="comment" form="usrform">
Enter text here...</textarea>

<p>The text area above is outside the form element, but should still be a part of the form.</p>

</body>
</html>

HTML <input type="checkbox">

<html>
<body>

<h1>Show Checkboxes</h1>

<form action="/action_page.php">
  <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
  <label for="vehicle1"> I have a bike</label><br>
  <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
  <label for="vehicle2"> I have a car</label><br>
  <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
  <label for="vehicle3"> I have a boat</label><br><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>

Definition and Usage

The <input type="checkbox"> defines a checkbox.

The checkbox is shown as a square box that is ticked (checked) when activated.

Checkboxes are used to let a user select one or more options of a limited number of choices.

Tip: Always add the <label> tag for best accessibility practices!



Comments

Popular posts from this blog

ICTT Exam Past-paper Answers

Perform internet and electronic mail operations