Professional Documents
Culture Documents
Html5 Notes
Html5 Notes
Html5 Notes
HTML is the main markup language for describing the structure of web pages.
HTML stands for HyperText Markup Language. HTML is the basic building
block of World Wide Web.
Apart from text, hypertext may contain tables, lists, forms, images, and other
presentational elements. It is an easy-to-use and flexible format to share
information over the Internet.
Tip: Our HTML tutorial will help you to learn the fundamentals of the latest
HTML5 language, from the basic to advanced topics step-by-step. If you're a
beginner, start with the basic section and gradually move forward by learning
a little bit every day.
What You Can Do with HTML
There are lot more things you can do with HTML.
You can publish documents online with text, images, lists, tables, etc.
You can access web resources such as images, videos or other HTML
document via hyperlinks.
You can create forms to collect user inputs like name, e-mail address,
comments, etc.
You can include images, videos, sound clips, flash movies, applications and
other HTML documents directly inside an HTML document.
You can create offline version of your website that work without internet.
You can store data in the user's web browser and access later on.
You can find the current location of your website's visitor.
The list does not end here, there are many other interesting things that you
can do with HTML. You will learn about all of them in detail in upcoming
chapters.
Getting Started
Here, you will learn how easy it is to create an HTML document (i.e. a web
page). To begin coding HTML you need only two stuff: a simple-text editor
and a web browser.
Tip: We suggest you to use only the simplest text editors such as Notepad
(under Windows), TextEdit (on the Mac). Once you understand the basic
principles, you may switch to more advanced tools such as Dreamweaver.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple HTML document</title>
</head>
<body>
<p>Hello World!<p>
</body>
</html>
Note: It is important that the extension .html is specified — some text editors,
such as Notepad, will automatically save it as .txt otherwise.
To open the file in a browser. Navigate to your file then double click on it. It
will open in your default Web browser. (If it does not, open your browser and
drag the file to it.)
Explanation of code
You might think what that code was all about. OK, let's get straight into it.
DOCTYPE declaration — A line defines the HTML5 document type.
A declarative header section (enclosed by the HEAD element) — Provides
information about the document, including its title, style information, and
scripts.
A document body (enclosed by the BODY element) — Contains the
document's actual content that is rendered in the web browser and displayed
to the user.
You will learn about the various elements of the HTML document in the
coming lessons. We suggest you experiment with everything you learn here.
HTML tags normally come in pairs like <html> and </html>. The first tag in a pair
is often called the opening tag (or start tag), and the second tag is called the
closing tag (or end tag).
An opening tag and a closing tag are identical, except a slash (/) after the
opening angle bracket of the closing tag, to tell the browser that the
command has been completed. In between these tags you can add headings,
paragraphs of text, tables, forms, images, videos etc. For example, a
paragraph, which is represented by the p element, would be written as:
<p>This is a paragraph.</p>
HTML Elements
An HTML element is an individual component of an HTML document.
Note: All elements don't require the end tag to be present. These are referred
as empty elements, self-closing elements or void elements. Learn more.
However, in common usage the terms HTML element and HTML tag are
interchangeable i.e. a tag is an element is a tag. For simplicity's sake of this
website, the terms "tag" and "element" are used to mean the same thing — as
it will define something on your web page.
Tip: We recommend using lowercase for tag and attributing names in HTML,
since by doing this you can make your document more compliant for future
upgrades.
HTML Attributes
Certain parameters are frequently included within the opening tag to provide
additional element properties (such as colorization, measurement, location,
alignment, or other appearances) to the data between the markup tags. These
parameters are called Attributes.
Note: Attributes are always specified in the start tag (or opening tag), and
they can only contain the value of the attribute.
Attribute Values
Most attributes require a value. In HTML, the value can be left unquoted if it
doesn't include spaces (name=value), or it can be quoted with single or double
quotes (name='value' or name="value"). By the way, it is recommended to
enclose Attribute values in quotes.
Tip: In some rare situations, when the attribute value itself contains quotes, it
is necessary to wrap attribute value inside single quotes: name='John
''Williams'' Jr.'
Attribute Example
In the example below href is attribute and the link provided is its value.
HTML links are defined with the <a> tag. You will learn about links in
upcoming tutorials.
Example
Try this code »
HTML Headings
Headings help in defining the hierarchy and the structure of the web page.
HTML Headings
HTML uses six levels of heading tags <h1> to <h6>; the higher the heading level
number, the greater it's importance — so <h1> defines the most important
heading, whereas the <h6> defines the least important heading in the
document.
Example
Try this code »
Tip: A document generally should have exactly one <h1> element to mark the
most important heading, followed by the <h2>, <h3> and so on.
HTML Paragraphs
Paragraph element used to publish text on the web pages.
HTML Paragraphs
Paragraphs are defined with the <p> tag. Paragraph tag is very basic and
typically the first tag you will need to publish your text on the web pages.
Example
Try this code »
1. <p>This is a paragraph.</p>
2. <p>This is another paragraph.</p>
Note: Browsers built-in style sheets automatically create some space above
and below the content of a paragraph, but you can override it using CSS.
1. <p>This is a paragraph.
2. <p>This is another paragraph.
The example above will work in most of the browsers, but don't rely on it.
Forgetting the end tag can produce unexpected results or errors.
Example
Try this code »
HTML Comments
Comments are usually added with the purpose of making the source code
easier to understand. It may help other developer (or you in the future when
you edit the source code) to understand what you were trying to do with the
HTML. Comments are significant to programmers but typically ignored by
browsers.
An HTML comment begins with <!--, and ends with -->, See the example
below:
Example
Try this code »
HTML Spaces
Normally the browser will display the multiple spaces created inside the HTML
code by pressing the space-bar key on the keyboard as one space, while
multiple line breaks created through pressing the enter key also displayed as
single space. Insert for creating extra spaces, and <br> tag to create line
breaks inside your HTML document.
Example
Try this code »
1. <p>multiple spaces.</p>
2. <p>multiple<br><br>line<br><br><br>breaks.</p>
HTML Links
A link or hyperlink is a connection from one web resource to another.
However you can overwrite this using CSS. Learn more about styling links.
The href attribute in source anchor specifies the address of the destination
anchor.
Example
Try this code »
Example
Try this code »
Example
Try this code »
Example
Try this code »
Example
Try this code »
Example
Try this code »
Note: The <strong> and <em> tags are "logical" tags. Use these tags when the
content of your page requires that certain words or phrases be stressed, and if
you want highlighting words only for visual effect, use the <b> and <i> tags.
HTML Styles
Style rules describe how documents are presented on the web browsers.
With CSS, it becomes easy to specify the colors used for the text and the
backgrounds, the size and the style for the fonts, the amount of space
between elements, adding border and outlines to the elements and a host of
other styling.
Inline styles — Using the style attribute in the HTML start tag.
Embedded style — Using the <style> element in the head section of the
document.
External style sheet — Using the <link> element, pointing to an external CSS
files.
In this tutorial we will cover all these different types of style sheet one by one:
Inline Styles
Inline styles are used to apply the unique style rules to an element by putting
the CSS rules directly into the start tag. It can be attached to an element using
the style attribute.
The style attribute includes a series of CSS property and value pairs.
Each property: value pair is separated by a semicolon (;), just as you would
write into an embedded or external style sheet. But it needs to be all in one
line i.e. no line break after the semicolon.
The following example will show you how to change the color and font-
size of the text:
Example
Try this code »
Example
Try this code »
1. <head>
2. <style type="text/css">
3. body {background-color: YellowGreen;}
4. p {color: Black;}
5. </style>
6. </head>
An external style sheet holds all the style rules in a separate document that
you can link from any HTML file on your site. External style sheets are the most
flexible because with an external style sheet, you can change the look of an
entire website by changing just one file.
You can attach external style sheets in two ways — linking and importing:
Example
Try this code »
1. <head>
2. <link rel="stylesheet" type="text/css" href="css/style.css">
3. </head>
You can use it in two ways. The simplest is within the header of your
document. Note that, other CSS rules may still be included in
the <style> element.
Example
Try this code »
1. <style type="text/css">
2. @import url("css/style.css");
3. p {
4. color: blue;
5. font-size: 16px;
6. }
7. </style>
Similarly, you can use the @import rule to import a style sheet within another
style sheet.
Example
Try this code »
1. @import url("css/layout.css");
2. @import url("css/color.css");
3. body {
4. color: blue;
5. font-size: 14px;
6. }
Note: All @import rules must occur at the start of the style sheet. Any style rule
defined in the style sheet itself override conflicting rule in the imported style
sheets.
HTML Images
Images improve the appearance and illustrate many concepts of the web
pages.
Example
Try this code »
Note: The required alt attribute provides alternative information for an image
if a user for some reason cannot able to view it because of slow connection, an
error in the src attribute, or if the user uses a screen reader.
Example
Try this code »
HTML Tables
The HTML table allows to arrange data like, text, images, links, forms, form
fields, other tables, etc. into rows and columns of cells.
A table is divided into rows with the <tr> tag, which stands for table row, and
each row is divided into data cells with the <td> tag, which stands for table
data.
A <td> tag can contain text, links, images, lists, forms, other tables, etc.
Example
Try this code »
<table border="1">
<thead>
<tr>
<th>No.</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Peter Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td>John Rambo</td>
<td>johnrambo@mail.com</td>
</tr>
</tbody>
</table>
Note: Browsers built-in style sheets will display the text in the <th> element as
bold and centered. But, you can override browser's default style sheet
using CSS.
Table Cellpadding and Cellspacing
The cellpadding and cellspacing attributes are used to adjust white space inside
a table.
cellpadding adjust the white space between table cell border and its content.
cellspacing adjust the white space between table cells.
Example
Try this code »
Normally, when we creating a table cell, it cannot pass over into the space
below or above another table cell. But, you can use the colspan attribute to
span multiple columns and rowspan attribute to span multiple rows in a table.
Here's is an example:
Example
Try this code »
<table border="1">
<tr>
<th rowspan="4">Users Info</th>
</tr>
<tr>
<td>1</td>
<td>John Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Peter Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td>John Rambo</td>
<td>johnrambo@mail.com</td>
</tr>
</table>
HTML Lists
HTML lists are used to group related pieces of information together.
Note: Inside a list item you can put text, line breaks, images, links, etc. You can
also place an entire list inside a list item to create nested list.
In this tutorial we will cover all these different list types one by one:
The list items in unordered lists are marked with bullets (small black circles), by
default.
Example
Try this code »
1. <ul>
2. <li>Chocolate Cake</li>
3. <li>Black Forest Cake</li>
4. <li>Pineapple Cake</li>
5. </ul>
— The output of the above example will look something like this:
Chocolate Cake
Black Forest Cake
Pineapple Cake
1. <ol>
2. <li>Mix ingredients</li>
3. <li>Bake in oven for an hour</li>
4. <li>Allow to stand for ten minutes</li>
5. </ol>
— The output of the above example will look something like this:
1. Mix ingredients
2. Bake in oven for an hour
3. Allow to stand for ten minutes
The definition list created using <dl> tag. The <dl> tag is used in conjunction
with <dt> — defines the item in the list, and <dd> describes the item in the list:
Example
Try this code »
1. <dl>
2. <dt>Bread</dt>
3. <dd>A baked food made of flour.</dd>
4. <dt>Coffee</dt>
5. <dd>A drink made from roasted coffee beans.</dd>
6. </dl>
— The output of the above example will look something like this:
Bread
Coffee
HTML Forms
An HTML form is a section of document that contains interactive controls that
enable a user to submit information to a web server.
The <form> tag is used to create an HTML form. Here's a simple example of a
login form:
Example
Try this code »
1. <form>
2. <fieldset>
3. <legend>Log In</legend>
4. <label>Username: <input type="text"></label>
5. <label>Password: <input type="password"></label>
6. <input type="submit" value="Submit">
7. </fieldset>
8. </form>
The following section describes different types of controls that you can use in
your form.
Input Element
This is the most commonly used element within HTML forms.
It allows you to specify various types of user input fields, depending on the
type attribute. An input element can be of type text field, checkbox, password
field, radio button, submit button, reset button, etc. and several new input
types introduced in HTML5.
Text Fields
Text fields are one line areas that allow the user to input text.
Example
Try this code »
1. <form>
2. <label for="username">Username:</label>
3. <input type="text" name="username" id="username">
4. </form>
— The output of the above example will look something like this:
Note: The <label> tag to define labels for <input> elements. If you want your
user to enter several lines you should use a <textarea> instead.
Password Field
Password fields are similar to text fields. The only difference is; characters in a
password field are masked i.e. shown as asterisks or dots. This is to prevent
others from reading the password on the screen. This is also a single-line text
input controls created using an <input> element whose typeattribute has a
value of password.
Example
Try this code »
1. <form>
2. <label for="user-pwd">Password:</label>
3. <input type="password" name="user-password" id="user-pwd">
4. </form>
— The output of the above example will look something like this:
Radio Buttons
Radio buttons are used to let the user select exactly one option from a pre-
defined set of options. It is created using an <input> element
whose type attribute has a value of radio.
Example
Try this code »
1. <form>
2. <input type="radio" name="sex" id="male">
3. <label for="male">Male</label>
4. <input type="radio" name="sex" id="female">
5. <label for="female">Female</label>
6. </form>
— The output of the above example will look something like this:
Note: If you want to allow your user to select more than one option at the
same time you should use the check boxes instead.
Checkboxes
Checkboxes allows the user to select one or more option from a pre-defined
set of options. It is created using an <input> element whose type attribute has a
value of checkbox.
Example
Try this code »
1. <form>
2. <input type="checkbox" name="sports" id="soccer">
3. <label for="soccer">Soccer</label>
4. <input type="checkbox" name="sports" id="cricket">
5. <label for="cricket">Cricket</label>
6. <input type="checkbox" name="sports" id="baseball">
7. <label for="baseball">Baseball</label>
8. </form>
— The output of the above example will look something like this:
This is also created using an <input> element, whose type attribute value is set
to file.
Example
Try this code »
1. <form>
2. <label for="file-select">Upload:</label>
3. <input type="file" name="upload" id="file-select">
4. </form>
— The output of the above example will look something like this:
Textarea
Textarea is a multiple-line text input control that allows a user to enter more
than one line of text. Multi-line text input controls are created using
an <textarea> element.
Example
Try this code »
1. <form>
2. <label for="address">Address:</label>
3. <textarea rows="3" cols="30" name="address" id="address"></textarea>
4. </form>
— The output of the above example will look something like this:
Select Boxes
A select box is a dropdown list of options that allows user to select one or
more option from a pull-down list of options. Select box is created using
the <select> element and <option> element. The option elements within
the <select> element define each list item.
Example
Try this code »
1. <form>
2. <label for="city">City:</label>
3. <select name="city" id="city">
4. <option value="sydney">Sydney</option>
5. <option value="melbourne">Melbourne</option>
6. <option value="cromwell">Cromwell</option>
7. </select>
8. </form>
— The output of the above example will look something like this:
Example
Try this code »
1. <form action="action.php" method="post" id="users">
2. <label for="first-name">First Name:</label>
3. <input type="text" name="first-name" id="first-name">
4. <input type="submit" value="Submit">
5. <input type="reset" value="Reset">
6. </form>
— The output of the above example will look something like this:
Type your name in the text field above, and click on submit button to see it in
action.
Note: you can also create buttons using the <button> element. Buttons
created with the <button> element function just like buttons created with the
input element, but they offer richer rendering possibilities.
action URL of the program that processes the information submitted via form.
method The HTTP method that the browser uses to submit the form. Possible values are get and post.
target A name or keyword indicating the target page where the result of the script will be displayed. The res
keywords are _blank, _self, _parent and _top.
Note: The name attribute has been included for backwards compatibility. You
should instead use the id attribute to identify elements.
HTML iFrame
An iframe is used to display a web page within another web page
What is iframe
An iframe or inline frame is used to display external objects including other
web pages within a web page. The basic syntax for adding an iframe can be
given with:
<iframe src="URL">
alternative content for browsers which do not support iframe.
</iframe>
Example
Try this code »
Example
Try this code »
An iframe can be named using the name attribute. This implies that when a link
with a targetattribute with that name as value is followed, the linked resource
is opened in the iframe.
Example
Try this code »
HTML Doctypes
A Document Type Declaration, or DOCTYPE, is an instruction to the Web
browser about the version of markup language in which a page is written.
HTML5 Doctype
A DOCTYPE declaration appears at the top of a web page before all other
elements. According to the HTML specification or standards, every HTML
document requires a document type declaration to insure that your pages are
displayed the way they are intended to be displayed. The doctype declaration
is usually the very first thing defined in an HTML document; however the
doctype declaration itself is not an HTML tag.
Doctypes from earlier versions of HTML were longer because the HTML
language was SGML-based and therefore required a reference to a DTD, but
they are obsolete now. With HTML5 this is no longer the case and the doctype
declaration is only needed to enable the standard mode for documents
written using the HTML syntax.
You can use the following markup as a template to create a new HTML5
document that uses the latest HTML5 doctype declaration.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<!-- Insert your content here -->
</body>
</html>
Note: The doctype declaration refers to a Document Type Definition (DTD). It
is an instruction to the web browser about what version of the markup
language the page is written in. The W3C provides DTDs for all HTML versions.
Warning: The <frameset> and <frame> elements has been removed from
HTML5 and should no longer be used. Therefore, frameset DTD is no longer
valid.
For documents that use this DTD, use the following DOCTYPE declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
Tip: Must add a doctype to your HTML/XHTML document and use the W3C's
Validator to check the markup or syntax error before publishing online.
HTML Layout
Web page layout is an essential part of creating well-formed, well-structured,
semantically-rich websites.
You can find, most of the websites on the internet have put their content in
multiple rows and columns — formatted like a magazine or newspaper, to give
general web users a better reading and writing environment. This can be easily
achieved by using the <table>, <div> or <span> tags and adding
some styles to them.
The following HTML layout is achieved using a table with 3 rows and 2
columns — the first and last row spans both columns using
the colspan attribute:
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Table Layout</title>
</head>
<body style="margin:0px;">
<table cellpadding="10px;" cellspacing="0" style="font:12px verdana, sans-serif;
width:100%;">
<tr>
<td colspan="2" style="background-color:#679BB7;">
<h1 style="font-size:18px; margin:10px 0;">Tutorial Republic</h1>
</td>
</tr>
<tr style="height:170px;">
<td style="background-color:#bbd2df; width:20%; vertical-align:top;">
<ul style="list-style:none; padding:0px; margin:0px;">
<li style="margin-bottom:5px;"><a href="#"
style="color:#3d677e;">Home</a></li>
<li style="margin-bottom:5px;"><a href="#"
style="color:#3d677e;">About</a></li>
<li style="margin-bottom:5px;"><a href="#"
style="color:#3d677e;">Contact</a></li>
</ul>
</td>
<td style="background-color:#f0f0f0; width:80%; vertical-align:top;">
<h2 style="font-size:16px; margin:0px;">Welcome to our site</h2>
<p>Here you will learn to create websites...</p>
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#679BB7;">
<p style="text-align:center; margin:5px;">copyright ©
tutorialrepublic.com</p>
</td>
</tr>
</table>
</body>
</html>
— The HTML code above will produce the following output:
Warning: The method used for creating layout in the above example is not
wrong, but it's not recommended. Avoid tables and inline styles for creating
layout.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Div Layout</title>
<style type="text/css">
body{
font: 12px verdana, sans-serif;
margin: 0px;
}
.header{
padding: 10px 0;
background-color: #679BB7;
}
.header h1{
font-size: 18px;
margin: 10px;
}
.container{
width: 100%;
background-color: #f0f0f0;
}
.sidebar{
float: left;
width: 20%;
min-height: 170px;
background-color: #bbd2df;
}
.sidebar .nav{
padding: 10px;
}
.nav ul{
list-style: none;
padding: 0px;
margin: 0px;
}
.nav ul li{
margin-bottom: 5px;
}
.nav ul li a{
color: #3d677e;
}
.nav ul li a:hover{
text-decoration: none;
}
.content{
float: left;
width: 80%;
min-height: 170px;
}
.content .section{
padding: 10px;
}
.content h2{
font-size: 16px;
margin: 0px;
}
.clearfix{
clear: both;
}
.footer{
background-color: #679BB7;
padding: 10px 0;
}
.footer p{
text-align: center;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Tutorial Republic</h1>
</div>
<div class="wrapper">
<div class="sidebar">
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="section">
<h2>Welcome to our site</h2>
<p>Here you will learn to create websites...</p>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="footer">
<p>copyright © tutorialrepublic.com</p>
</div>
</div>
</body>
</html>
— The HTML code above will produce the same output as the previous
example:
Tip: Better layouts can be created by using DIV, SPAN and CSS. You can
change the layout of all the pages of your website by just editing a CSS file. To
learn more about CSS, please check out CSS tutorial.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Web Page Layout</title>
<style type="text/css">
body{
font: 12px verdana, sans-serif;
margin: 0px;
}
header{
background-color: #679BB7;
padding: 10px;
}
header h1{
font-size: 18px;
margin: 10px 0;
}
.container{
width: 100%;
background-color: #f0f0f0;
}
.sidebar{
float: left;
width: 20%;
min-height: 170px;
background-color: #bbd2df;
}
.sidebar nav{
padding: 10px;
}
nav ul{
list-style: none;
padding: 0px;
margin: 0px;
}
nav ul li{
margin-bottom: 5px;
}
nav ul li a{
color: #3d677e;
}
nav ul li a:hover{
text-decoration: none;
}
.content{
float: left;
width: 80%;
min-height: 170px;
}
.content section{
padding: 10px;
}
section h2{
font-size: 16px;
margin: 0px;
}
.clearfix:after{
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
footer{
background-color: #679BB7;
padding: 10px;
}
footer p{
text-align: center;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>Tutorial Republic</h1>
</header>
<div class="wrapper clearfix">
<div class="sidebar">
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
<div class="content">
<section>
<h2>Welcome to our site</h2>
<p>Here you will learn to create websites...</p>
</section>
</div>
</div>
<footer>
<p>copyright © tutorialrepublic.com</p>
</footer>
</div>
</body>
</html>
— The HTML code above will also produce the same output as the previous
example:
Tag Description
<details> Represents a widget from which the user can obtain additional information or controls on-demand
HTML Head
The head element is the container for all the head elements, provide extra
information about the page, or reference other resources that are required for
the page to display or behave correctly.
The title of the document may be used for different purposes. For example:
To display a title in the browser title bar and in the task bar.
To provide a title for the page when it is added to favorites or bookmarked.
To displays a title for the page in search-engine results.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World Document</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
Tip: A good title should be short and specific to the document's content,
because search engine's web crawlers pay particular attention to the words
used in the title. The title should ideally be less than 65 characters in
length. Learn more.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<title>Defining a base URL</title>
<base href="https://www.tutorialrepublic.com/">
</head>
<body>
<p><a href="html-tutorial/html-head.php">HTML Head</a>.</p>
</body>
</html>
The link above will actually resolve to https://www.tutorialrepublic.com/html-
tutorial/html-head.php regardless of the URL of the current page. This is
because the relative URL indicated in the HTML Tutorial link: html-
tutorial/html-head.php is added to the end of the base
URL: https://www.tutorialrepublic.com/.
Warning: The HTML <base> element must appear before any element that
refers to an external resource. HTML permits only one base element for each
document.
Example
Try this code »
1. <head>
2. <title>Linking to style sheets</title>
3. <link type="text/css" rel="stylesheet" href="style.css">
4. </head>
To learn more about linking stylesheets, please check out tutorial on HTML
styles.
Example
Try this code »
<head>
<title>Internal style sheet</title>
<style type="text/css">
body { background-color: YellowGreen; }
h1 { color: red; }
p { color: green; }
</style>
</head>
Note: An embedded style sheet should be used when a single document has a
unique style. If the same style sheet is used in multiple documents, then an
external style sheet would be more appropriate. Learn more.
HTML Meta
The meta elements used to provide structured metadata about a web page.
META's name attribute provides a property name while the content attribute
gives the corresponding value. The content attribute value may contain text
and entities, but it may not contain HTML tags. There is no standard list of
meta properties, so you may define whatever metadata they like. Here's is an
example:
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="author" content="John Carter">
<title>Defining Document's Author</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
The <meta> tag in the example above simply defines the author of the
document.
Note: Metadata will not be displayed on the page, but will be machine
parsable, and can be used by browsers, search engines or other web services.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Declaring Character Encoding</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
However, to set character encoding inside CSS document, the @charset at-rule
is used.
Note: UTF-8 is a very versatile and recommended character encoding to
choose. However, if this is not specified, then the default encoding of the
platform is used.
Keywords and Description for Search Engines
Some search engines use metadata, especially keywords and descriptions to
index web pages; however this may not necessarily be true. Keywords giving
extra weight to a document's keywords and description provide a short
synopsis of the page. The meta tags in the following example define the
keywords and description of a page.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="keywords" content="HTML, CSS, References">
<meta name="description" content="Tutorials on HTML and CSS">
<title>Defining Keywords and Description</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
Tip: Search engines will often use the meta description of a page to create
short synopsis for the page when it appear in search results. Learn more.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Enable Zooming in Mobile Devices</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
Tip: Always use the <meta> viewport tag in your web pages. It will make your
website more accessible on mobile devices like cell phones and tablets.
HTML Script
The script element is used to embed or reference JavaScript within an HTML
document to add interactivity or affect the behavior of web pages.
Client-side Scripting
Client-side scripting refers to the type of computer programs that are
executed by the user's web browser. JavaScript is the most popular client-side
scripting language on the web.
Common uses for JavaScript are form validation, generate a pop-up alert box
message, creating image gallery, dynamic changes of content, etc.
The script in the example below writes Hello World! to the HTML output:
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Embedded JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
</body>
</html>
Tip: Ideally, scripts should be placed at the bottom of the page, because
scripts block parallel downloads. That will make your web pages load faster.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>External JavaScript Example</title>
</head>
<body>
<script type="text/javascript" src="hello.js"></script>
</body>
</html>
The noscript element can contain all the HTML elements that you'd include
inside the <body> element of a normal HTML page.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>No-script Example</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script>
<noscript>
<p>Sorry, your browser does not support JavaScript!</p>
</noscript>
</body>
</html>
Note: The content inside the noscript element will only be displayed if scripts
are not supported, or are disabled in the user's browser.
HTML Entities
Character entity references, or entities for short, enable you to use characters
that cannot be expressed in the document's character encoding or that cannot
be entered by a keyboard , e.g. copyright symbol ©.
To display these special characters, they must be replaced with the character
entities.
Note: Entities names are case sensitive! Check out HTML Character
Entities reference for a complete list of character entities.
HTML URL
URL stands for Uniform Resource Locator or Universal Resource Locator. A URL
is a specific character string that constitutes a reference to an Internet
resource.
What is URL
URL is the global address of documents and other resources on the World
Wide Web. Its main purpose is to identify the location of a document and
other web resources available on the Internet, and specify the mechanism for
accessing it through a web browser.
For instance, if you look at the address bar of your browser you will see:
https://www.tutorialrepublic.com/html-tutorial/html-url.php
— This is the URL of the web page you are viewing right now.
Scheme name — The scheme identifies the protocol to be used to access the
resource on the Internet. The scheme names followed by the three
characters :// (a colon and two slashes). The most commonly used protocols
are http://, https://, ftp://, and mailto://.
Host name — The host name identifies the host where resource is located. A
hostname is a domain name assigned to a host computer. This is usually a
combination of the host's local name with its parent domain's name. For
example, www.tutorialrepublic.com consists of host's machine name www and
the domain name tutorialrepublic.com.
Port Number — Servers often deliver more than one type of service, so you
must also tell the server what service is being requested. These requests are
made by port number. Well-known port numbers for a service are normally
omitted from the URL. For example, web service HTTP is commonly delivered
on port 80.
Path — The path identifies the specific resource within the host that the user
wants to access. For example, /html/html-url.php
Query String — The query string contains data to be passed to server-side
scripts, running on the web server. For example, parameters for a search. The
query string preceded by a question mark, is usually a string of name and
value pairs separated by ampersands, for
example, ?first_name=John&last_name=Corner.
Fragment identifier — The fragment identifier, if present, specifies a part or a
position within the overall resource or document. The fragment identifier
introduced by a hash mark "#" is the optional last part of a URL for a
document.
When fragment identifier used with HTTP, it usually specifies a section or
location within the page, and the browser may scroll to display that part of the
page.
Note: Scheme and host components of a URL are not case-sensitive, but path
and query string are case-sensitive. Usually the whole URL is specified in lower
case.
Reserved Characters
Certain characters are "reserved" because they may (or may not) be defined as
delimiters by the generic syntax in a particular URL scheme. For example,
forward slash / characters are used to separate different parts of a URL.
If data for a URL component contains character that would conflict with a
reserved set of characters, which is defined as a delimiter in the URL scheme
then the conflicting character must be percent-encoded before the URL is
formed. Reserved characters in a URL are:
! # $ & ' ( ) * + , / : ; = ? @ [
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5
Unreserved Characters
Characters that are allowed in a URL but do not have a reserved purpose are
called unreserved. These include uppercase and lowercase letters, decimal
digits, hyphen, period, underscore, and tilde. The following table lists all the
unreserved characters in a URL:
A B C D E F G H I J K L M N O P Q R S T U V W X
a b c d e f g h i j k l m n o p q r s t u v w x
0 1 2 3 4 5 6 7 8 9 - _ . ~
Enter some character and click on encode or decode button to see the output.
PREVIOUS PAGEN
HTML Validation
HTML validation is the process of checking the code against the formal
guidelines and standards set by the Wide Web Consortium (W3C) for
HTML/XHTML Web pages.
Validating a Website
Validating a website is the process of ensuring that the pages on the website
conform to the norms or standards defined by the World Wide Web
Consortium (W3C).
There are several specific reasons for validating a website, some of them are:
Note: Validation is important. It will ensure that your web pages are
interpreted in the same way (the way you want it) by the various web
browsers, search engines etc. as well as users and visitors of your Web site.
Follow the link given below to validate your HTML/XHTML document. It will
automatically detect whether you're using HTML or XHTML, and which
doctype you're using.
W3.org's HTML Validator