Moocs File
Moocs File
HTML :-
HTML stands for Hyper Text Markup Language, which is the most
widely used language on Web to develop web pages. HTML was created by
Berners-Lee in late 1991 but "HTML 2.0" was the first standard HTML
specification which was published in 1995. HTML 4.01 was a major version
of HTML and it was published in late 1999. Though HTML 4.01 version is
widely used but currently we are having HTML-5 version which is an
extension to HTML 4.01, and this version was published in 2012.
Basic HTML Document In its simplest form, following is an example of
an HTML document:
This is a heading
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
HTML Tags
As told earlier, HTML is a markup language and makes use of various tags
to format the content. These tags are enclosed within angle braces . Except
few tags, most of the tags have their corresponding closing tags. For
example, has its closing tag
and
tag has its closing tag
tag etc. Above example of HTML document uses the following tags:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Heading Tags:
Any document starts with a heading. You can use different sizes for your
headings. HTML also has six levels of headings, which use the elements
<h1>,<h2> ,<h3>,<h4> , <h5>, and <h6>. While displaying any heading,
browser adds one line before and one line after that heading.
Paragraph Tag:
The tag offers a way to structure your text into different paragraphs. Each
paragraph of text should go in between an opening <p>and a closing </p>
tag as shown below in the example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Centering Content :
You can use tag to put any content in the center of the page or any table
cell.
Horizontal Lines
tag creates a line from the current position in the document to the right
margin and breaks the line accordingly.
Again tag is an example of the empty element, where you do not need
opening and closing tags, as there is nothing to go in between them. The
element has a space between the characters hr and the forward slash. If
you omit this space, older browsers will have trouble rendering the
horizontal line, while if you miss the forward slash character and just use
HTML ELEMENTS:-
An HTML element is defined by a starting tag. If the element contains other
content, it ends with a closing tag, where the element name is preceded by
a forward slash as shown below with few tags.
here <p>….</p> is an HTML element, <h1>…..</h1>
is another HTML element. There are some HTML elements which don't
need to be closed, such as ,<img/> and <h1/> and </br> elements. These
are known as void elements. HTML documents consists of a tree of these
elements and they specify how HTML documents should be built, and what
kind of content should be placed in what part of an HTML document.
HTML ATTRIBUTES:-
We have seen few HTML tags and their usage like heading tags <h1>,<h2>
and paragraph tag <p>and other tags. We used them so far in their simplest
form, but most of the HTML tags can also have attributes, which are extra
bits of information.
An attribute is used to define the characteristics of an HTML element and is
placed inside the element's opening tag. All attributes are made up of two
parts: a name and a value:
• The name is the property you want to set. For example, the paragraph
element in the example carries an attribute whose name is align, which you
can use to indicate the alignment of paragraph on the page.
• The value is what you want the value of the property to be set and always
put within quotations. The below example shows three possible values of
align attribute: left, center and right.
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:
• If you have two elements of the same name within a Web page (or style
sheet), you can use the id attribute to distinguish between elements that
have the same name.
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.
CSS handles the look and feel part of a web page. Using CSS, you can
control the color of the text, the style of fonts, the spacing between
paragraphs, how columns are sized and laid out, what background images
or colors are used, as well as a variety of other effects.
CSS is easy to learn and understand but it provides a powerful control over
the presentation of an HTML document. Most commonly, CSS is combined
with the markup languages HTML or XHTML.
Advantages of CSS
• CSS saves time - You can write CSS once and then reuse the same sheet
in multiple HTML pages. You can define a style for each HTML element and
apply it to as many web pages as you want.
• Pages load faster - If you are using CSS, you do not need to write HTML
tag attributes every time. Just write one CSS rule of a tag and apply it to all
the occurrences of that tag. So, less code means faster download times.
• Superior styles to HTML - CSS has a much wider array of attributes than
HTML, so you can give a far better look to your HTML page in comparison to
HTML attributes.
A CSS comprises of style rules that are interpreted by the browser and then
applied to the corresponding elements in your document. A style rule is
made of three parts:
• Property: A property is a type of attribute of HTML tag. Put simply, all the
HTML attributes are converted into CSS properties. They could be color,
border, etc.
• Value: Values are assigned to properties. For example, color property
can have the value either red or #F1F1F1 etc.
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to
style.
We can divide CSS selectors into five categories:
• Simple selectors (select elements based on name, id, class)
• Combinator selectors (select elements based on a specific
relationship between them)
• Pseudo-class selectors (select elements based on a certain state)
• Pseudo-elements selectors (select and style a part of an element)
• Attribute selectors (select elements based on an attribute or
attribute value)
To select an element with a specific id, write a hash (#) character, followed
by the id of the element.
The CSS rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
}
Three Ways to Insert CSS
There are three ways of inserting a style sheet:
• External CSS
• Internal CSS
• Inline CSS
External CSS
With an external style sheet, you can change the look of an entire website by
changing just one file!
Each HTML page must include a reference to the external style sheet file
inside the <link> element, inside the head section.
Example
External styles are defined within the <link> element, inside the <head>
section of an HTML page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor, and must be saved
with a .css extension.
The external .css file should not contain any HTML tags.
Internal CSS
An internal style sheet may be used if one single HTML page has a unique
style.
The internal style is defined inside the <style> element, inside the head
section.
Example
Internal styles are defined within the <style> element, inside the <head>
section of an HTML page:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The
style attribute can contain any CSS property.
Example
Inline styles are defined within the "style" attribute of the relevant element:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
CSS Margins
The CSS margin properties are used to create space around elements,
outside of any defined borders.
With CSS, you have full control over the margins. There are properties for
setting the margin for each side of an element (top, right, bottom, and left).
Margin - Individual Sides
CSS has properties for specifying the margin for each side of an element:
• margin-top
• margin-right
• margin-bottom
• margin-left
All the margin properties can have the following values:
The element will then take up the specified width, and the remaining space
will be split equally between the left and right margins.
Example
Use margin: auto:
div {
width: 300px;
margin: auto;
border: 1px solid red;
}
CSS background-image
The background-image property specifies an image to use as the
background of an element.
CSS Backgrounds
The CSS background properties are used to add background effects for
elements.
In these chapters, you will learn about the following CSS background
properties:
• background-color
• background-image
• background-repeat
• background-attachment
• background-position
• background (shorthand prop
JavaScript Introduction
What is JavaScript?
JavaScript is the programming language of the web.
document.getElementById("demo").style.fontSize = "35px";
The <script> Tag
In HTML, JavaScript code is inserted between <script> and </script> tags.
Example
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
JavaScript Functions and Events
A JavaScript function is a block of JavaScript code, that can be executed
when "called" for.
For example, a function can be called when an event occurs, like when the
user clicks a button.
JavaScript in <head>
In this example, a JavaScript function is placed in the <head> section of an
HTML page.
The function is invoked (called) when a button is clicked:
Example
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</head>
<body>
<h2>Demo JavaScript in Head</h2>
</body>
</html>
JavaScript in <body>
In this example, a JavaScript function is placed in the <body> section of an
HTML page.
The function is invoked (called) when a button is clicked:
Example
<!DOCTYPE html>
<html>
<body>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</body>
</html>
External JavaScript
Scripts can also be placed in external files:
Example
<script src="myScript.js"></script>
JavaScript Values
The JavaScript syntax defines two types of values:
• Fixed values
• Variable values
Fixed values are called Literals.
Variable values are called Variables.
JavaScript - Introduction
JavaScript Literals
The two most important syntax rules for fixed values are:
1001
2. Strings are text, written within double or single quotes:
"John Doe"
'John Doe'
JavaScript Variables
In a programming language, variables are used to store data values.
JavaScript uses the keywords var, let and const to declare variables.
An equal sign is used to assign values to variables.
In this example, x is defined as a variable. Then, x is assigned (given) the
value 6:
let x;
x = 6;