written 5.8 years ago by |
0.1 INTRODUCTION TO HTML 5
HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML 1.0, and XHTML 1.1.
HTML5 is a standard for structuring and presenting content on the World Wide Web.
HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).
0.1.1 New Features
- HTML5 introduces a number of new elements and attributes that can help you in building modern websites. Here is a set of some of the most prominent features introduced in HTML5.
1. New Semantic Elements − These are like <header>
, <footer>
and <section>
.
2. Forms 2.0 − Improvements to HTML web forms where new attributes have been introduced for <input>
tag.
3. Persistent Local Storage − To achieve without resorting to third-party plugins.
4. WebSocket − A next-generation bidirectional communication technology for web applications.
5. Server-Sent Events − HTML5 introduces events which flow from the web server to the web browsers and they are called Server-Sent Events (SSE).
6. Canvas − This supports a two-dimensional drawing surface that you can program with JavaScript.
7. Audio & Video − You can embed audio or video on your web pages without resorting to third-party plugins.
8. Geolocation − Now visitors can choose to share their physical location with your web application.
9. Microdata − This lets you create your own vocabularies beyond HTML5 and extend your web pages with custom semantics.
10. Drag and drop − Drag and drop the items from one location to another location on the same webpage.
0.1.2 HTML5 Document
The following tags have been introduced for better structure −
section − This tag represents a generic document or application section. It can be used together with h1-h6 to indicate the document structure.
article − This tag represents an independent piece of content of a document, such as a blog entry or newspaper article.
aside − This tag represents a piece of content that is only slightly related to the rest of the page.
header − This tag represents the header of a section.
footer − This tag represents a footer for a section and can contain information about the author, copyright information, et cetera.
nav − This tag represents a section of the document intended for navigation.
dialog − This tag can be used to mark up a conversation.
figure − This tag can be used to associate a caption together with some embedded content, such as a graphic or video.
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>...</title>
</head>
<body>
<header role = "banner">
<h1>HTML5 Document Structure Example</h1>
<p>This page should be tried in safari, chrome or Mozila.</p>
</header>
<nav>
<ul>
<li><a href = "https://www.tutorialspoint.com/html">HTML Tutorial</a></li>
<li><a href = "https://www.tutorialspoint.com/css">CSS Tutorial</a></li>
<li><a href = "https://www.tutorialspoint.com/javascript"> JavaScript Tutorial</a></li>
</ul>
</nav>
<article>
<section>
<p>Once article can have multiple sections</p> </section>
</article>
<aside>
<p>This is aside part of the web page</p>
</aside>
<footer>
<p>Created by <a href = "https://tutorialspoint.com/">Tutorials Point</a></p>
</footer>
</body>
</html>
0.2 CSS BASICS
CSS is used to control the style of a web document in a simple and easy way.
CSS is the acronym for "Cascading Style Sheet".
It covers both the versions CSS1, CSS2 and CSS3, and gives a complete understanding of CSS, starting from its basics to advanced concepts.
Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to simplify the process of making web pages presentable.
CSS is easy to learn and understand but it provides 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 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.
Easy maintenance − To make a global change, simply change the style, and all elements in all the web pages will be updated automatically.
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.
Multiple Device Compatibility − Style sheets allow content to be optimized for more than one type of device. By using the same HTML document, different versions of a website can be presented for handheld devices such as PDAs and cell phones or for printing.
Global web standards − Now HTML attributes are being deprecated and it is being recommended to use CSS. So its a good idea to start using CSS in all the HTML pages to make them compatible to future browsers.
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 −
(a) Selector − A selector is an HTML tag at which a style will be applied. This could be any tag like <h1>
or <table>
etc.
(b) 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.
(c) Value − Values are assigned to properties. For example, color property can have value either red or #F1F1F1 etc.
Syntax: selector { property: value }
The Type Selectors This is the same selector we have seen above. Again, one more example to give a color to all level 1 headings −
h1{ color:#36CFFF: }
The Universal Selectors
Rather than selecting elements of a specific type, the universal selector quite simply matches the name of any element type −
* {
color: #000000;
}
This rule renders the content of every element in our document in black.
- The Descendant Selectors
Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. As given in the following example, style rule will apply to <em>
element only when it lies inside <ul>
tag.
ul em { color: #000000; }
- The Class Selectors
You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule.
.black { color: #000000; }
This rule renders the content in black for every element with class attribute set to black in our document. You can make it a bit more particular. For example −
h1.black { color: #000000; }
This rule renders the content in black for only <h1>
elements with class attribute set to black.
You can apply more than one class selectors to a given element. Consider the following example −
<p class = "center bold">
This para will be styled by the classes center and bold.
</p>
- The ID Selectors
You can define style rules based on the id attribute of the elements. All the elements having that id will be formatted according to the defined rule.
# black { color: #000000; }
This rule renders the content in black for every element with id attribute set to black in our document. You can make it a bit more particular. For example −
h1#black { color: #000000; }
This rule renders the content in black for only <h1>
elements with id attribute set to black.
The true power of id selectors is when they are used as the foundation for descendant selectors, For example −
#black h2 { color: #000000; }
In this example, all level 2 headings will be displayed in black color when those headings will lie within tags having id attribute set to black.
- The Child Selectors
You have seen the descendant selectors. There is one more type of selector, which is very similar to descendants but have different functionality. Consider the following example −
body > p { color: #000000; }
This rule will render all the paragraphs in black if they are the direct child of <body>
element. Other paragraphs put inside other elements like <div>
or <td>
would not have any effect of this rule.
- The Attribute Selectors
You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of the text −
input[type = "text"] { color: #000000; }
The advantage to this method is that the <input type = "submit" />
element is unaffected, and the color applied only to the desired text fields.
There are following rules applied to attribute selector.
p[lang] − Selects all paragraph elements with a lang attribute.
p[lang="fr"] − Selects all paragraph elements whose lang attribute has a value of exactly "fr".
p[lang~="fr"] − Selects all paragraph elements whose lang attribute contains the word "fr".
p[lang|="en"] − Selects all paragraph elements whose lang attribute contains values that are exactly "en", or begin with "en-".
- Multiple Style Rules
You may need to define multiple style rules for a single element. You can define these rules to combine multiple properties and corresponding values into a single block as defined in the following example −
h1 { color: #36C; font-weight: normal; letter-spacing: .4em; margin-bottom: 1em; text-transform: lowercase;}
Here all the property and value pairs are separated by a semicolon (;). You can keep them in a single line or multiple lines. For better readability, we keep them in separate lines.
For a while, don't bother about the properties mentioned in the above block. These properties will be explained in the coming chapters and you can find complete detail about properties in CSS References
- Grouping Selectors
You can apply a style to many selectors if you like. Just separate the selectors with a comma, as given in the following example −
h1, h2, h3 { color: #36C; font-weight: normal; letter-spacing: .4em; margin-bottom: 1em; text-transform: lowercase;}
This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list is irrelevant. All the elements in the selector will have the corresponding declarations applied to them.
You can combine the various id selectors together as shown below −
#content, #footer, #supplement { position: absolute; left: 510px; width: 200px;}
Example:
<!DOCTYPE html>
<html>
<head>
<style type = "text/css" media = "all">
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>
0.3 XML BASICS
XML stands for Extensible Markup Language and is a text-based markup language derived from Standard Generalized Markup Language (SGML).
XML tags identify the data and are used to store and organize the data, rather than specifying how to display it like HTML tags, which are used to display the data.
XML is not going to replace HTML in the near future, but it introduces new possibilities by adopting many successful features of HTML.
There are three important characteristics of XML that make it useful in a variety of systems and solutions −
XML is extensible − XML allows you to create your own self-descriptive tags, or language, that suits your application.
XML carries the data, does not present it − XML allows you to store the data irrespective of how it will be presented.
XML is a public standard − XML was developed by an organization called the World Wide Web Consortium (W3C) and is available as an open standard.
A short list of XML usage says it all −
- XML can work behind the scene to simplify the creation of HTML documents for large websites.
- XML can be used to exchange information between organizations and systems.
- XML can be used for offloading and reloading of databases.
- XML can be used to store and arrange the data, which can customize your data handling needs.
- XML can easily be merged with style sheets to create almost any desired output.
- Virtually, any type of data can be expressed as an XML document.
Example:
<?xml version = "1.0"?>
<contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</contact-info>
0.3.1 XML Declaration
The XML document can optionally have an XML declaration. It is written as follows −
<?xml version = "1.0" encoding = "UTF-8"?>
- Where version is the XML version and encoding specifies the character encoding used in the document.
- Syntax Rules for XML Declaration
- The XML declaration is case sensitive and must begin with "
<?xml>
" where "xml" is written in lower-case. - If document contains XML declaration, then it strictly needs to be the first statement of the XML document.
- The XML declaration strictly needs be the first statement in the XML document.
- An HTTP protocol can override the value of encoding that you put in the XML declaration.
0.3.2 XML References
References usually allow you to add or include additional text or markup in an XML document. References always begin with the symbol "&" which is a reserved character and end with the symbol ";". XML has two types of references −
Entity References − An entity reference contains a name between the start and the end delimiters. For example & where amp is name. The name refers to a predefined string of text and/or markup.
Character References − These contain references, such as A
, contains a hash mark (“#”) followed by a number. The number always refers to the Unicode code of a character. In this case, 65 refers to alphabet "A".
0.3.3 XML Elements
- XML elements can be defined as building blocks of an XML. Elements can behave as containers to hold text, elements, attributes, media objects or all of these.
- Each XML document contains one or more elements, the scope of which are either delimited by start and end tags, or for empty elements, by an empty-element tag.
<element-name attribute1 attribute2>....content</element-name>
XML Elements Rules
- An element name can contain any alphanumeric characters. The only punctuation mark allowed in names are the hyphen (-), under-score (_) and period (.).
- Names are case sensitive. For example, Address, address, and ADDRESS are different names.
- Start and end tags of an element must be identical.
- An element, which is a container, can contain text or elements as seen in the above example.
0.3.4 Element Attribute Rules
Attributes are part of XML elements. An element can have multiple unique attributes. Attribute gives more information about XML elements. To be more precise, they define the properties of elements. An XML attribute is always a name-value pair.
Following are the rules that need to be followed for attributes −
- An attribute name must not appear more than once in the same start-tag or empty-element tag.
- An attribute must be declared in the Document Type Definition (DTD) using an Attribute-List Declaration.
- Attribute values must not contain direct or indirect entity references to external entities.
- The replacement text of any entity referred to directly or indirectly in an attribute value must not contain a less than sign (<)
Example
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE garden [
<!ELEMENT garden (plants)*>
<!ELEMENT plants (#PCDATA)>
<!ATTLIST plants category CDATA #REQUIRED>
]>
<garden>
<plants category = "flowers" />
<plants category = "shrubs">
</plants>
</garden>