Chapter 02-MARKUP LANGUAGE HTML and CSS
Chapter 02-MARKUP LANGUAGE HTML and CSS
2.1. INTRODUCTION
HTML (Hypertext Markup Language) is a fundamental language used for creating and structuring the content of
web pages. It forms the backbone of the World Wide Web, providing a standardized way to describe the structure
and presentation of information on the internet. HTML uses a set of markup tags to define elements within a
document, allowing browsers to interpret and display the content accordingly.
HTML offers a wide range of elements and attributes to structure and present content on the web. It also allows
you to create links, forms, tables, lists, and much more. We should also note that HTML is a markup language,
not a programming language, as it focuses on describing the structure and presentation of content rather than
performing calculations or operations.
In this chapter, we will help students to master the basics of the HTML because understanding HTML is essential
for anyone involved in web development, as it forms the foundation for building modern and engaging websites.
1
https://www.ietf.org/
1|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
version played a significant role in the popularization of the web and the growth
of the early web industry.
HTML 4.01 HTML 4.01, released in 1999, introduced even more features and improvements,
including support for frames, scripting languages like JavaScript, and cascading
style sheets (CSS). This version remained widely used for many years and formed
the foundation of many websites.
XHTML Extensible HyperText Markup Language (XHTML) was introduced in 2000 as a
reformulation of HTML 4.01 using the stricter rules of XML (eXtensible Markup
Language). XHTML aimed to bring the structure of XML to HTML, making it
more compatible with other XML-based technologies. XHTML 1.0 was a bridge
between HTML and XML, but its adoption was very limited.
HTML5 HTML5 is the latest major version of HTML, introduced in 2014. It is a significant
advancement that includes new semantic elements, multimedia support (video and
audio), canvas for graphics, local storage capabilities, and improved form
handling. HTML5 also supports mobile devices, making it suitable for creating
responsive and mobile-friendly websites.
HTML5 brought a shift in web development by reducing the reliance on browser
plugins, such as Adobe Flash, for multimedia content and introducing native
support for various media types.
Since its inception, HTML has evolved to meet the demands of an ever-changing web landscape. The latest
version, HTML5, continues to be widely used and serves as the foundation for building modern web applications
and websites. Figure 2.1 shows the key HTLM release years.
▪ Sublime text3: Sublime Text is a popular and versatile text editor used for coding and programming. It
is known for its speed, simplicity, and powerful features that enhance the coding experience. Sublime
Text is available for Windows, macOS, and Linux, making it accessible to developers on different
2
https://notepad-plus-plus.org/downloads/
3
https://www.sublimetext.com/
2|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
operating systems. Its combination of a clean interface, powerful features, and a vibrant community of
users and plugin developers has made it a preferred choice for many programmers.
Link for download: https://www.sublimetext.com/
The following steps describe how to create your first web page with Notepad++ or sublime.
To start a new HTML page, first create a new file in Sublime Text and save it with the .html extension. This will
set the syntax of your document to HTML. Then write or copy the following HTML code into sublime .
The HTML element is everything from the start tag to the end tag, as shown in the following examples:
3|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Note: It is worth to mention that some HTML elements have no content (like the <br> element). These elements
are called empty elements. Empty elements do not have an end tag. The table below shows the basic structure of
an HTML element.
▪ HEAD: The <head> element is a container for metadata (data about data) and is placed between the
<html> tag and the <body> tag. Metadata typically define the document title <title>, character set
<meta>, styles <style>, scripts <script>, and other meta information.
Data stored in the <head> tag is not displayed to the user; it is just written for reference purposes and as
a watermark of the owner.
4|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
▪ BODY: This contains everything you want to display on the Web Page. A body tag <body> is used to
enclose all the data which a web page has from texts to links. All the content that you see rendered in the
browser is contained within this element.
The example below shows the basic structure of a simple HTML Document.
</body>
</html> <!--end of the HTML document -->
Example Explained
▪ The <!DOCTYPE html> declaration defines that this document is an HTML5 document. All HTML
documents must start with a document type declaration. It must only appear once, at the top of the page
(before any HTML tags). This declaration represents the document type, and helps browsers to display
web pages correctly. In addition, it is not case sensitive.
▪ The <html> element is the root element of an HTML page. In fact, the HTML document itself begins
with <html> and ends with </html>.
▪ The <head> element contains meta information about the HTML page. In another word, it contains
machine-readable information (metadata) about the document, like its title, scripts, and style sheets. It is
always placed between the <html> tag and the <body> tag.
▪ The <title> element specifies a title for the HTML page (which is shown in the browser's title bar or
in the page's tab). The title must be text-only, and must be the precise description of a page's content.
▪ The <body> element defines the document's body, and is a container for all the visible contents, such as
headings, paragraphs, images, hyperlinks, tables, lists, etc. It must be the second element of the <html>
element and follows the head element.
▪ The <h1> element defines a large heading (titles or subtitles that you want to display on a webpage).
▪ The <p> element defines a paragraph. A paragraph always starts on a new line, and browsers
automatically add some white space (a margin) before and after a paragraph.
Note (HTML COMMENT TAG): HTML comments are not displayed in the browser, but they can help
document your HTML source code. You can add comments to your HTML source by using the following syntax:
Exercise: Write an HTML program to create a webpage to print your first name, last name, and city name in red
colour. The web page should have a green background. The <font> tag was used in HTML 4 to specify the font
face, font size, and colour of text.
5|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
<!DOCTYPE html>
<html lang="en">
<head>
<title>My First Page</title>
</head>
</body>
</html>
<!DOCTYPE html>
<html lang= "en">
<head>
<meta charset="UTF-8", http-equiv="content-type", content="text/html">
character set used
<meta name="description" content="Tutorials"> Description of the web page
<meta name="author" content="John Doe"> The author of a page
<meta name="keywords" content="HTML, CSS"> Keywords for search engines
<meta http-equiv="refresh" content="30"> Refresh document every 30 seconds
<title>My First Page</title>
</head>
<body>
<h1>This is an html document</h1>
</body>
</html>
Note: utf-8 has the advantage of being able to represent all the characters of Unicode in a manner
compatible with the old ASCII encoding.
2) HTML Headings: HTML headings are titles or subtitles that you want to display on a webpage. They
are defined with the <h1> to <h6> tags. <h1> defines the most important heading, while <h6> defines
the least important heading. Search engines use the headings to index the structure and content of your
web pages. Thus, it is important to use headings to show the document structure.
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
6|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Each HTML heading has a default size. However, you can specify the size for any heading with the
style attribute, using the CSS font-size property:
<h1 style="font-size:60px;">Heading 1</h1>
3) HTML paragraph: A paragraph always starts on a new line, and is usually a block of text. Browsers
automatically add some white space (a margin) before and after a paragraph. The HTML <p> element is
used to define a paragraph.
4) HTML Horizontal Rules: The <hr> tag defines a thematic break in an HTML page, and is most often
displayed as a horizontal rule. It is usually used to separate content (or define a change) in an HTML
page. The <hr> tag is an empty tag, which means that it has no end tag, as shown in the example bellow.
<!DOCTYPE html>
<html lang= "en">
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
</body>
</html>
5) HTML Line Breaks: The HTML <br> element defines a line break (a new line) without starting a new
paragraph. It is also an empty tag, which means that it has no end tag.
<!DOCTYPE html>
<html lang= "en">
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body bgcolor="yellowgreen" >
<p>This is<br>a paragraph<br>
with line breaks. </p>
</body>
</html>
6) HTML Formatting Elements: HTML contains several elements for defining text with a special
meaning. The most important are:
<b> - Bold text <small> - Smaller text
<strong> - Important text <del> - Deleted text
<i> - Italic text <ins> - Inserted text
7|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Examples:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body bgcolor="LightSalmon">
</body>
</html>
7) HTML Links: 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. The HTML <a> tag defines
a hyperlink. The example bellow shows how to create a link to www.google.com:
HTML links have some attributes that can be used for more features, as shown in the table below.
Attribute Description
target The target attribute specifies where to open the linked document. It can have one of
the following values:
▪ _self - Default. Opens the document in the same window/tab as it was
clicked
▪ _blank - Opens the document in a new window or tab
▪ _parent - Opens the document in the parent frame
▪ _top - Opens the document in the full body of the window.
8|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
href Indicates the link's destination. Clicking on the link text, will send the reader to
▪ URL address, <p><a href="www.google.com">CSS Tutorial</a></p>
▪ Document, <p><a href="courses.pdf">My courses</a></p>
▪ Email address, <a href="mailto:[email protected]">Send
email</a>
title This attribute specifies extra information about an element. The information is most
often shown as a tooltip text when the mouse moves over the element.
<a href="https://www.umc.com/html/" title="Go to google HTML
section">
Visit our HTML Tutorial
</a>
8) HTML Lists: HTML lists allow web developers to group a set of related items in lists.
▪ Unordered list starts with the <ul> tag. Each list item starts with the <li> tag. The list items will
be marked with bullets (small black circles) by default.
▪ Ordered HTML List starts with the <ol> tag. Each list item starts with the <li> tag. The list items
will be marked with numbers by default.
The example below shows the two types of html lists
<!DOCTYPE html>
<html>
<body bgcolor="gold">
</body>
</html>
9) HTML Images: Images can improve the design and the appearance of a web page. The HTML <img>
tag is used to embed an image in a web page. It is an empty tag, it contains attributes only, and does not
have a closing tag. It has two required attributes src and alt, and other optional attributes as shown in
the table below.
Attribute Description
9|Page
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Width, You can use the width and height attributes to specify the width and height of an image.
height <img src="girle.jpg" alt="Girl in a jacket" width="500" height="600"
Style You can also use the style attribute to specify the width and height of an image.
<img src="girle.jpg" alt="Girl in a
jacket" style="width:500px;height:600px;">
Note (Relative URL): it is a link to an image that is hosted within the website. Here, the URL does not
include the domain name.
▪ If the URL begins without a slash, it will be relative to the current page.
o Example: src="img_food.jpg"
▪ If the URL begins with a slash, it will be relative to the domain.
o Example: src="/images/img_food.jpg"
10) HTML colours: HTML colours are specified with predefined colour names (HTML supports 140
standard colour names), or with RGB, HEX, HSL, RGBA, or HSLA values.
All modern browsers support the following 140 colour names. The following figure shows the 140
colour names as background-colours along with their Hex code.
10 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Note 01: in HTML, colours can also be specified using RGB values. An RGB colour value is specified with:
rgb (red, green, blue). Each parameter (red, green, and blue) defines the intensity of the colour with a value
between 0 and 255.
▪ For example, rgb (255, 0, 0) is displayed as red, because red is set to its highest value (255), and the other
two (green and blue) are set to 0.
▪ To display black, set all colour parameters to 0, like this: rgb(0, 0, 0) and for the white colour, set all colour
parameters to 255, like this: rgb(255, 255, 255).
Note 02: hexadecimal colour is specified with: #rrggbb. Where rr (red), gg (green) and bb (blue) are hexadecimal
integers between 00 and ff, specifying the intensity of the colour.
▪ For example, #ff0000 is displayed as red, because red is set to its highest value (ff), and the other two
(green and blue) are set to 00.
▪ Another example, #00ff00 is displayed as green, because green is set to its highest value (ff), and the
other two (red and blue) are set to 00.
▪ To display black, set all colour parameters to 00, like this: #000000.
▪ To display white, set all colour parameters to ff, like this: #ffffff.
Example: in this example, the border is an attribute of <table> tag and it is used to put a border across all the
cells. If you do not need a border, then you can use border="0".
<!DOCTYPE html>
<html>
<body bgcolor="bisque">
<h3>This is a table </h3>
<table border = "1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
11 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body bgcolor="bisque">
2) HTML Table Colspan & Rowspan: HTML tables can have cells that span over multiple rows and/or
columns, as shown in the examples below:
To make a cell span over multiple rows, use the rowspan attribute. The value of this attribute represents
the number of rows to span, as shown in the examples below.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body bgcolor="bisque">
<h3>This is a table with merged cells </h3>
<table border = "1">
<tr>
<th>Name</th>
<td>Karim</td>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>(+213)77758962</td>
</tr>
<tr>
<td>(+213)78726053</td>
</tr>
</table>
</body>
</html>
12 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
To make a cell span over multiple columns, use the colspan attribute. The value of this attribute
represents the number of columns to span, as shown in the examples below.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body bgcolor="bisque">
<h3>This is a table with merged cells </h3>
<table border = "1">
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>Malik</td>
<td>Ali</td>
<td>44</td>
</tr>
<tr>
<td>Salim</td>
<td>Rida</td>
<td>57</td>
</tr>
</table>
</body>
</html>
Exercise: write a program to create an HTML table having the following output:
Solution:
<!DOCTYPE html>
<html lan="en">
<head>
<meta charset="UTF-8">
<title>My First Page</title>
</head>
<body>
<table style="border: 1px solid black" width="25%">
<tr bgcolor="lightblue"><th colspan="6">STUDENTS MARK SHEET</tr>
<tr bgcolor="gold">
<th>Name</th>
<th>Maths</th>
<th>Science</th>
<th>English</th>
</tr>
<tr bgcolor="lightgreen">
<td>Amine</td>
<td>85</td>
<td>87</td>
<td>88</td>
</tr>
<tr bgcolor="limegreen">
<td>Samia</td>
<td>33</td>
<td>96</td>
<td>58</td>
</tr>
</body>
</html>
13 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
14 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
▪ Selector: The first element in the rule is always the selector, it tells the browser which element or
elements of the web page will be styled.
▪ Declaration block: This block begins with the opening curly brace { and ends with the closing }, between
the curly braces are specified formatting commands (declarations), which are used by the browser to
stylize the selected selector element. You can specify as many declarations as you want in a block. The
declaration block itself is also called style.
▪ Declarations: Each declaration consists of two parts: the property and its value. The declaration must
always end with a semicolon (;). You can omit the “;” only at the end of the last declaration before the
closing curly brace.
▪ Properties: A property is a formatting command that defines a specific style effect for an element. The
property itself is a word or several words written through a hyphen. Each property has its own predefined
set of values. After the property name, a colon is specified, which separates the property name from the
valid value.
Example: the example below presents examples of CSS rules with some commonly used CSS properties.
<!DOCTYPE html>
<html>
<head>
<title>My Style</title>
<style>
body {
background-color: lightblue;
}
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
border: 2px solid gold;
padding: 30px;
margin: 50px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Explained example
▪ The CSS color property defines the text colour 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.
▪ The CSS border property defines a border around an HTML element.
▪ The CSS padding property defines a padding (space) between the text and the border.
▪ The CSS margin property defines a margin (space) outside the border.
15 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
▪ Inline CSS: You can apply inline styles directly to an HTML element using the "style" attribute. An
inline CSS is used to apply a unique style to a single HTML element. The following example sets the
text colour of the <h1> element to blue, and the text colour of the <p> element to red.
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
▪ Internal CSS: An internal CSS is used to define a style for a single HTML page. You can define styles
within the <style> tags in the <head> section of the HTML document.
The following example sets the text colour of ALL the <h1> elements (on that HTML page) to blue, and
the text colour of ALL the <p> elements to red. In addition, the page will be displayed with a
"powderblue" background colour:
<!DOCTYPE html>
<html>
<head>
<title>My Style</title>
<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>
▪ External CSS: An external style sheet is used to define the style for many HTML pages .You can link
an external CSS file to your HTML documents using the <link> tag in the <head> section of each
HTML page. In this case, the external style sheet can be written in any text editor. The file must not
contain any HTML code, and must be saved with a .css extension.
The HTML document The style file (styles.css)
<!DOCTYPE html>
<html> body {
<head> background-color: powderblue;
<link rel="stylesheet" href="styles.css"> }
</head>
<body> h1 {
color: blue;
}
<h1>This is a heading</h1>
<p>This is a paragraph.</p> p {
color: red;
</body> }
</html>
16 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
Element name Here, all <p> elements on the page will be center-aligned, with a red text colour:
selector p {
text-align: center;
color: red;
}
ID selector The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one
unique element. Here, The CSS rule below will be applied only to the HTML element
with id="para1":
#para1 {
text-align: center;
color: red;
}
Class selector The class selector selects HTML elements with a specific class attribute. To select
elements with a specific class, write a period (.) character, followed by the class name.
Here, all HTML elements with class="center" will be red and center-aligned.
.center {
text-align: center;
color: red;
}
You can also specify that only specific HTML elements should be affected by a class.
Here, only <p> elements with class="center" will be red and center-aligned:
p.center {
text-align: center;
color: red;
}
HTML elements can also refer to more than one class. Here, the <p> element will be
styled according to class="center" and to class="large":
<p class="center large">This paragraph refers to two classes.</p>
Universal The universal selector (*) selects all HTML elements on the page. Here, The CSS rule
Selector will affect every HTML element on the page:
* {
text-align: center;
color: blue;
}
Grouping The grouping selector selects all the HTML elements with the same style definitions.
Selector Here, the h1, h2, and p elements have the same style definitions:
h1, h2, p {
text-align: center;
color: red;
}
17 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
7) Add text inside the box and place it at the centre from both sides
Box 2 has similar properties of box 1 with some changes:
1) background colour blue
2) border colour yellow
Solution: The <div> tag defines a division or a section in an HTML document. It is used as a container for
HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled
by using the class or id attribute and any sort of content can be put inside it.
<!DOCTYPE html>
<html>
<head>
<style>
section {
display: flex;
flex-direction: column;
align-items: flex-end
}
▪ Inline frame element: The HTML <iframe> tag specifies an inline frame. An inline frame is used to
embed another document within the current HTML document.
Note: it is a good practice to always include a title attribute for the iframe element. This is used by screen
readers to read out what the content of the iframe is.
18 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
▪ Heigh and Width attributes: these attributes are used to specify the hight and width of the iframe. They
are specified in pixels by default.
▪ Remove the border: iframe has a border around it by default. To remove the border, you can use in the
attribute style, the property CSS border with the value none. With CSS, you can also change the size,
style and colour of the iframe’s border.
<iframe src="demo.html" height="200" width="300" title="iframe example"
style=="border:none;" >
</iframe>
Example of using frames: the first column is the main page entitled “frames.html” and the frame is linked to the
second webpage demo.html” in the second column.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>frames</title> <title>demo</title>
</head> <style>
<body bgcolor=“bisque”> body {background-color:
powderblue;}
<h1> This is the main html page </h1> h1{color: blue;}
</style>
<iframe src="demo.html" height="100"
width="300" title="iframe example" </head>
<body>
style=="border:none;" >
<h1> I am a Frame </h1>
</iframe>
</body>
</body> </html>
</html>
Iframe - Target for a Link: An iframe can be used as the target frame for a link. In this case, the target attribute
of the link must refer to the name attribute of the iframe.
Example:
19 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
The most important attributes for the HTML <form> element include:
▪ The Action Attribute: This attribute defines the action to be performed when the form is submitted.
Usually, the form data is sent to a file on the server when the user clicks on the submit button.
▪ The name Attribute: Specifies the name of the form.
▪ The Target Attribute: This attribute specifies where to display the response that is received after
submitting the form. It can have one of the following values:
o _blank: The response is displayed in a new window or tab.
o _self: The response is displayed in the current window
o _parent: The response is displayed in the parent frame
o _top: The response is displayed in the full body of the window
o Framename: The response is displayed in a named iframe
▪ The Method Attribute: This attribute specifies the HTTP method to be used when submitting the form
data. The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with
method="post"). The default HTTP method when submitting form data is GET. However, it is
recommended to do not use GET to send sensitive data because the submitted form data is visible in the
URL.
Example:
The HTML <form> element can contain one or more of the following form elements:
Element Description
<input> It is one of the most used form elements. element can be displayed in several ways,
depending on the type attribute, as shown in the table below:
Each input field must have a name attribute to be submitted.
<label> This element defines a label for several form elements. is useful for screen-reader
users, because the screen-reader will read out loud the label when the user focus on
the input element.
The for Attribute is used to specify the type of form element a label is bound to. It
contains the value of the id attribute of that element.
<select> This element defines a drop-down list. The <option> element defines an option that
can be selected in the <select> element.
By default, the first item in the drop-down list is selected.
The size attribute can be used to specify the number of visible values.
<textarea> This element defines a multi-line input field (a text area).
The rows attribute specifies the visible number of lines in a text area.
The cols attribute specifies the visible width of a text area.
<button> This element defines a clickable button
<fieldset>, The <fieldset> element is used to group related data in a form, while the <legend>
<legend> element defines a caption for the <fieldset> element.
<optgroup> This tag is used to group related options in a <select> element (drop-down list). The
label attribute specifies a label for an option-group.
Example: the following html code illustrates the usage of different elements in the form element.
<!DOCTYPE html>
<html lan="en">
<head>
<meta charset="UTF-8">
<title>My Form</title>
20 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
</head>
<body bgcolor="bisque">
<form name="myforme" action="/action_page.php" target="_blank" method="get">
<fieldset>
<legend>Personal:</legend>
<label for="fname">Full name:</label>
<input type="text" id="fname" name="fname">
</fieldset>
<fieldset>
<legend>My Car:</legend>
<label for="cars">Choose a car:</label>
<legend>My message:</legend>
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
</fieldset><br><br>
</body>
</html>
The following table shows the most important HTML Input Types
21 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
type="reset" Defines a reset button that will reset all form values to their default values
type="radio" Defines a radio button that let a user select ONLY ONE of a limited number of
choices
type="checkbox" Defines a checkbox to let a user select zero or more options of a limited number of
choices
type="button" Defines a button
type="color" This type is used for input fields that should contain a colour.
type="date" This type is used for input fields that should contain a date.
type="email" This type is used for input fields that should contain an e-mail address
type="image" Defines an image as a submit button
type="file" Defines a file-select field and a "Browse" button for file uploads
type="number" Defines a numeric input field. You can also set restrictions on what numbers are
accepted.
type="range" Defines a control for entering a number whose exact value is not important. Default
range is 0 to 100. However, you can set restrictions on what numbers are accepted
with the min, max, and step attributes.
type="search" This type is used for search fields (a search field behaves like a regular text field)
Example: the following html code illustrates the usage of different input Types.
Note: is actually one of the most frequently used HTML entities. Nbsp stands for non-breaking space,
meaning a space that will not break into a new line.
<!DOCTYPE html>
<html lan="en">
<head>
<meta charset="UTF-8">
<title>My Form</title>
</head>
22 | P a g e
CHAPTER 2: MARKUP LANGUAGE HTML & CSS
<body bgcolor="bisque">
<form name="myforme" action="/action_page.php" target="_blank" method="get">
<fieldset>
<legend> Search Google:</legend>
<input type="search" id="gsearch" name="gsearch" size="40">
</fieldset><br>
<fieldset>
<legend> Personal information:</legend>
<label for="fname">Full name: </label>
<input type="text" id="fname" name="fname"><br>
<label for="birthday">Birthday: </label>
<input type="date" id="birthday" name="birthday"><br>
<label for="email">Your email:</label>
<input type="email" id="email" name="email"><br>
<label for="pwd">Password: </label>
<input type="password" id="pwd" name="pwd"><br>
<label for="pwd">Your Bio: </label>
<input type="file" id="myfile" name="myfile">
<label for="tall">Your Tall (between 1.50 and 2 meters):</label>
<input type="number" id="tall" name="tall" min="1.50" max="2">
<label for="vol">Your age (between 10 and 80):</label>
<input type="range" id="age" name="age" min="10" max="80"><br><br>
<input type="image" src="img_submit.gif" alt="Submit" height="32">
</fieldset><br>
<fieldset>
<legend>Choose your favorite Web language:</legend>
<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>
</fieldset><br>
<fieldset>
<legend>What kind of vehicle you have?</legend>
<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>
</fieldset><br>
</body>
</html>
23 | P a g e