Professional Documents
Culture Documents
Web development
HTML
What is HTML?
HTML is the standard markup language for creating
Web pages.
HTML stands for Hyper Text Markup Language
HTML describes the structure of Web pages using
markup
HTML elements are the building blocks of HTML
pages
HTML elements are represented by tags
HTML tags label pieces of content such as "heading",
"paragraph", "table", and so on
Browsers do not display the HTML tags, but use
them to render the content of the page
HTML is divided into three parts
1.Doctype
2.head
3.body
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The <!DOCTYPE html> declaration defines this
•
document to be HTML5
The <html> element is the root element of an
HTML page
The <head> element contains meta information
about the document
The <title> element specifies a title for the
document
The <body> element contains the visible page
content
The <h1> element defines a large heading The
<p> element defines a paragraph
HTML Tags
HTML tags are element names surrounded by angle
brackets:
<tagname>content goes here...</tagname>
tags.
<h1> defines the most important heading. <h6>
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
2.HTML Links
HTML links are defined with the <a> tag:
Example
<a href="https://www.w3schools.com">This is a
link</a>
The link's destination is specified in the href attribute.
HTML Images
HTML images are defined with the <img> tag.
width="104" height="142">
HTML Horizontal Rules
The <hr> tag defines a thematic break in an HTML
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>This paragraph contains a lot of lines in the
source code, but the browser ignores it.</p>
Example with Html Headings and paragraph tags
<!DOCTYPE html>
<html>
<body>
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
</body>
</html>
HTML Line Breaks
The HTML <br> element defines a line break.
<p>This is a paragraph.</p>
ocean.
</body>
</html>
HTML Table - Adding Border Spacing
Border spacing specifies the space between the cells.
To set the border spacing for a table, use the CSS border-spacing
property
<!DOCTYPE html>
<html>
<head>
<style> table, th, td {
border: 1px solid black; padding: 5px;
}
table {
border-spacing: 15px;
}
</style>
</head>
<body>
<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>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
HTML Table - Cells that Span Many Columns
To make a cell span more than one column, use the colspan
attribute:
<!DOCTYPE html>
<html>
<head>
<style> table, th, td {
border: 1px solid black; border-collapse: collapse;
}
th, td {
padding: 5px; text-align: left;
}
</style>
</head>
<h2>Cell that spans two columns:</h2>
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
</body>
</html>
HTML Table - Cells that Span Many Rows
To make a cell span more than one row, use the rowspan
attribute:
<!DOCTYPE html>
<html>
<head>
<style> table, th, td {
border: 1px solid black; border-collapse: collapse;
}
th, td {
padding: 5px; text-align: left;
}
</style>
</head>
<h2>Cell that spans two rows:</h2>
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>55577854</td>
</tr>
<tr>
<td>55577855</td>
</tr>
</table>
</body>
</html>
HTML Table - Adding a Caption
To add a caption to a table, use the <caption> tag:
<!DOCTYPE html>
<html>
<head>
<style> table, th, td {
border: 1px solid black; border-collapse:
collapse;
}
th, td {
padding: 5px; text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
•Use the HTML <table> element to define a table
•Use the HTML <tr> element to define a table row
•Use the HTML <td> element to define a table data
•Use the HTML <th> element to define a table heading
•Use the HTML <caption> element to define a table caption
•Use the CSS border property to define a border
•Use the CSS border-collapse property to collapse cell borders
•Use the CSS padding property to add padding to cells
•Use the CSS text-align property to align cell text
•Use the CSS border-spacing property to set the spacing
between cells
•Use the colspan attribute to make a cell span many columns
•Use the rowspan attribute to make a cell span many rows
3.HTML Lists
An unordered list starts with the <ul> tag. Each list item starts with
the <li> tag.
The list items will be marked with bullets (small black circles) by
default:
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Unordered HTML List - Choose List Item Marker
The CSS list-style-type property is used to define the style of the
list item marker:Value Description
disc Sets the list item marker to a bullet (default)
circle Sets the list item marker to a circle
square Sets the list item marker to a square
none The list items will not be marked
Example - Disc
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Circle
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Square
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - None
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li> </ul>
2.Ordered HTML List
An ordered list starts with the <ol> tag. Each list item starts with
the <li> tag.
The list items will be marked with numbers by default:
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Ordered HTML List - The Type Attribute
The type attribute of the <ol> tag, defines the type of the list item
marker:
Type Description
type="1" The list items will be numbered with numbers (default)
type="A" The list items will be numbered with uppercase letters
type="a" The list items will be numbered with lowercase letters
type="I" The list items will be numbered with uppercase roman
numbers
type="i" The list items will be numbered with lowercase roman
numbers
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Letters:
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Roman Numbers:
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Roman Numbers:
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li> </ol>
HTML Description Lists
HTML also supports description lists.
A description list is a list of terms, with a description of each term.
The <dl> tag defines the description list, the <dt> tag defines the
term (name), and the <dd> tag describes each term:
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Nested HTML Lists
List can be nested (lists inside lists):
Example
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
•Use the HTML <ul> element to define an unordered list
•Use the CSS list-style-type property to define the list item
marker
•Use the HTML <ol> element to define an ordered list
•Use the HTML type attribute to define the numbering type
•Use the HTML <li> element to define a list item
•Use the HTML <dl> element to define a description list
•Use the HTML <dt> element to define the description term
•Use the HTML <dd> element to describe the term in a description
list
•Lists can be nested inside lists
•List items can contain other HTML elements
•Use the CSS property float:left or display:inline to display a list
horizontally
4.Forms
The <form> Element
The HTML <form> element defines a form that is used to collect
user input:
<form>
.
form elements
.
</form>
An HTML form contains form elements.
Form elements are different types of input elements, like text fields,
checkboxes, radio buttons, submit buttons, and more.
Here is the list of <form> attributes:
Attribute Description
1. accept-charset Specifies the charset used in the submitted
form (default: the page charset).
2. action Specifies an address (url) where to submit the
form (default: the submitting page).
3. autocomplete Specifies if the browser should autocomplete
the form (default: on).
4. enctype Specifies the encoding of the submitted data
(default: is url-encoded).
5. method Specifies the HTTP method used when
submitting the form (default: GET).
6. name Specifies a name used to identify the form (for
DOM usage: document.forms.name).
7. novalidate Specifies that the browser should not validate
the form. target Specifies the target of the
address in the action attribute (default: _self).
The <input> Element
The <input> element is the most important form element.
The <input> element can be displayed in several ways, depending
on the type attribute.
Here are some examples:
Type Description
<input type="text"> Defines a one-line text input field
<input type="radio"> Defines a radio button (for selecting one
of many choices)
<input type="submit"> Defines a submit button (for submitting
the form)
The Action Attribute
The action attribute defines the action to be performed when the
form is submitted.
Normally, the form data is sent to a web page on the server when
the user clicks on the submit button.
In the example above, the form data is sent to a page on the
server called "/action_page.php". This page contains a server-side
script that handles the form data:
<form action="/action_page.php">
The browser's back button might not work as the user hopes.
There are still few browsers that do not support frame technology.
HTML <frameset> Tag
The <frameset> tag defines a frameset.
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.
The <frameset> tag is not supported in HTML5.
Note: If you want to validate a page containing frames, be sure
the <!DOCTYPE> is set to either "HTML Frameset DTD“
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag. The
<frameset> tag defines, how to divide the window into frames. The rows
attribute of <frameset> tag defines horizontal frames and cols attribute
defines vertical frames. Each frame is indicated by <frame> tag and it defines
which HTML document shall open into the frame.
Attribute Value Description
Let's see following example where a test.htm file has following code
Here, we have created two columns to fill with two frames. The first frame is
200 pixels wide and will contain the navigation menu bar implemented by
menu.htm file. The second column fills in remaining space and will contain the
main part of the page and it is implemented by main.htm file. For all the three
links available in menu bar, we have mentioned target frame as main_page, so
whenever you click any of the links in menu bar, available link will open in main
page.
TARGET Attribute Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Target Frames</title>
</head>
<noframes>
<body>Your browser does not support frames.</body>
</noframes>
</frameset>
</html>
Following is the content of menu.htm file
<!DOCTYPE html>
<html>
<body bgcolor = "#4a7d49">
<a href = "http://www.google.com" target = "main_page">Google</a>
<br />
<br />
<a href = "http://www.microsoft.com" target =
"main_page">Microsoft</a>
<br />
<br />
<a href = "http://news.bbc.co.uk" target = "main_page">BBC News</a>
</body>
</html>
Following is the content of main.htm file
<!DOCTYPE html>
<html>
</html>
iframe tag Example
You can define an inline frame with HTML tag <iframe>. The <iframe> tag is not
somehow related to <frameset> tag, instead, it can appear anywhere in your document.
The <iframe> tag defines a rectangular region within the document in which the
browser can display a separate document, including scrollbars and borders. An inline
frame is used to embed another document within the current HTML document.
The src attribute is used to specify the URL of the document that occupies the inline
frame.
<!DOCTYPE html>
<html>
<head>
<title>HTML Iframes</title>
</head>
<body>
<p>Document content goes here...</p>
<iframe src = "/html/menu.htm" width = "555" height = "200">
Sorry your browser does not support inline frames.
</iframe>
<p>Document content also go here...</p>
</body>
</html>
Document content also go here...
6.stylesheet
Styling HTML with CSS
CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on
screen, paper, or in other media.
CSS saves a lot of work. It can control the layout of multiple web
pages all at once.
CSS can be added to HTML elements in 3 ways:
•Inline - by using the style attribute in HTML elements
•Internal - by using a <style> element in the <head> section
•External - by using an external CSS file
The most common way to add CSS, is to keep the styles in
separate CSS files. However, here we will use inline and internal
styling, because this is easier to demonstrate, and easier for you
to try it yourself.
Inline CSS
An inline CSS is used to apply a unique style to a single HTML
element.
An inline CSS uses the style attribute of an HTML element.
This example sets the text color of the <h1> element to blue:
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML
page, within a <style> element:
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;} h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
External CSS
An external style sheet is used to define the style for many HTML
pages.
With an external style sheet, you can change the look of an
entire web site, by changing one file!
To use an external style sheet, add a link to it in the <head>
section of the HTML page:
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.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. The file
must not contain any HTML code, and must be saved with a .css
extension.
Here is how the "styles.css" looks: body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
CSS Fonts
The CSS color property defines the text color to be used. The CSS font-family property
defines the font to be used. The CSS font-size property defines the text size to be used.
<!DOCTYPE html>
<html>
<head>
<style> h1 {
color: blue;
font-family: verdana; font-size: 300%;
}
p {
color: red;
font-family: courier; font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Border
The CSS border property defines a border around an HTML element:
<!DOCTYPE html>
<html>
<head>
<style> p {
border: 1px solid powderblue;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
CSS Padding
The CSS padding property defines a padding (space) between the text and the
border:
<!DOCTYPE html>
<html>
<head>
<style> p {
border: 1px solid powderblue; padding: 30px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
CSS Margin
The CSS margin property defines a margin (space) outside the border:
<!DOCTYPE html>
<html>
<head>
<style> p {
border: 1px solid powderblue; margin: 50px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
The id Attribute
To define a specific style for one special element, add an id attribute to
the element:
<!DOCTYPE html>
<html>
<head>
<style> #p01 {
color: blue;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p id="p01">I am different.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style> p.error {
color: red;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p class="error">I am different.</p>
<p>This is a paragraph.</p>
<p class="error">I am different too.</p>
</body>
</html>
External References
External style sheets can be referenced with a full URL or with a
path relative to the current web page.
This example uses a full URL to link to a style sheet:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="https://www.w3schools.com/html/styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This example links to a style sheet located in the html folder on
the current website:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/html/styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This example links to a style sheet located in the same folder as
the current page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
•Use the HTML style attribute for inline styling
•Use the HTML <style> element to define internal CSS
•Use the HTML <link> element to refer to an external CSS file
•Use the HTML <head> element to store <style> and <link>
elements
•Use the CSS color property for text colors
•Use the CSS font-family property for text fonts
•Use the CSS font-size property for text sizes
•Use the CSS border property for borders
•Use the CSS padding property for space inside the border
•Use the CSS margin property for space outside the border