unit 1 HTML
unit 1 HTML
This topic focuses on the fundamental components of the web development framework
and then describes the components of the Node.js-to-Angular stack and discusses
various aspects of the general website/web application development framework from
users to backend services.
The main components of any given web framework are the user, browser, webserver,
In the following figure, components are described in a top-down manner from user
down to backend services.
User:
Users are a fundamental part of all websites; User expectations define the requirements for
developing a good website, and these expectations have changed a lot over the years.
The user role in a web framework is to sit on the visual output and interaction input of
webpages. That is, users view the results of the web framework processing and then
provide interactions using mouse clicks, keyboard input, and swipes and taps on mobile
devices.
Browser
The browser plays three roles in the web framework.
First, it provides communication to and from the webserver.
Second, it interprets the data from the server and renders it into the view that the user
actually sees.
Finally, the browser handles user interaction through the keyboard, mouse,
touchscreen, or other input device and takes the appropriate action.
POST: POST requests are used when sending data to the server, such as adding an item
to a shopping cart or submitting a web form.
AJAX: Asynchronous JavaScript and XML (AJAX) is actually just a GET or POST request
done directly by JavaScript running in the browser. Despite the name, an AJAX request
can receive XML, JSON, or raw data in the response.
The screen that the user actually views and interacts with is often made up of several
different pieces of data retrieved from the webserver.
The browser reads data from the initial URL and then renders the HTML document to
build a Document Object Model (DOM).
The DOM is a tree structure object with the HTML document as the root. The structure
of the tree basically matches the structure of the HTML document.
For example, the document will have html as a child, and html will have head and body
as children, and body may have div, p, or other elements as children, like this: document
+ html
+ head
+ body
+ div
+ p.
The browser interprets each DOM element and renders it to the user’s screen to build the
webpage view.
The browser often ends up getting various types of data from multiple webserver requests to
build the webpage.
The final view of the web page/web page behaviour is contains following content.
Webserver
The webserver’s main focus is handling requests from browsers.
the browser may request a document, post data, or perform an AJAX request to get a
data.
The webserver uses the HTTP headers as well as the URL to determine what action to
take.
Different responses things will be generated depending on the server, its
configurations and technologies.
Example: Apache and IIS, are made to serve static files such as .html, .css, and media
files.
To handle POST requests that modify server data and AJAX requests to interact with
backend services, webservers need to be extended with server-side scripts.
A server-side program is really anything that can be executed by the webserver to
perform the task the browser is requesting. These can be written in PHP, Python, C,
C++, C#, Java, … the list goes on and on. Webservers such as Apache and IIS provide
mechanisms to include server-side scripts and then wire them up to specific URL
locations requested by the browser.
The server-side scripts either generate the response directly by executing their code or
connect with other backend servers such as databases to obtain the necessary
information and then use that information to build and send the appropriateresponse.
Backend Services:
Backend services are services that run behind the webserver and provide data used to build
responses to the browser.
The most common type of backend service is a database that stores information.
When a request comes in from the browser that requires information from the database or
other backend service, the server-side script connects to the database, retrieves the
information, formats it, and then sends it back to the browser.
Conversely, when data comes in from a web request that needs to be stored in the database,
the server-side script connects to the database and updates the data.
Figure 1.2 provides a basic diagram of how the Node.js-to-Angular stack fits into the basic
website/web application model.
The following sections describe each of these technologies and why they were chosen as part of the
Node.js-to-Angular stack.
Figure 1.2 Basic diagram showing where Node.js, Express, MongoDB, and Angular fit in the web
paradigm
Node.js:
The following are just a few reasons why Node.js is a great framework to start from:
Features of Node.js:
JavaScript end-to-end: One of the biggest advantages to Node.js is that it allows you to write both
server- and client-side scripts in JavaScript. There have always been difficulties in deciding where to
put scripting logic. Too much on the client side makes the client cumbersome and unwieldy, but too
much on the server side slows down web applications and puts a heavy burden on the webserver.
With Node.js you can take JavaScript written on the client and easily adapt it for the server and vice
versa. Also, your client developers and server developers will be speaking the same language.
Event-driven scalability: Node.js applies a different logic to handling web requests. Rather
than having multiple threads waiting to process web requests, they are processed on the
same thread using a basic event model. This allows Node.js webservers to scale in ways that
traditional webservers never can.
Extensibility: Node.js has a great following and an active development community. New
modules to extend Node.js functionality are being developed all the time. Also it is simple to
install and include new modules in Node.js, making it easy to extend a Node.js project to
include new functionality in minutes.
Time: Let’s face it, time is valuable. Node.js is super easy to set up and develop in. In only a
few minutes, you can install Node.js and have a working webserver.
MongoDB:
MongoDB is an agile and scalable NoSQL database. The name Mongo comes from
“humongous.” It is based on the NoSQL document store model, meaning that data is stored
in the database as a form of JSON objects rather than the traditional columns and rows of a
relational database.
MongoDB provides great website backend storage for high traffic websites that need to
store data such as user comments, blogs, or other items because it is fast, scalable, and easy
to implement.
Node.js supports a variety of DB access drivers, so the data store could just as easily be
MySQL or some other database
The following are some of the reasons that MongoDB really fits in the Node.js stack well:
Express:
The Express module acts as the webserver in the Node.js-to-Angular stack. The fact that it is
running in Node.js makes it easy to configure, implement, and control.
The Express module extends Node.js to provide several key components for handling web
requests. This allows you to implement a running webserver in Node.js with only a few lines
of code.
For example, the Express module provides the ability to easily set up destination route
(URLs) for users to connect to. It also provides great functionality on working with the HTTP
request and response objects, including things like cookies and HTTP headers.
Route management: Express makes it easy to define routes (URL endpoints) that tie directly
to Node.js script functionality on the server.
Error handling: Express provides built-in error handling for documents not found and other
errors.
Easy integration: An Express server can easily be implemented behind an existing reverse
proxy system such as Nginx or Varnish. This allows it to be easily integrated into your existing
secured system.
Cookies: Express provides easy cookie management.
Session and cache management: Express also enables session management and cache
management.
Angular:
Data binding: Angular has a clean method to bind data to HTML elements using its powerful
scope mechanism.
Extensibility: The Angular architecture allows you to easily extend almost every aspect of
the language to provide your own custom implementations.
Clean: Angular forces you to write clean, logical code.
Reusable code: The combination of extensibility and clean code makes it easy to write
reusable code in Angular. In fact, the language often forces you to do so when creating
custom services.
Support: Google is investing a lot into this project, which gives it an advantage over other
similar initiatives.
Compatibility: Angular is based on TypeScript, which makes it easier to begin integrating
Angular into your environment and to reuse pieces of your existing code within the structure
of the Angular framework.
HTML Basics:
Headings, Paragraphs, Links, Images, Lists, Tables, Div
Element, Forms.
HTML:
HTML stands for Hypertext Markup Language. which is used for creating web pages and web
applications.
Understanding meaning of Hypertext, Markup Language, and Web page.
Hypertext refers to the way in which Web pages (HTML documents) are linked together. A
text has a link within it, is a hypertext. Whenever you click on a link, it will navigates you to
another web page(document). Thus, the link available on a webpage is called Hypertext.
HTML is a Markup Language which means you use HTML to simply "mark-up" a text
document with tags that tell a Web browser how to structure it to display.
A web page is a simple document displayable by a browser. Such documents are written in
the HTML language). A web page can embed a variety of different types of resources such
as:
empty elements: An element without content and has no ending tag is called “empty
element”.
For example, to insert a line break, use a single <br> tag, which represents the empty br
element, because it doesn’t enclose any content and thus has no corresponding close tag:
<br>
Empty element is added with “/ “after the element name.
<br/>
The start tag of an element might contain attributes that modify the meaning of the tag.
For example, in HTML, the simple inclusion of the noshade attribute in an <hr> tag, as
shown here: <hr noshade>
Under XHTML, such style attributes are not allowed, because all attributes must have a
value, so instead you have to use syntax like this:
<hr noshade="noshade" />
Values are always enclosed in either single or double quotes.
Multiple attributes:
<body> : Text between body tag describes the body content of the page that is visible to the
end user. This tag contains the main content of the HTML document.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Webpage </title>
</head>
<body>
<h1>This is my first web page </h1>
<h2> How it looks? </h2>
<p>It looks Nice!!!!! </p>
</body>
</html>
HTML Heading:
A HTML heading or HTML h tag can be defined as a title or a subtitle which you want to
display on the webpage. When you place the text within the heading tags <h1>.........</h1>,
it is displayed on the browser in the bold format and size of the text depends on the number
of heading.
There are six different HTML headings which are defined with the <h1> to <h6> tags, from
highest level h1 (main heading) to the least level h6 (least important heading ).
h1 is the largest heading tag and h6 is the smallest one. So h1 is used for most important
heading and h6 is used for least important.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Webpage </title>
</head>
<h1> Welcome to Computer Application </h1>
<h2> Welcome to Computer Application </h2>
<h3> Welcome to Computer Application </h3>
<h4> Welcome to Computer Application </h4>
<h5> Welcome to Computer Application </h5>
<h6> Welcome to Computer Application </h6>
</body>
</html>
Paragraphs:
paragraphs tags or <p> tags in HTML help us create paragraphs on a web page. On web
browsers, paragraphs display as blocks of text separated from adjacent blocks by blank lines,
white spaces, or first-line indentation.
You can use a <p> tag followed by the content you want to display in your paragraph and a
</p>. Whenever the web browser comes across a <p> tag, it starts its contents on a new
line.
HTML Paragraph Syntax:
<p>Paragraph Content</p>
Explanation:
<p>: Start tag for the paragraph.
Paragraph Content: The text will appear as a paragraph on a visitor’s screen.
</h1>: It is the closing tag for the paragraph.
HTML paragraphs help us in multiple ways, such as:
They make a web page more readable by giving it a structural view.
Paragraphs can consist of different types of related content, such as text, images,
forms, and more.
Here is a simple example in HTML to display different paragraphs on a web
page:
<!DOCTYPE html>
<html>
<head>
<title>Paragraph in HTML</title>
</head>
<body>
<p>
This is paragraph 1. This is paragraph 1. This is paragraph 1. This is paragraph 1. This
is paragraph 1. This is paragraph 1. This is paragraph 1. This is paragraph 1. This is
paragraph 1. This is paragraph 1.
</p>
<p>
This is paragraph 2.This is paragraph 2. This is paragraph 2.This is paragraph 2.This is
paragraph 2. This is paragraph 2.This is paragraph 2. This is paragraph 2. This is
paragraph
</p>
<p>
This is paragraph 3. This is paragraph 3. This is paragraph 3. This is paragraph 3. This
is paragraph 3. This is paragraph 3. This is paragraph 3. This is paragraph 3. This is
paragraph 3. This is paragraph 3. This is paragraph 3.
</p>
</body>
</html>
Links:
The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to
web pages, files, email addresses, locations in the same page, or anything else a URL can
address.( The <a> tag defines a hyperlink, which is used to link from one page to another).
The most imp>ortant attribute of the <a> element is the href attribute, which indicates the
link's destination.
By default, links will appear as follows in all browsers:
o An unvisited link is underlined and blue
o A visited link is underlined and purple
o An active link is underlined and red
.
Example: <a href="http://www.democompany.com/">External Link</a>.
Standard Syntax:
<a
Accesskey = "key"
Charset = "character code for language of linked resource"
Class = "class name(s)"
coords = "comma-separated list of numbers"
dir = "ltr | rtl"
href = "URL"
hreflang = "language code"
id = "unique alphanumeric identifier"
lang = "language code"
name = "name of target location"
rel = "comma-separated list of relationship values"
rev = "comma-separated list of relationship values"
shape="default | circle | poly | rect"
style="style information"
tabindex = "number"
target = "frame or window name | _blank | _parent | _self | _top"
title = "advisory text"
type="content type of linked data" >
</a>
ATTRIBUTS:
charset: This attribute defines the character encoding of the linked resource.
href : This is the single required attribute for anchors defining a hypertext source link. It indicates the
link target—either a URL or a URL fragment, which is a name preceded by a hash mark (#) specifying
an internal target location within the current document. URLs are not restricted to Web-based (http)
documents. URLs might use any protocol supported by the browser.
For example, file, ftp, and mailto work in most user agents.
hreflang :This attribute is used to indicate the language of the linked resource and should be set to
whichever language is specified in the core lang attribute.
Download: Specifies that the target will be downloaded when a user clicks on the hyperlink.
Target: Specifies where to open the linked document.
_blank, which indicates a new window.
_parent, which indicates the parent frame set containing the source link;
_self, which indicates the frame containing the source link.
_top, which indicates the full browser window.
download filename Specifies that the target will be downloaded when a user
clicks on the hyperlink
href URL Specifies the URL of the page the link goes to
referrerpolicy no-referrer Specifies which referrer information to send with the link
no-referrer-when-
downgrade
origin
origin-when-cross-
origin
same-origin
strict-origin-when-
cross-origin
unsafe-url
shape :This attribute is used to define a selectable region for hypertext source links associated with a
figure in order to create an image map. The values for the attribute are circle, default, polygon, and
rect.
The format of the coords attribute depends on the value of shape. For circle, the value is x,y,r,
where x and y are the pixel coordinates for the center of the circle and r is the radius value in pixels.
For rect, the coords attribute should be x,y,w,h. The x,y values define the upper-left corner of the
rectangle, while w and h define the width and height, respectively.
A value of polygon for shape requires x1,y1,x2,y2,… values for coords. Each of the x,y pairs defines a
point in the polygon, with successive points being joined by straight lines and the last point joined to
the first. The value of default for shape requires that the entire enclosed area, typically an image, be
used.
coords : For use with object shapes, this attribute uses a comma-separated list of numbers to define
the coordinates of the object on the page.
Examples:
<!-- anchor linking to external file -->
<a href="http://www.democompany.com/">External Link</a>
align: This attribute controls the horizontal alignment of the image with respect to the page. The
default value is left.
src : This attribute indicates the URL of an image file to be displayed. Most browsers will
display .gif, .jpeg, and .png files directly.
Alt: This attribute contains a string to be displayed instead of the image for browsers that cannot
display images.
Border: This attribute indicates the width, in pixels, of the border surrounding the image.
Dynsrc: In the Microsoft implementation, this attribute indicates the URL of a movie file and is used
instead of the src attribute. Common formats used here are .avi (Audio-Visual Interleaved), .mov
(QuickTime), and .mpg and .mpeg (Motion Picture Experts Group).
Ismap: This attribute indicates that the image is a server-side image map. User mouse actions over
the image are sent to the server for processing.
longdesc This attribute specifies the URL of a document that contains a long description of the
image. This attribute is used as a complement to the alt attribute.
loop In the Microsoft implementation, this attribute is used with the dynsrc attribute to cause a
movie to loop. Its value is either a numeric loop count or the keyword infinite.
lowsrc This nonstandard attribute, supported in most browsers, contains the URL of an image to be
initially loaded. Typically, the lowsrc image is a low-resolution or black-andwhite image that provides
a quick preview of the image to follow. Once the primary image is loaded, it replaces the lowsrc
image.
Name: This common attribute is used to bind a name to the image.
start : In the Microsoft implementation, this attribute is used with the dynsrc attribute to indicate
when a movie should play. The default value, if no value is specified, is to play the video as soon as it
has finished loading. Alternatively, a value of mouseover can be set to play the move once the user
has moved their mouse over the video.
usemap This attribute makes the image support client-side image mapping. Its argument is a URL
specifying the map file, which associates image regions with hyperlinks. The URL is generally a
fragment identifier that references a location in the current document rather than a remote
resource.
The HTML <map> tag defines an image map. An image map is an image with clickable areas. The
areas are defined with one or more <area> tags.
The Image
The image is inserted using the <img> tag. The only difference from other images is that you must
add a usemap attribute:
The usemap value starts with a hash tag # followed by the name of the image map, and is used to
create a relationship between the image and the image map.
The <map> element is used to create an image map, and is linked to the image by using the
required name attribute:
Shape="rect"
The coordinates for shape="rect" come in pairs, one for the x-axis and one for the y-axis.
So, the coordinates 34,44 is located 34 pixels from the left margin and 44 pixels from the top:
The coordinates 270,350 is located 270 pixels from the left margin and 350 pixels from the top:
Core Attributes:
The four core attributes that can be used on the majority of HTML elements (although not all)
are:
Id
Title
Class
Style
The Id Attribute
The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page.
There are two primary reasons that you might want to use an id attribute on an element:
Example
<p id="html">This para explains what is HTML</p>
<p id="css">This para explains what is Cascading Style Sheet</p>
The title Attribute
The title attribute gives a suggested title for the element. They syntax for the title attribute is similar
as explained for id attribute:
The behavior of this attribute will depend upon the element that carries it, although it is often
displayed as a tooltip when cursor comes over the element or while the element is loading.
Example:
<html>
<head>
<title>The title Attribute Example</title>
</head>
<body>
<h3 title="Hello HTML!">Titled Heading Tag Example</h3>
</body>
</html>
This will produce the following result:
Titled Heading Tag Example
Now try to bring your cursor over "Titled Heading Tag Example" and you will see that whatever title
you used in your code is coming out as a tooltip of the cursor.
The class attribute is used to associate an element with a style sheet, and specifies the class of
element. You will learn more about the use of the class attribute when you will learn Cascading Style
Sheet (CSS). So for now you can avoid it.
The value of the attribute may also be a space-separated list of class names.
For example:
class="className1 className2 className3"
The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.
<!DOCTYPE html>
<html>
<head>
<title>The style Attribute</title>
</head>
<body>
<p style="font-family:arial; color:#FF0000;">Some text...</p>
</body>
</html>
Some text...
Internationalization Attributes:
There are three internationalization attributes, which are available for most (although not all)
XHTML elements.
• dir
• lang
• xml:lang
The dir attribute allows you to indicate to the browser about the direction in which the text should
flow. The dir attribute can take one of two values, as you can see in the table that follows:
Value Meaning
rtl Right to left (for languages such as Hebrew or Arabic that are read right to left).
Example:
<!DOCTYPE html>
<html dir="rtl">
<head>
<title>Display Directions</title>
</head>
<body>
</body>
</html>
The lang attribute allows you to indicate the main language used in a document, but this attribute
was kept in HTML only for backwards compatibility with earlier versions of HTML. This attribute has
been replaced by the xml:lang attribute in new XHTML documents.
The values of the lang attribute are ISO-639 standard two-character language codes. Check
HTML Language Codes: ISO 639 for a complete list of language codes.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
</body>
</html>
Generic Attributes:
Here's a table of some other attributes that are readily usable with many of the HTML tags.
values element
element
Style Sheets.
Style Sheets.
width Numeric Value Specifies the width of tables, images, or
table cells.
table cells.
HTML LIST
The lists can be ordered or underdered depending on the requirement. In html we can create both
order and unorder lists by using <ol> and <ul> tags. There is one more list which is description list -
HTML <dl>, <dt> & <dd> tag are used to create description lists.
three ways for specifying lists of information namely ordered, unordered, and definition lists. All lists
must contain one or more list items. Items are marked by <li>.
HTML Unorder Lists
Unorder lists are marked with bullet points, by using html <ul> & <li> tag we can create a unorder
list. This is also know as unorder list.
<!DOCTYPE html>
<html>
<head>
<title>HTML List</title>
</head>
<body>
<h2>Example of HTML List</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>Java</li>
<li>JavaFX</li>
</ul>
</body>
</html>
Output:
By default, list items are preceded with bullet symbol. Using type attribute we can have other
symbols also such as disc, square.
<!DOCTYPE html>
<html>
<head>
<title>HTML List</title>
</head>
<body>
<h2>Example of HTML List</h2>
<ol>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>Java</li>
<li>JavaFX</li>
</ol>
</body>
</html>
Output:
Example of HTML List
1. HTML
2. CSS
3. JavaScript
4. Java
5. JavaFX
By default, list items are preceded with decimal number symbol. Using type attribute, we can
have other symbols also such as roman, alphabets.
<!DOCTYPE html>
<html>
<head>
<title>HTML List</title>
</head>
<body>
<h2>Example of HTML List</h2>
<dl>
<dt>HTML</dt>
<dd>HyperText markup languague</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheet</dd>
<dt>JS</dt>
<dd>JavaScript</dd>
</dl>
</body>
</html>
An HTML Table is an arrangement (structured set) of data in rows and columns in tabular
format. Tables are useful for various tasks, such as presenting text information and numerical
data.
<table> Defines the structure for organizing data in rows and columns within a web page.
<th> Shows a table header cell that typically holds titles or headings.
<thead> Defines the header section of a table, often containing column labels.
Represents the main content area of a table, separating it from the header or
<tbody>
footer.
<tfoot> Specifies the footer section of a table, typically holding summaries or totals.
Defines attributes for table columns that can be applied to multiple columns at
<col>
once.
Groups together a set of columns in a table to which you can apply formatting or
<colgroup>
properties collectively.
Defining Tables in HTML:
An HTML table is defined with the “table” tag. Each table row is defined with the “tr” tag. A table
header is defined with the “th” tag. By default, table headings are bold and centered. A table
data/cell is defined with the “td” tag.
Table Cells:
Table Cell are the building blocks for defining the Table. It is denoted with <td> as a start tag &
</td> as a end tag.
Syntax:
</td> Content...</td>
Table Rows:
The rows can be formed with the help of combination of Table Cells. It is denoted by <tr> and
</tr> tag as a start & end tags.
Syntax:
</tr> Content...</tr>
Table Headers
The Headers are generally use to provide the Heading. The Table Headers can also be used to add
the heading to the Table. This contains the <th> & </th> tags.
Syntax:
</th> Content...</th>
<body>
<table>
<tr>
<th>Book Name</th>
<th>Author Name</th>
<th>Genre</th>
</tr>
<tr>
<td>The Book Thief</td>
<td>Markus Zusak</td>
<td>Historical Fiction</td>
</tr>
<tr>
<td>The Cruel Prince</td>
<td>Holly Black</td>
<td>Fantasy</td>
</tr>
<tr>
<td>The Silent Patient</td>
<td> Alex Michaelides</td>
<td>Psychological Fiction</td>
</tr>
</table>
</body>
</html>
Attribute Description
accesskey Specifies a shortcut key to activate/focus an element
class Specifies one or more classnames for an element (refers to a class in a style sheet)
example:
<colgroup>
<col span="2" style="background-color: #D6EEEE">
</colgroup>
The <div> element is used as a container for other HTML elements.Defines a section in a document
(block-level)
The <div> element is by default a block element, meaning that it takes all available width, and comes
with line breaks before and after.
Example:
<div>
<h2>Motivation</h2>
<p>Your present circumstances don’t determine where you can go; they
merely determine where you start.</p>
<p>Start where you are. Use what you have. Do what you can</p>
</div>
<div> as a container:
The <div> element is often used to group sections of a web page together.
If you have a <div> element that is not 100% wide, and you want to center-align it, set the
CSS margin property to auto.
Example:
<style>
div {
width:300px;
margin:auto;
}
</style>
When building web pages, you often want to have two or more <div> elements side by side, like this:
There are different methods for aligning elements side by side, all include some CSS styling. We will
look at the most common methods:
The CSS float property was If you change The CSS Flexbox Layout
not originally meant to the <div> element's display propert Module was introduced to
align <div> elements side- y from block to inline-block, make it easier to design
by-side, but has been used the <div> elements will no longer flexible responsive layout
for this purpose for many add a line break before and after, structure without using float
years. and will be displayed side by side or positioning.
instead of on top of each other.
The CSS float property is To make the CSS flex
used for positioning and <style> method work, surround
formatting content and div { the <div> elements with
allow elements float next to width: 30%; another <div> element and
each other instead of on display: inline-block; give it the status as a flex
top of each other. } container.
</style>
Example Example
How to use float to align div How to use flex to align div
elements side by side: elements side by <style>
.mycontainer {
<style> display: flex;
.mycontainer { }
width:100%; .mycontainer > div {
overflow:auto; width:33%;
} }
.mycontainer div { </style> side:
width:33%;
float:left;
}
</style>
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it
easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each
row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and
give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
HTML Forms
An HTML form is used to collect user input. The user input is most often sent to a server for
processing.
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
The <form> element is a container for different types of input elements, such as: text fields,
checkboxes, radio buttons, submit buttons, etc.
The HTML <form> element can contain one or more of the following form elements:
<input>
<label>
<select>
<textarea>
<button>
<fieldset>
<legend>
<datalist>
<output>
<option>
<optgroup>
HTML Form Attributes:
The Action Attribute:
The action 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.
Example:
<form action="/login.js">
<label for="fname">First name:</label><br>
The target attribute specifies where to display the response that is received after submitting the
form.
Value Description
The method 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").
This example uses the GET method when submitting the form data:
Notes on GET:
Notes on POST:
Appends the form data inside the body of the HTTP request (the submitted form data is not
shown in the URL)
POST has no size limitations, and can be used to send large amounts of data.
Form submissions with POST cannot be bookmarked
The autocomplete attribute specifies whether a form should have autocomplete on or off.
When autocomplete is on, the browser automatically complete values based on values that the user
has entered before.
When present, it specifies that the form-data (input) should not be validated when submitted.
HTML FORM ELEMENTS
SYNTAX DESCRIPTION
<input type="text"> defines a single-line text input field
<input type="password"> defines a password field
defines a button for submitting form data to a form-handler.
The form-handler is typically a server page with a script for
<input type="submit">
processing input data. The form-handler is specified in the form's
action attribute.
defines a reset button that will reset all form values to their default
<input type="reset">
values
defines a radio button. Radio buttons let a user select ONLY ONE of a
<input type="radio">
limited number of choices
defines a checkbox. Checkboxes let a user select ZERO or MORE
<input type="checkbox">
options of a limited number of choices
<input type="button"> defines a button.
is used for input fields that should contain a colour.
<input type="color"> Depending on browser support, a color picker can show up in the
input field
is used for input fields that should contain a date.
Depending on browser support, a date picker can show up in the
<input type="date">
input field. You can also use the min and max attributes to add
restrictions to dates. EX: max="1979-12-31"
<input type="datetime-local"> specifies a date and time input field, with no time zone
<input type="email"> is used for input fields that should contain an e-mail address
defines an image as a submit button. The path to the image is
<input type="image"> specified in the src attribute. EX: <input type="image"
src="img_submit.gif" alt="Submit" width="48" height="48">
<input type="file"> defines a file-select field and a "Browse" button for file uploads.
<input type="hidden"> defines a hidden input field (not visible to a user)
<input type="month"> allows the user to select a month and year.
defines a numeric input field.
<input type="number"> EX: <input type="number" id="quantity" name="quantity" min="1"
max="5">
defines a control for entering a number whose exact value is not
<input type="range">
important (like a slider control). Default range is 0 to 100
<input type="search"> is used for search fields (a search field behaves like a regular text field
is used for input fields that should contain a telephone number.
<input type="tel"> EX:<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-
9]{2}-[0-9]{3}">
<input type="time"> allows the user to select a time (no time zone).
<input type="url"> is used for input fields that should contain a URL address.
<input type="week"> allows the user to select a week and year.
HTML Input Attributes:
different attributes for the HTML <input> element.
ATTRIBUTE DESCRIPTION
attribute specifies an initial value(default) for an input field.
value
Ex: <input type="text" id="fname" name="fname" value="John">
attribute specifies that an input field is read-only.A read-only input field
readonly cannot be modified.
Ex: <input type="text" id="fname" name="fname" value="John" readonly>
attribute specifies that an input field should be disabled.
disabled
Ex:<input type="text" id="fname" name="fname" value="John" disabled>
attribute specifies the visible width, in characters, of an input field.The
size default value for size is 20.
EX: <input type="text" id="fname" name="fname" size="50">
attribute specifies the maximum number of characters allowed in an input
maxlength
field. EX:<input type="text" id="pin" name="pin" maxlength="4" size="4">
attributes specify the minimum and maximum values for an input field.The
min and max min and max attributes work with the following input types: number, range,
date, datetime-local, month, time and week.
attribute specifies that the user is allowed to enter more than one value in an
multiple
input field. forinput types: email, and file
attribute specifies a regular expression that the input field's value is checked
against, when the form is submitted.pattern attribute works with the
pattern following input types: text, date, search, url, tel, email, and password.
Ex: <input type="text" id="country_code" name="country_code"
pattern="[A-Za-z]{3}" title="Three letter country code">
attribute specifies a short hint that describes the expected value of an input
field (a sample value or a short description of the expected format).
The short hint is displayed in the input field before the user enters a
placeholder value.The placeholder attribute works with the following input types: text,
search, url, number, tel, email, and password.
Ex: <input type="tel" id="phone" name="phone" placeholder="123-45-
678">
attribute specifies that an input field must be filled out before submitting the
form. The required attribute works with the following input types: text,
required search, url, tel, email, password, date pickers, number, checkbox, radio, and
file Ex: <input type="text" id="username" name="username" required>
attribute specifies the legal number intervals for an input field.
step Example: if step="3", legal numbers could be -3, 0, 3, 6, etc.
Ex:<input type="number" id="points" name="points" step="3">
attribute specifies that an input field should automatically get focus when
autofocus
the page loads. Ex:<input type="text" id="fname" name="fname" autofocus>
attributes specify the height and width of an <input type="image"> element.
height and
Ex:<input type="image" src="img_submit.gif" alt="Submit" width="48"
width
height="48">
list and element that contains pre-defined options for an <input> element.
<datalist>
attribute specifies whether a form or an input field should have
autocomplete
autocomplete on or off.
2. <label> Element:
The <label> element defines a label for several form elements.
The for attribute of the <label> tag should be equal to the id attribute of the <input> element to bind
them together.
3.<select> Element:
The <select> element defines a drop-down list. The <option> element defines an option that can be
selected. By default, the first item in the drop-down list is selected. To define a pre-selected option,
add the selected attribute to the option. Use the size attribute to specify the number of visible
values:
Use the multiple attribute to allow the user to select more than one value.
4. <textarea> Element:
The <textarea> 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.
5. <button> Element:
The <button> element defines a clickable button.