HTML pdf
HTML pdf
:::::::HTML::::::
HTML document is a text document saved with the extension .html or .htm that
contains texts and some tags written between "< >" which give the instructions
needed to configure the web page.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Remember to save the above file with the .html extension. The above code is
called the source code of a website..
All the keywords written between the angular brackets(< >) are different, tags
used for different purposes.
**<!DOCTYPE html> tells the browser that the file being displayed is HTML5 page.
doctype declaration is case insensitive.
**<html> meant to contain all the HTML data and is the start of an HTML
document.
:::HTML ELEMENTS:::
Elements are the things that make up the web page. Tags just
define the beginning and end of the elements. Everything that a web page
includes is an HTML element.
::br Tag::
Note : Some HTML elements have no content (like the <br> element). These
elements are called "empty elements". Empty elements do not have an end tag!.
::HTML document in Browser::
Coding Ninjas
A browser does not display the HTML tags but uses them to determine how to
display the document:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
By right-clicking on the web page and selecting the view page source option you
can view the HTML code of that web page.
**HTML codes are written in text editors, and then they are saved with .html or
.htm extension.
**Basic Code**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> MY WEB </title>
</head>
<body>
<h6>
Hello World!
</h6>
</body>
</html>
::Tags::
Tags define all elements of the document, i.e. they give meaning to the
plain text of HTML.
.. HTML tags are surrounded by the two characters < and > (They are called
"angle brackets")
'' The tag name can either start from an alphabet or an underscore( _ )
'' The text between the start and end tags is the element content.
'' Tags with an opening and closing can have any number of tags within
themselves
.. HTML tags are not case sensitive, <p> means the same as <P>
'' HTML tags normally comes in pairs("container tags"), i.e. both opening and
closing(it is the same, just the name of the tag with the character '/ ' in the
beginning) tag
NOTE : You might come across "self-closing" tags, whereby a br tag, for, e.g..,
will look like <br/> instead of simply <br>.
1. Comments in HTML:">
The comment tag <!-- --> is used to insert comments in the source code.
Comments are not displayed in the browsers.
You can use comments to explain your code, which can help you when you edit the
source code at a later date. This is especially useful if you have a lot of
code.
2. Paragraphs:">
Paragraphs are blocks of text separated from each other by some space.
They are defined using the <p> and </p> tags. When the p element ends, the next
element appears in the next line.
<head>
<title>p tag</title>
</head>
<body>
</body>
</html>
P tag
This is line 1.
This is line 2.
NOTE : When formatting without a p-tag, new lines are appended on the current
line. This happens because the spacing of text doesn’t matter to the browser.
3. Headings:">
<!DOCTYPE html>
<html>
<head>
<title>Heading Levels</title>
</head>
<body>
</body>
</html>
4. Line Breaks:">
There are multiple ways to provide line breaks or move the content to the
next line.
Writing the HTML code in the next line does not mean it will display the same in
the browser.
Example :
<p>
Hello world !
Welcome you all
to Coding Ninjas
</p>
Display on Browser : Hello world ! Welcome you all to Coding Ninjas
The <hr> tag defines a thematic break in an HTML page, and is often
displayed as a horizontal line.
The <hr> element is used to separate content (or define a change) in an HTML
page.
NOTE : The <hr> tag is an empty tag, which means that it has no end tag.
6.Break Tag:">
::IMAGES IN HTML::
Overview:"
You can also directly use the image address from the browser
The <a> tag defines a hyperlink, which is used to link from one page to
another.
..You must have seen that clicking on a link opens a new page may be on the
same page or another.
..These web pages are connected using links. They give us the ability to go to a
different web page without each time entering its URL. These kinds of links are
external links, i.e. they help in connecting to external web pages.
..Links can also be internal, which means that they will be linking the content
within the same page. E.g., link to the top of the page or any link to any
specific content on the page.
1. href Attribute:">
An anchor can point to any resource on the Web: an HTML page, an image, a sound
file, a movie, etc. These all are known as external links.
Ex::
<h2>Let's start Learning!</h2>
<p> Take daily challenges at
<a href = "http://www.codingninjas.in/students/assignments">Coding
Ninjas</a>
here Coding Ninjas will get clickable link on that .That will go to what you
have to seen..
NOTE : You need to remember that here also, we can provide the relative URL of a
file as a value to href attribute. Eg: href="/home/myPC/Documents/test.html".
Relative links works relative to the page. So, when a user clicks a relative
link, the browser looks for the location of the file relative to the current
page.
&.File is present in the same folder - In this case, the name of the file is
provided. Eg: <a href="relativeFile.html">Click Me</a> , will look for the file
inside the same folder.
&.File is present in the subfolder - In this case, the name of the file
provided is preceded with the folder names according to hierarchy.
&.File is present somewhere in the parent folder - In this case, to move one
folder above use '../'
&.File is present in another subfolder of the parent folder - This case covers
the above two cases.
Absolute links provide the complete web address of the web page where you want
to go.
3.target Attribute:">
With the target attribute, you can define where the linked document
will be opened.
.._self : load the URL into the current tab itself. This is the default.
.._parent : load the URL into the parent browsing context. If there is no
parent, this behaves the same as _self.
.._top : load the URL into the top-level browsing context. If there is no
parent, this behaves the same as _self.
The line below will open the document in a new browser window:
NOTE : By default, the linked page will be displayed in the current browser
window.
**Code**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anchor Tag</title>
</head>
<body>
<h1>Anchor Tag</h1>
<p>It has several attribute but the most important are following :
<ul>
<li><b>href</b> attribute used to define the resource path.</li>
</p>
</body>
</html>
Output::
Anchor Tag
The <a> tag is used to link a page with other page, by defining a hyperlink.
. target attribute used to specify where to open the linked page, means
within the same page or in a new tab. corresponding values are _self and _blank.
Coding Ninjas
TOPIC - 4:: Attributes in HTML::
:::Attributes in HTML:::
..In some rare situations, like when the attribute value itself contains quotes,
it is necessary to use single quotes: name='John "ShotGun" Nelson' and
vice-versa.
1.href Attribute:">
href attribute specifies the URL of the page, the link which we need to
provide in the anchor tag.
2.src Attribute:">
The <img> tag is used to embed an image in an HTML page. The src
attribute specifies the path to the image to be displayed:
The <img> tag contains the width and height attributes, which specifies
the width and height of the image (in pixels)
Example : <img src="path.jpg" width="500" height="600">
4.alt Attribute:">
alt attribute or alternate text tells the reader what they are
missing on a page if the browser can't load images. The browser will then
display the alternate text instead of the image.
5.style Attribute:">
::Styling in HTML::
.The property is a CSS property. The value is a CSS value. We will learn
about CSS later.
1. Text Color:">
The CSS colour property is used to set the text colour for an
HTML element.
EX: <h1 style = " color : red ; ">Welcome to Codig ninjas !</h1>
<p style = " color : green; "> Let's start Learning </p>
2. Text Size:">
The CSS font-size property is used to set the text size for an HTML
element.
..You can see in the above example both of the paragraphs have different text
sizes.
EX: <p style = " font-size : 30px;"> Welcome to Coding ninjas !</p>
<p style = " font-size : 100px;"> monospaceLet start Learning</p>
3. Fonts:">
The CSS font-family property is used to set the font to be used for an
HTML element.
Ex: <p style = " font-family : sans-serif ; "> Welcome to coding ninjas! </p>
<p style = " font-family : monospace ; "> Let start Learning </p>
4. Text Alignment:">
EX: <p style = "text-align : center ; "> Welcome to coding ninjas ! </p> # It
will display in center of the screen
<p style = "text-align : right; "> Let start Learning</p> # It will display
in right side of the screen.
5. Background Color:">
</body>
6.Multiple styles:">
We can also merge the above styles and set the properties for them, and
properties are separated by semicolons( ; ).
Ex: <p style = "text-align : center ; color : red "> Welcome to coding ninjas !
</p>
<p style = "text-align : center; color : green "> Let start Learning</p>
..In the above example, we merged text-align and colour property for a p-tag.
HTML provides us with the ability for formatting text just like we do
it in MS Word or any text editing software.
The following HTML tags are used to format the appearance of the text on your
web page.
This can jazz up the look of the web page. However, too much variety in the
text formatting can also look displeasing.HTML also defines special elements for
defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic
text.
TOPIC - 7 : Colors:::
:::Colours in HTML:::
1. Background Color:">
2. Text Color:">
The color property sets the colour of an element. It has the same
value as that of the colour property.
3. Border:">
You can make borders around an element which have some specific width,
type and colour. We will cover Borders later in the CSS module .
4. Colour Values:">
**By name:
All modern browsers support 140 different colours named in CSS. Unlike
HTML, CSS will completely ignore unknown keywords.
The color keywords all represent plain, solid colours, without transparency.
**Using rgb:
RGB stands for Red, Green and Blue. It is a colour model where a combination
of red,
green and blue forms a colour. The intensity of each colour has values ranging
from 0 to 255. This provides a very large number of colours dataset.
Example : the RGB value for black is: rgb(0, 0, 0) and for white is: rgb(255,
255, 255).
**Using hsl:
The colour can also be specified using the HSL (Hue, Saturation and
Lightness) components.
..Hue is a degree on the colour wheel from 0 to 360. 0 is red, 120 is green,
and 240 is blue.
**Using rgba:
RGBA (Red, Green, Blue, Alpha) is an extension of RGB, provided with alpha
transparency. This alpha value determines the opacity of the RGB defined colour.
The alpha parameter is a number between 0.0 (transparent) and 1.0 (opaque).
Ex: rgba(255, 0, 0, 0.6) is a red color, with 0.6 opacity will have the color.
**Using hsla:
Ex: hsla(0, 100%. 50%, 0.6) is also a red color with 0.6 opacity and have same
color.
TOPIC - 8 : Lists:::
:::Lists in HTML:::
1. Unordered Lists:">
. They are defined using the <ul> tag, and the <li> tag is used for each list
item.
**Code**
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
</ul>
</body>
</html>
output: Lists
. first item
. second item
. third item
HTML provides an interesting feature to change the style of the list item
marker.
There are 4 types of style in unordered lists:
NOTE : The above styles can be produced by using the type attribute. However,
this attribute is now not supported in HTML5, and you now need to change the
style using CSS(we will learn later about it).
2. Ordered Lists:">
They are defined using the <ol> tag, and the <li> tag is used for each list
item.
**Code**
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol>
</ol>
</body>
</html>
output: Lists
1. first item
2. second item
3. third item
Similarly, like the unordered lists, there are also different ways to number the
ordered lists using the type attribute.
i. type="i" - The list items will be numbered with lowercase roman numbers
NOTE : If you want to change the starting numbering of the list, then the start
attribute is used.
Output : Lists
7. first item
8. second item
9. third item
3.Description Lists:">
A definition list starts with the <dl> tag. Each definition - list term starts
with the <dt> tag. Each definition - list definition starts with the <dd> tag.
</dl>
Coffee
- black hot drink
Milk
- white cold drink
**Sample code**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>
Favourite Indian Music
</h1>
<ol start="2">
<li>Bengali folk Music</li>
<li>Gujarati folk music</li>
<li>Marathi folk music</li>
</ol>
<h1>
Favourite Indian Music composer
</h1>
<h1>
Favourite Hollywood Song
</h1>
</body>
</html>
V. A.R.Rahman
VI. Pritam
VII. Meet Bros
Block elements are those that take up the full width available on a web
page, effectively blocking out any other elements from sitting next to it on the
left or right.
Inline elements are those that only take up as much width as much needed to
display the contents of the element, thereby allowing other elements to be in
line with the inline element.
Examples of block elements are : <div>, <p>, <h1> to <h6>, <nav>, etc.
1. div tag::
The <div> element is very often used together with CSS to layout a web page. By
default, browsers always place a line break before and after the <div> element.
You can see in the above example that div made the statement take the complete
width of the web page and shifted the content to the next line.
<div>
Welcome to Coding Ninjas !
</div>
</p>
2. span tag::
. The <span> element has no required attributes, but style, class and id are
common.
. When used together with CSS, the <span> element can be used to style parts of
the text.
</span>
</p>
Here the output will be welcome to Coding Ninjas the background of that will be
in cyan color.
** span element does not shift the content to the next but helps to style a
specific part of the content.
1. Internal Styling ::
<html>
<head>
<style>
p{
color: red;
</head>
<body>
</body>
</html>
. In the above example, we applied the style to the p element using the internal
styling method.
2. Class Attribute ::
<html>
<head>
<style>
.course{
color: red;
background-color: cyan;
</style>
</head>
<body>
<div class="course">
Web Development
</div>
<div class="course">
Android Development
</div>
<div class="course">
</div>
</body>
</html>
. In the above example, we applied the style to the “course” class, which was
shared by three divs.
3. Multiple Classes ::
HTML elements can belong to more than one class, or you can say
multiple classes can be given to an element.
. Course and fees are the two classes which both are associated with the div
** In the following example, the first <div> element belongs to both the course
class and the strength class and will get the CSS styles from both classes.
<html>
<head>
<style>
.course{
color: red;
.strength{
background-color: cyan;
</style>
</head>
<body>
</body>
</html>
4. id Attribute ::
. You cannot have more than one element with the same id in an HTML document.
. JavaScript also uses it to access and manipulate the element with the specific
id.
Syntax : write a hash character (#), followed by an id name. Then, define the
CSS properties within curly braces { }.
EX: <head>
<style>
</style>
</head>
<body>
</body>
Output: This is id one!
This is id two!
This is id three!
This is id four!
5. Internal Links ::
You simply add a unique id value to an existing element using the id attribute.
Explanation: In the href attribute, the heading is the id of the heading of this
page. id of an HTML element is an attribute, and it can have any value. While
referring to an id, '#' is used at the beginning of its name.
. Clicking on the link shown below will scroll you to the heading such that it
is the first line of the display.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Data</title>
</head>
<body>
<h3 class="student">Hi students</h3>
</body>
</html>
Output: Hi students
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
Output: Hi students
To use JavaScript in your web page, you need to insert it into your HTML
page.
You can write your JavaScript code by using the <script> tag. You then
need to write JavaScript code in between them. This will also help in using the
same script in other web pages as well.
</script>
You can add a type attribute to mention the type of script you are using. But
since default scripts are written in JavaScript, you may not need to write it.
. <script> tag can be used in another manner as well. It can add external
JavaScript files to the web page.
**
Writing JavaScript code in external files separates it from HTML code. It makes
HTML and JavaScript easier to read and maintain.
**
Example : < script type = " text/javascript " src = " myScript.js "> </script>
. The JavaScript file name with the extension is mentioned inside the src
attribute, i.e. file name is myScript.js
. External scripts can be referenced with a full absolute URL or with a path
relative to the current web page.
You place scripts inside the <head> tag, just like the <link> tag. You
can use both of the ways mentioned above to add the script to the web page by
writing them inside the <head> tag like -
<head>
</head>
But you can also add script inside the <body> tag as well like -
<body>
...
<!-- HTML CODE -->
...
</body>
But when you use the above two methods, the JavaScript compilation is done
first, even before the HTML code is rendered on the web page. This slows down
the loading time of the web page, and also, some things might not be as expected
as elements are not rendered at that time.
To improve the web page’s loading time, we can also load and compile the
JavaScript after the page is loaded. To do this, we need to add the script at
the bottom of the <body> tag after the HTML code like -
<body>
…
<!-- HTML CODE -->
...
</body>
Now, the HTML code is rendered first, and then after that, the JavaScript is
loaded.
2. Internal JavaScript ::
Rather than making another JavaScript file and attaching it to the HTML
file, you could also write the JavaScript code within the HTML file as we did
for the CSS.
But this method is not recommended much. It could be done if there are some
lines of JavaScript code.
External JavaScript files help us to reuse them in multiple HTML files.
EX: <body>
<script type="text/javascript">
document.getElementById("heading").innerHTML = "ByeJavaScript";
</script>
</body>
The above JavaScript code changes the inner HTML content of the element, which
had an id heading associated with it.
3. <noscript> Tag ::
document.getElementById("heading").innerHTML = "ByeJavaScript";
</script>
**XHTML**
**HTML**
HTML is the Hypertext Markup Language which is the most widely used
language over the internet. HTML is used to create web pages and link them from
one to another. Please note HTML is not a programming language. It is a markup
language. We can use different other technologies like CSS and javaScript to
give a new look to the pages developed by HTML.
. <!DOCTYPE> is mandatory
The DOCTYPE in XHTML is different from HTML , it must have an XHTML <!DOCTYPE>
declaration.
The <html>, <head>, <title>, and <body> elements are mandatory , and the xmlns
attribute in <html> must specify the xml namespace for the document.
Example :
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of document</title>
</head>
<body>
</body>
</html>
2. XHTML Elements Must Always be Closed XHTML Empty Elements Must Always be
Closed
::Tables in HTML::
Tables are used to show the tabular data. To achieve this, many
tags are used. All the table data is enclosed within the <table> tags.
A table is divided into rows (with the <tr> tag), and each row is
divided into data cells (with the <td> tag). tr stands for table row, which
represents the row of a table, and td stands for table-data, which is the
content of a data cell.
A data cell can contain text, images, lists, paragraphs, forms, horizontal
rules, tables etc.
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
:: border Attribute ::
** Headings in a Table ::
If you want to add column names, then HTML provides a separate tag for
that. Headings in a table are defined with the <th> tag.
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table>
>> <tbody> tag is used to group the body content in an HTML table.
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
<tfoot>
<tr>
</tr>
</tfooft>
</table>
Output: || Column 1 || Column 2 || Column 3 ||
|| Row 1, cell 1 || Row 1, cell 2 || Row 1, cell 3 ||
|| Row 2, cell 1 || Row 2, cell 2 || Row 2, cell 3 ||
|| Row 3, cell 1 || Row 3, cell 2 || Row 3, cell 3 ||
|| Row 4, cell 1 || Row 4, cell 2 || Row 4, cell 3 ||
|| Row 5, cell 1 || Row 5, cell 2 || Row 5, cell 3 ||
|| Column 1 || Column 2 || Column 3 ||
:: caption Tag ::
>> The <caption> tag must be inserted immediately after the <table> tag.
To manage the layout of the tables, two attributes are used, rowspan and
colspan.
>> Attribute rowspan is used to mention the number of rows that a particular
cell will be occupying.
>> Attribute colspan is used to mention the number of columns that a specific
cell will be occupying.
They both are used with the td tag and can also be used with the th tag.
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
<tfoot>
<tr>
</tr>
</tfooft>
</table>
:::Forms:::
** Forms in HTML ::
"HTML Forms are used to collect different kinds of input from the
user". Through these forms, a user enters the data, which is either processed by
the browser itself (using Javascript) or the data goes to the servers where it
gets processed.
A form is an area that can contain form elements. A form is defined with the
<form> tag.
Syntax : <form>
// Form Elements
</form>
Let’s consider a basic form asking for the first name and the last name of the
user.
Submit
. In the above example, you can see that several tags and attributes are used.
We will cover them all in the upcoming modules.
. Firstly let’s learn about the form attributes or the functions in submitting
the form.
:: Form Attributes ::
When the form is submitted, the page gets reloaded, and we know
that the form gets submitted. But actually, the form input data is not being
submitted to the server. To get the form to send the input data to the server,
we need to set 2 attributes in the form:
1.action attribute
2.method attribute
1. action Attribute ::
The action attribute defines the action to be performed when the form is
submitted.
It tells where the form data is sent when the form is submitted. This contains
the address (i.e. URL) of the file where the data is sent. The URL can be
provided in an absolute and relative path.
NOTE: If the action attribute is not mentioned, the action is set to the
current page URL.
</form>
. In the above example, the form data is submitted to the index.html present
relative to the path.
2. method Attribute ::
NOTE: The default HTTP method when submitting form data is GET.
** GET method ::
This method appends the data into the URL with '?' as a separator in
name-value pairs. Since this data will be visible, so sensitive data (like
passwords) should not be sent. This can be used to send query strings.
Syntax : URL?name=value&name=value
EX: https://www.domain.com/url?variable=value&variable=value
& -- separator
This method appends the data inside the body of the HTTP request. The
post is used to "send the sensitive data" (the submitted form data is not shown
in the URL).
3. formaction Attribute ::
The input formation attribute specifies the URL of the file that will
process the input when the form is submitted using that specific button.
NOTE : This attribute overrides the action attribute of the <form> element.
</form>
:: Input Tag ::
The <input> tag specifies an input field where the user can
"enter data". <input> elements are used within a <form> element to declare input
controls that allow users to input data.
:: type Attribute ::
HTML provides different types of input that you can use for different
kinds of entries. By default, the value of type is text, which specifies that we
want single-line text input.
. submit
. email
. password
. date
. number
. range
. URL
. checkbox
. radio
. hidden
. time
Output: Submit
:: value Attribute ::
>> For "button", "reset", and "submit" : It defines the text on the button
>> For "text", "password", and "hidden" : It defines the initial (default) value
of the input field
>> For "checkbox", "radio", "image" - it defines the value associated with the
input (It is also the value that is sent on submit)
The name attribute is a compulsory attribute for input tag in a form. Without
this attribute, this form element won't be submitted or, in other words would
not be sent to the server.
The name attribute also uniquely identifies that piece of data. The value of the
input is accessed using the name attribute.
** label Tag ::
. The label is tied to this input element by giving the "id" attribute of the
input element the same value as the label's "for" attribute.
NOTE : The value of id and name can be the same, and most of the time, this will
be the case.
EX: <form>
<input type="text" required>
<input type="submit" value="Submit"/>
</form>
If we click submit without entering any value, this pop-up shows up.
---------------Submit
|
This is a required field
. The value of the placeholder attribute specifies a short hint that describes
the expected value of an input field.
Output: --------------
| First name |
--------------
EX: <form>
<br>
</form>
Output:
Username:
Coding_ninjas
Password:
------------
| ………………. |
------------
EX: <form>
</form>
EX: <form>
</form>
Checkboxes are used when more than one option may need to be checked,
or you can also use them to enable or disable something.
. There is also an attribute named checked, that when present, makes the
checkbox selected by default when the page loads.
EX: <form>
</form>
Output: . Red
. Green
.* White
6. Input type radio :
The radio button is just like a checkbox, but the difference is that
the values of the name attribute are all the same.
. The name attributes are all set to the same value makes these radio buttons
part of the same set, and therefore, you can only select one of them at once.
EX: <form>
</form>
Output: .* Male
. Female
. Other
. The hidden field includes some data and submits it along with the form,
which is not visible to the user.
. A hidden field often stores what database record needs to be updated when the
form is submitted.
EX: <form>
</form>
Output: Name: -------------
Submit
2 :: Select Element :: 2
. The select tag also contains a name attribute, like other form elements,
that represent the associated data submitted to the server.
:: Attributes ::
1. Multiple :
It allows the user to select more than one value. ( Press ctrl and select
)
</select>
Output : Option 1
Option 2
Option 3
2. size :
</select>
Output: Option 1
Option 2
Only 2 out of 3 options are displayed in the above example, and others can be
seen using the scrollbar.
:: option Element ::
. The first <option> element from the options' list is selected by default.
To change this predefined option, use the selected attribute with the <option>
tag.
Each option element should have a value attribute, which contains the data value
that will be submitted to the server when that option is selected.
</select>
Output: Green ^
Red
Blue
Green*
:::optgroup Element:::
The <optgroup> tag is used to group several options together into one
group.
EX: <select>
<optgroup label="Books">
</optgroup>
<optgroup label="Snippets">
</optgroup>
</select>
Ouput: HTML ^
Books
HTML
CSS
Snippets
Git
Java
:: Textarea Element ::
The <textarea> element is an input element where the user can input
multi-line text, unlike the <input type = ” text ”> element where there is only
a single line.
. A text area can hold an unlimited number of characters, and text wrapping is
allowed
EX: <form>
</form>
>> The rows attribute specifies the visible height of a text area.
>> The cols attribute specifies the visible width of a text area.
EX: <form>
</form>
Output: | |
| Type here ……….. |
| |
| |
EX: <form>
<fieldset>
<fieldset>
</form>
1. input tag :
The <input> tag can also be used to create a button. To use it as a
button, the type attribute is set to value submit. When the click event occurs,
i.e. the user clicks on the button, the form gets submitted. The input tag is a
self-closing tag, so the value of the button is set by the value attribute.
EX: <form>
</form>
Output: Submit
2. button tag :
. The button tag is a container tag and, therefore, can contain other tags.
This helps in adding images and other content to the button.
. The button has to set the type attribute to submit to make it a submit
button.
</button>
3. autofocus Attribute :
EX: <form>
</form>
Output: *With autofocus : Submit - It will focus
Question :: Your task is to build a form shown below using HTML form elements
and attributes
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<fieldset>
<!-- Main Heading -->
<legend>REGISTRATION FORM</legend>
<div>
<br>
<label for="lname">Last Name</label>
<br>
<input type="text" id= "lname" >
</div>
<div>
<p>Gender</p>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</div>
<div>
<br>
<label for="mail">Email</label>
<br>
<input type="email" id= "mail" required placeholder="[email protected]">
</div>
<div>
<br>
<textarea placeholder="Tell us about yourself..." rows="4"
cols="30"></textarea>
</div>
</fieldset>
<br>
<!-- Submit button -->
<input type="submit" autofocus>
</form>
</body>
</html>
Ans 1.
HTML form validation is a process of examining the HTML form page’s
contents to avoid errored-out data being sent to the server. This process is a
significant step in developing HTML-based web applications, as it can easily
improve the quality of the web page or the web application. There are two ways
to perform the HTML form Validation, and they are by Using HTML5 built-in
functionality and by Using JavaScript.
Q2. What is the usage of a novalidate attribute for the form tag that is
introduced in HTML5?
Ans 2.
Its value is a boolean type that indicates whether or not the data
being submitted by the form will be validated beforehand. By making this false,
forms can be submitted without validation which helps users to resume later
also.
Q3. What are the different new form element types in HTML 5?
Ans 3.
. Color
. Date
. Datetime-local
. Email
. Time
. Url
. Number
. Search
. Range
. Telephone
Ans 4 .
The button tag is used in HTML 5. It is used to create a clickable
button within the HTML form on the web page. It is generally used to create a
"submit" or "reset" button. Let's see the code to display the button.
<button name="button" type="button">Click Here</button>
Ans 5 . It forces a user to fill in text on the text field or text area before
submitting the form. It is used for form validation.
HTML can embed audio and videos directly on a web page without any
external support.
>> These elements are not sufficient to add the media. We need to control the
media as well. So, there are several tags and attributes that are required to
add the media entirely.
>> The <audio> and <video> are the same way the content is added to it, and only
the tag name is different.
:: controls Attribute ::
:: src Attribute ::
The src attribute is used to "specify the URL" of the media file
that is needed to be played. This can have an absolute or relative path.
:: type Attribute ::
The type attribute is used to specify the media type of the media
resource.
EX: Adding a video to a web page in different supported types for different
browsers
<video controls>
</video>
</video>
. By using the height and width attribute, the video size on a web page can also
be customized.
EX: Adding a audio to a web page in different supported types for different
browsers
<audio controls>
</audio>
. Multiple source tags are used so that the audio plays if any one of the
formats is supported by the browser. Else, the text message will be shown.
NOTE : Autoplay and muted can also be used for the audio element.
Youtube videos can also be directly added to your web page using the
embed video option on any youtube video.
"<iframe> element" is used to add the video with the src attribute but
a shortcut to that is simply to go to any youtube video and right-click on the
video, then select the ""copy embed code"" option.
>> Paste the code on the code editor, and the video will be added to the web
page.
src="https://www.youtube.com/embed/wDil2PGNPVI">
</iframe>
NOTE : controls, autoplay and muted attributes can also be used with iframe
Steps 1 : Go to google maps and enter the address you want to show
EX:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d30615.195624268494!2d
80.97141085072172!3d16.42993214537087!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m
3!1m2!1s0x3a361ca9703a5305%3A0xb92bbf81640f13be!2sGudivada%2C%20Andhra%20Pradesh
!5e0!3m2!1sen!2sin!4v1730811406905!5m2!1sen!2sin" width="600" height="450"
style="border:0;" allowfullscreen="" loading="lazy"
referrerpolicy="no-referrer-when-downgrade">
</iframe>
</body>
</html>
>> Metadata will not be displayed on the page but will be machine parsable. The
meta tag is a self-closing tag, and the data stored in it is known as metadata.
>> Meta elements are typically used to specify page description, keywords,
author of the document, title, image etc.
. You must have seen card views of a website at many places like this :
In the above card, you can see the meta image, title and description. If
metadata is not specified in the HTML code, the browser will automatically fetch
this data from the web page, which could also lead to unexpected results.
. name
. Content
. property
. charset
. http-equiv
Meta tags have been one of the essential elements of SEO. They are
used to provide details about your site to search engines. Search engine
optimization (SEO) is defined as the process of affecting the online visibility
of a website or a web page in a web search engine's results.
NOTE : There can be any number of meta tags defined within a page inside the
head.
1. name Attribute ::
The name attribute is used to specify the name for the metadata.
The name attribute is used together with the content attribute. This attribute
specifies a name for the information/value of the content attribute.
NOTE : If the http-equiv attribute is set, the name attribute should not be set.
SEO is used by the search engines like google and bing to search for the
website's content relevant to the user search. This increases the quality and
quantity of traffic on one's website.
2. content Attribute ::
The content attribute gives the value associated with the http-equiv or
name attribute.
content="width=device-width,initial-scale=0.5,minimum-scale=0.5">
3. property Attribute ::
This attribute tells the type of data that should be given to the
metadata. It is used with the content attribute.
4. charset Attribute ::
The charset attribute is used for declaring the character encoding for
the page. It is a good practice to use UTF-8 encoding. However, this must be
taken care of that the declared character set matches the one on the page and is
defined for every page of the website.
Example: the refresh value is used to specify the seconds after which the page
will be refreshed. And if, along with the time, a URL is mentioned as
'5;url=https://www.codingninjas.in/', then after 5 seconds, the user would be
redirected to the mentioned URL.
:: Favicon ::
You can see an icon beside the title of the page on the tab itself. This is
known as favicon.
:: Emojis ::
To display emojis on web page meta tag is used with the charset
attribute set to UTF-8 because emojis are characters from the UTF-8 character
set.
>> Some numbers or characters which can’t be typed on a keyboard can also be
shown on a web page using their UTF-8 code.
Emojis are not present on the keyboard so they are typed with their specific
codes like :
. 😃 is for 😃
. 😄 is for 😄
. 😅 is for 😅
<!DOCTYPE html>
<html>
<head>
<title>Article</title>
</head>
<body>
<div class="container-article">
<div class="article-title">
<h1>
Airport
</h1>
</div>
<div class="article-description">
<h3>
Importance of Airport Security
</h3>
</div>
<div class="article-img-container">
<img
src="https://content.presspage.com/uploads/1911/1920_dsc-4234.jpg?10000"
alt="Airport image" height="100" width="250">
</div>
<div class="article-content">
<p>
<!-- add any content here -->
Airport security plays a key role in engendering trust in passengers when it
comes to air transport. It seems obvious that air travel would not have evolved
the way it has in recent years if it werent secure, if passengers hadnt trusted
that their flight would arrive at its destination without any life-threatening
incidents. Security, therefore, is not only a pillar for the development of
aviation but has actively contributed to the passenger number growth we have
witnessed in recent years. Personally, I would even go as far as to say that
this mode of transport would have become extinct if, throughout the years,
passengers hadnt put their faith in air travel being safe and secure.
</p>
</div>
</div>
</body>
</html>