Global Attributes: The Attributes of An Element Which Is Common To The All HTML Elements. Some of The Global Attributes Are
Global Attributes: The Attributes of An Element Which Is Common To The All HTML Elements. Some of The Global Attributes Are
accesskey: Provides a hint for Specifies a shortcut key to activate/focus a current element. This
attribute consists of a space-separated list of characters. The browser should use the first one
that exists on the computer keyboard layout.
Syntax:<element accesskey="character">
class: The class attribute specifies one or more class names for an element . Classes allows CSS
and JavaScript to select and access specific elements via the tag.
Syntax: <element class="classname">
Example:
<html>
<head>
<style>
h1.intro {
color: blue;
}
.mark {
background-color: yellow;
p.highlight {
color: green;
}
</style>
</head>
<body>
<h1 class="intro">Header one</h1>
<p>A paragraph.</p>
<p class="highlight">Note that this is an highlight paragraph. :)</p>
true or the empty string, which indicates that the element must be editable;
false, which indicates that the element must not be editable.
The contenteditable attribute specifies whether the content of an element is editable or not.
Syntax: <element contenteditable="true|false">
Example:
<html>
<body>
</body>
</html>
Data-* : Used to store custom data private to the page or application. This attribute is ability to
embed custom data attributes on all HTML elements.
Syntax: <element data-*="somevalue">
Example:
<ul>
<li data-animal-type="bird">Sparrow</li>
<li data-animal-type="fish">Dalphin</li>
</ul>
dir: This attribute specifies the text direction of the element's content. There are three different
value of attribute should be assign. That are ltr, rtl and auto.
Syntax: <element dir="ltr|rtl|auto">
Example:
<html>
<body>
</body>
</html>
hidden: This is the boolean attribute indicates that the element is not yet, or is no
longer, relevant. It can be used to hide elements of the page that can't be used until the login
process has been completed.
Syntax: <element hidden>
Example:
id: The id attribute specifies a unique id for an HTML element. It most be used to point to a
style in a style sheet, and by JavaScript to define the element with the specific id.
Syntax: <element id="id">
Example: copy
Example:
Tabindex: This attribute define the order of an element for the navigation.
Syntax: <element tabindex="number">
Example:
<a href="https://www.google.com/" tabindex="2">google</a>
<a href="http://www.msn.com/" tabindex="1">Msn</a>
<a href="http://www.microsoft.com/" tabindex="3">Microsoft</a>
Title: This attribute is used for extra information of the element when the mouse is over that
element.
Syntax: <element title="text">
Example:
HTML document have basic two containers that are head and body.
<html>
<head>
<title> The title of your Web page goes here</title>
</head>
<body>
The text and images on your Web page go here
</body>
</html>
Page structure
<p> ….</p> paragraph:
<div>...</div> division: enables you do designate sections of text for styling; will insert
an extra line
<span>...</span> span: enables you to designate sections of text for styling without
inserting any extra space.
<center> …..</center> center the content like text and image
<blockquote>……</blockquote> indents text from the left margin
Heading: Heading is also define by heading tag (e.g., <h1> <h2>….<h6>)
Block level formatting is mainly used for containing the block of element and some text.
It can be appear in the body of an html page. Block level elements begin on new lines.
<h1>My <span style="color:red">Important</span> Heading</h1>
List Tags:
List is the piece of short information, which is used for listing the data.
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
A link is specified using HTML tag <a>. This tag is called anchor tag and anything between the
opening <a> tag and the closing </a> tag becomes part of the link and a user can click that part
to reach to the linked document
<a href="https://www.news.com”> Visit our NEWS</a>
The alt attribute provides an alternate text for an image, if the user for some reason cannot
view it (because of slow connection, an error in the src attribute, or if the user uses a screen
reader).
<img src="img_chania.jpg" alt="Flowers in Chania">
Server-Side Image
Some web sites store their images on image servers.
<img src="https://www.abc.com/images/html5.gif" alt="HTML5
Icon" style="width:128px;height:128px;">
Image Maps
The <map> tag defines an image-map. An image-map is an image with clickable areas. The idea
behind an image map is that you should be able to perform different actions depending on
where in the image you click.
<img src="workplace.jpg" alt="Workplace" usemap="#workmap">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffee.htm">
</map>
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.
Shape
You must define the shape of the area, and you can choose one of these values:
HTML Table
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 style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
There are attribute of table element some of them are the global attributes to.
Align: It is define the table aligned inside the contacting document.
Left: Table is displayed on the left side of the document
Center: on the center of the document
Right: on the right side of the document
Bgcolor: This attribute define the background color of the table. For color, 6 digit hexadecimal
code and prefixed is denoted by #. Black--#000000, red--#ff0000, white--#ffffff
Border: the size of the frame surrounding the table.
<table border="1|0">
Cellpadding: The cellpadding attribute specifies the space, in pixels, between the cell wall and
the cell content.
<table cellpadding="10">
cellspacing : The cellspacing attribute specifies the space, in pixels, between cells.
<table cellspacing="10">
Frame: The frame attribute specifies which parts of the outside table borders that should be
visible.
Syntax
<table frame="value">
<table frame="box">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
rules : The rules attribute specifies which parts of the inside borders that should be visible.
The styling of the rules is browser dependent and cannot be modified.
Syntax:
<table rules="value">
Attribute Values
Value Description
none No lines
groups Lines between row groups (defined by the <thead>, <tbody>, <tfoot>) and
column groups (defined by the <col>, <colgropus>).
rows Lines between rows
cols Lines between columns
all Lines between rows and columns
<table rules="rows">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
Syntax:
<table summary="text">
<table width="400">
Frameset: It is used to divide the page into multiple sections where each section can be loaded
separately.
The <frameset> element holds one or more <frame> elements. Each <frame> element can hold
a separate document.
The <frameset> element specifies How many columns or rows there will be in the frameset, and
How much percentage/pixels of space will occupy each of them.
<frameset cols="25%,*,25%">
<frame src="frame_1.htm">
<frame src="frame_2.htm">
<frame src="frame_3.htm">
</frameset>
The name attribute is used to reference the element in a JavaScript, or to act as a target
for a link.
<frame name="text">
Src: The src attribute specifies the URL of the document to show in a frame.
<frame src="frame_a.htm">
marginwidth : The marginwidth attribute specifies the width between the content and the left
and right sides of the frame, in pixels.
<frame marginwidth="pixels">
<frameset cols="50%,50%">
<frame src="frame_a.htm" marginwidth="50">
<frame src="frame_b.htm" marginwidth="0">
</frameset
marginheight : The marginheight attribute specifies the height between the content and the top
and bottom of the frame, in pixels.
<frame marginheight="pixels">
scrolling : The scrolling attribute specifies whether or not to display scrollbars in a <frame>.
By default, scrollbars appear in a <frame> if the content is larger than the <frame>.
<frame scrolling="auto|yes|no">
</frameset>
</frameset>
Targeting frames
Load a new linked page into a particular frame as a link. Where frame name and source is
define.
Inline frame or iframe is allow to open new page inside the main page. It is used as
<iframe>….</iframe> tag.
A form is a document with spaces in which to write or select, for a series of documents
with similar contents. Where form in html is a document which stores information of
user on a web server using interactive controls. Some of the information are as follows;
name, address, password, contact number, email id etc.
The control contains are the text field, checkbox, submit button etc.
The <form> tag is used to create an HTML form for user input.
The <form> element can contain one or more of the following form elements:
<input>
<textarea>
<button>
<select>
<option>
<optgroup>
<fieldset>
<label>
<output>
action: The action attribute specifies where to send the form-data when a form is
submitted.
<form action="URL">
url is define for where to send the form-data when the form is submitted.
Method: The method attribute specifies how to send form-data (the form-data is sent
to the page specified in the action attribute).
The form-data can be sent as URL variables (with method="get") or as HTTP post
transaction (with method="post").
Notes on GET:
Notes on POST:
Appends form-data inside the body of the HTTP request (data is not shown is
in URL)
Has no size limitations
Form submissions with POST cannot be bookmarked
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
<form action="/action_page.php" method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
Ex:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML onsubmit attribute with form</title>
</head>
<body>
<form name="user_info" onsubmit="alert('The form is submitted')" action="">
Name : <input type="text" name="name"><br>
email : <input type="text" name="email"><br>
Describe yourself : <br/>
<textarea rows="10" colos="10" name="describe_yourself">
</textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
enctype
<form action="/action_page_binary.asp" method="post" enctype="multipart/form-
data">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
accept
The accept attribute specifies the type of files that the server accepts (that can be
submitted through a file upload).
Eg:
<form>
<input type= “file” name= “pic” accept= “image/jpeg”>
<input type = “submit”>
</form>
accept-charset
This attribute specifies the characters encoding that are to be used for the form
submission.
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
target
This attribute specified the name or keyword indicating where to display the response
that is received after submitting the form.
_self: Load the response into the same frame. This value is the default if the attribute is
not specified.
_blank: Load the response into a new window or tab.
_parent: Load the response into the parent frame, if there is no parent; this option
behaves the same way as _self.
_top: Load the response into the full original window, and cancel all other frames.
iframename: The response is displayed in a named <iframe>
<form action="/action_page.php" method="get" target="_blank">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
autofocus
This attribute specifies that the input field should automatically get focus when the page
loads.
<form action="/action_page.php" method="get" target="_blank">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
Fieldset
The <fieldset> tag is used to group related elements in a form and draws a box around the
related elements. This can be especially useful in large forms, where readability and ease
of access can be improved with segmentation.
<form id = “form1”>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
<input type="submit">
</form>
<fieldset form="form1">
User Name: <input type="text" name="username"><br>
</fieldset>
input
The <input> tag specifies an input field where the user can enter data. This <input>
elements are used within a <form> element to declare input controls that allow users to
input data. An input field can vary in many ways, depending on the type attribute.
<input type="text" name="fname">
type attribute of the input elements define the different control used as their purpose.
In input element there are number of different type of control are define they are as
follows: button, checkbox, color, date, datetime-local, email, file, hidden, image, month,
number, password, radio, range, reset, search, submit, tel, text, time, url, week
<form action="/action_page.php">
<input type="checkbox" name="Subject" value="Math"> Math<br>
<input type="checkbox" name="Subject" value="Computer" checked> Computer<br>
<input type="submit" value="Submit">
</form>
<form action="/action_page.php">
<input type="submit">
</form>
button -The <button> tag defines a clickable button. Inside a <button> element you can put
content, like text or images. This is the difference between this element and buttons created
with the <input> element.
type –The type attribute specifies the type of button. That are button, submit, reset
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
label
This element is used for the labeling the different control which can be associated to a
form, and is supposed to provide a short description for it. <label> element is also able to
associated with the input element. To associate the <label> with an <input> element, you
need to give the <input> an id attribute. The <label> then needs a for attribute whose
value is the same as the input's id.
for -The for attribute specifies which form element a label is bound to.
<label for="element_id">
<form action="/action_page.php">
<label for="male">Male</label>
<input type="radio" name="gender" id="male" value="male"><br>
<input type="submit" value="Submit">
</form>
form -The form attribute specifies one or more forms the <label> element belongs to.
<label form="form_id">
<form action="/action_page.php" id="form1">
<input type="radio" name="gender" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="gender" id="female" value="female"><br>
<label for="other">Other</label>
<input type="radio" name="gender" id="other" value="other"><br><br>
<input type="submit" value="Submit">
</form>
<label for="male" form="form1">Male</label>
select
HTML <select> tag is used to create drop down list of options, which appears when
clicking on form element and allows the user to choose one of the options.
The <option> tag is used to define the possible options to choose from. The tag is put
into <select> tag. The first option from the options’ list is selected by default.
<select>
<option value="HTML">Html</option>
<option value="CSS">Css/option>
<option value="Java">Java</option>
<option value="PHP">PHP</option>
</select>
multiple – This attribute specifies that multiple options can be selected at once
The <textarea> tag defines a form field where user can input a multi-line text.
Unlike the <input> tag, text wrapping inside <textarea> is allowed when the form is
submitted. A text area can contain an unlimited number of characters. The text between
opening <textarea> and closing </textarea> tags is rendered in a fixed-width font
Script
The HTML <script> tag declares client-side script (JavaScript) in an HTML document.
When defining a client-side script the script tag is used for image manipulation, form
validation, and dynamic changes of content. The HTML <script> tag can be placed in
the <head> element, as well as within the <body> element. The <script> must be
executed first, must be placed in the heading of the document.
Eg;
<html>
<body>
<p>When you leave the input field, a function is triggered which transforms the input
text to upper case.</p>
<script>
function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
</script>
</body>
</html>
A Style Sheet is a collection of style rules that that tells a browser how the
various styles are to be applied to the HTML tags to present the document. Rules can be
applied to all the basic HTML elements, for example the <p> tag, or you can define you
own variation and apply them where you wish to.
Style Sheets let you selectively override previous defined Styles. For example a Web site
might be using a standard Style Sheet but certain Web pages can have an additional
Style Sheet that can override styles that have been defined in the standard Style Sheet.
Example:
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
</style>
Importance of CSS
Cascading Style Sheet(CSS) is used to set the style in web pages which contain HTML
elements. It sets the background color, font-size, font-family, color, … etc property of
elements in a web pages.
There are three types of CSS which are given below:
Inline CSS
Internal or Embedded CSS
External CSS
Inline CSS: Inline CSS contains the CSS property in the body section attached with element is
known as inline CSS. This kind of style is specified within an HTML tag using style attribute.
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<p style = "color:#009900; font-size:50px;
font-style:italic; text-align:center;">
Madhan Bhandari
</p>
</body>
</html>
Internal or Embedded CSS: This can be used when a single HTML document must be styled
uniquely. The CSS rule set should be within the HTML file in the head section i.e the CSS is
embedded within the HTML file.
<html>
<head>
<title>Internal CSS</title>
<style>
.main {
text-align:center;
}
.mbm {
color:#009900;
font-size:50px;
font-weight:bold;
}
.std {
font-style:bold;
font-size:20px;
}
</style>
</head>
<body>
<div class = "main">
<div class ="mbm">Madhan Bhandari Memorial College</div>
<div class ="std">
A computer science portal for student
</div>
</div>
</body>
</html>
External CSS: External CSS contains separate CSS file which contains only style property with
the help of tag attributes (For example class, id, heading, … etc). CSS property written in a
separate file with .css extension and should be linked to the HTML document using link tag. This
means that for each element, style can be set only once and that will be applied across web
pages.
body {
background-color:powderblue;
.main {
text-align:center;
.mbm {
color:#009900;
font-size:50px;
font-weight:bold;
#stud {
font-style:bold;
font-size:20px;
<html>
<head>
</head>
<body>
<div id ="stud">
</div>
</div>
</body>
</html>
CSS Selectors
CSS Selectors allow us to target specific HTML elements with our style sheets. Selectors are the
part of CSS rule set. CSS selectors select HTML elements according to its id, class, type, attribute
etc.
There are several different types of selectors in CSS.
Type Selectors are very simple. They correspond with any HTML element type.
p {
text-align: center;
color: red;
}
body {
font-family: Arial, sans-serif;
font-size: small;
}
h1 {
color: green;
}
The id selector selects the id attribute of an HTML element to select a specific element. An id is
always unique within the page so it is chosen to select a single, unique element.
It is written with the hash character (#), followed by the id of the element.
#para1 {
text-align: center;
color: red;
}
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. The major difference is
that while a certain ID should only be assigned to one element, we can assign the same class to
as many elements as we want.
.center {
text-align: center;
color: red;
}
If you want to specify that only one specific HTML element should be affected then you should
use the element name with class selector.
p.center {
text-align: center;
color: red;
}
The universal selector is used as a wildcard character. It selects all the elements on the pages.
* {
text-align: center;
color: blue;
}
The grouping selector is used to select all the elements with the same style definitions.
Grouping selector is used to minimize the code. Commas are used to separate each selector in
grouping.
CSS Combinators
CSS combinators are explaining the relationship between two selectors. CSS selectors are the
patterns used to select the elements for style purpose. A CSS selector can be a simple selector
or a complex selector consisting of more than one selector connected using combinators.
General Sibling selector: The general sibling selector is used to select the element that follows
the first selector element and also share the same parent as the first selector element. This can
be used to select a group of elements that share the same parent element.
div ~ p{
color: #009900;
font-size:32px;
font-weight:bold;
margin:0px;
text-align:center;
}
div {
text-align:center;
}
Adjacent Sibling selector: The Adjacent sibling selector is used to select the element that is
adjacent or the element that is the next to the specified selector tag. This combinator selects
only one tag that is just next to the specified tag.
div + p{
color: #009900;
font-size:32px;
font-weight:bold;
margin:0px;
text-align:center;
}
div {
text-align:center;
}
p {
text-align:center;
}
Child Combinator: This selector is used to select the element that is the immediate child of the
specified tag. This combinator is stricter than the descendant selector because it selects only
the second selector if it has the first selector element as its parent.
div > p{
color: #009900;
font-size:32px;
font-weight:bold;
margin:0px;
text-align:center;
}
div {
text-align:center;
}
p {
text-align:center;
}
Descendant selector: This selector is used to select all the child elements of the specified tag.
The tags can be the direct child of the specified tag or can be very deep in the specified tag. This
combinator combines the two selectors such that selected elements have an ancestor same as
the first selector element.
div p{
color: #009900;
font-size:32px;
font-weight:bold;
margin:0px;
text-align:center;
}
div {
text-align:center;
}
p {
text-align:center;
}