HTML
HTML
What is Internet?
The Internet is essentially a global network of computing resources. You can think of the
Internet as a physical collection of routers and circuits as a set of shared resources.
Some common definitions given in the past include −
Internet-Based Services
Some of the basic services available to Internet users are −
Email − A fast, easy, and inexpensive way to communicate with other Internet users
around the world.
Telnet − Allows a user to log into a remote computer as though it were a local
system.
FTP − Allows a user to transfer virtually every kind of file that can be stored on a
computer from one Internet-connected computer to another.
UseNet news − A distributed bulletin board that offers a combination news and
discussion service on thousands of topics.
World Wide Web (WWW) − A hypertext interface to Internet information resources.
What is WWW?
WWW stands for World Wide Web. A technical definition of the World Wide Web is − All the
resources and users on the Internet that are using the Hypertext Transfer Protocol (HTTP).
In simple terms, The World Wide Web is a way of exchanging information between
computers on the Internet, trying them together into a vast collection of interactive
multimedia resources.
What is HTTP?
HTTP stands for Hypertext Transfer Protocol. This is the protocol being used to transfer
hypertext documents that makes the World Wide Web possible.
A standard web address such as Yahoo.com is called a URL and here the prefix http
indicates its protocol
What is URL?
URL stands for Uniform Resource Locator, and is used to specify addresses on the World
Wide Web. A URL is the fundamental network identification for any resource connected to
1
ACMS
protocol://hostname/other_information
The protocol specifies how information is transferred from a link. The protocol used for
web resources is HyperText Transfer Protocol (HTTP). Other protocols compatible with
most web browsers include FTP, telnet, newsgroups, and Gopher.
The protocol is followed by a colon, two slashes, and then the domain name. The domain
name is the computer on which the resource is located.
Links to particular files or subdirectories may be further specified after the domain name.
The directory names are separated by single forward slashes.
https://msbte.engg-info.website/msbte-model-answer-paper-summer-winter
What is Website?
website is a collection of various pages written in HTML markup language. This is a
location on the web where people can find tutorials on latest technologies. Similarly, there
are millions of websites available on the web.
Each page available on the website is called a web page and first page of any website is
called home page for that site.
2
ACMS
SMTP stands for Simple Mail Transfer Protocol Server. This server takes care of delivering
emails from one server to another server. When you send an email to an email address, it
is delivered to its recipient by a SMTP Server.
What is ISP?
ISP stands for Internet Service Provider. They are the companies who provide you service
in terms of internet connection to connect to the internet.
You will buy space on a Web Server from any Internet Service Provider. This space will be
used to host your Website.
What is HTML?
HTML stands for Hyper Text Markup Language. This is the language in which we write web
pages for any Website.
This is a subset of Standard Generalized Mark-Up Language (SGML) for electronic
publishing, the specific standard used for the World Wide Web.
What is Hyperlink?
A hyperlink or simply a link is a selectable element in an electronic document that serves
as an access point to other electronic resources. Typically, you click the hyperlink to
access the linked resource. Familiar hyperlinks include buttons, icons, image maps, and
clickable text links.
What is DNS?
DNS stands for Domain Name System. When someone types in your domain name,
www.example.com, your browser will ask the Domain Name System to find the IP that
hosts your site. When you register your domain name, your IP address should be put in a
DNS along with your domain name. Without doing it your domain name will not be
functioning properly.
What is W3C?
W3C stands for World Wide Web Consortium which is an international consortium of
companies involved with the Internet and the Web.
3
ACMS
4
ACMS
INDEX
5
ACMS
HTML
HTML or HTML 5 tutorial provides basic and advanced concepts of html. Our HTML tutorial is developed
for beginners and professionals. The major points of HTML are given below:
1. <!DOCTYPE>
2. <html>
3. <body>
4. <h1>Write Your First Heading</h1>
5. <p>Write Your First Paragraph.</p>
6. </body>
7. </html>
HTML 5 Tags
In this tutorial, we will learn HTML 5 tags such as audio tag, video tag, canvas tag, HTML svg, HTML
geolocation, HTML drag and drop etc.
What is HTML
HTML is an acronym which stands for Hyper Text Markup Language. Let's see what is Hyper Text and
what is Markup Language?
6
ACMS
Hyper Text: Hyper Text simply means "Text within Text". A text has a link within it, is a hypertext. Every
time when you click on a word which brings you to a new webpage, you have clicked on a hypertext.
Markup language: A markup language is a programming language that is used make text more
interactive and dynamic. It can turn a text into images, tables, links etc.
An HTML document is made of many HTML tags and each HTML tag contains different content.
1. <!DOCTYPE>
2. <html>
3. <body>
4. <h1>Write Your First Heading</h1>
5. <p>Write Your First Paragraph.</p>
6. </body>
7. </html>
body : Text between body tag describes the body content of the page that is visible to the end user.
Features of HTML
1) It is a very easy and simple language. It can be easily understood and modified.
2) It is very easy to make effective presentation with HTML because it has a lot of formatting tags.
3) It is a markup language so it provides a flexible way to design web pages along with the text.
4) It facilitates programmers to add link on the web pages (by html anchor tag) , so it enhances the
interest of browsing of the user.
7
ACMS
5) It is platform-independent because it can be displayed on any platform like Windows, Linux and
Macintosh etc.
6) It facilitates the programmer to add Graphics, Videos, and Sound to the web pages which makes it
more attractive and interactive.
HTML Tags
HTML tags contain three main parts: opening tag, content and closing tag. But some HTML tags are
unclosed tags.
When a web browser reads an HTML document, browser reads it from top to bottom and left to right.
HTML tags are used to create HTML documents and render their properties. Each HTML tags have
different properties.
Syntax
<tag> content </tag>
<br> Tag: br stands for break line, it breaks the line of the code.
8
ACMS
<hr> Tag: hr stands for Horizontal Rule. This tag is used to put a line across the webpage.
HTML Formatting
HTML Formatting
HTML Formatting is a process of formatting text for better look and feel. There are many formatting tags
in HTML. These tags are used to make text bold, italicized, or underlined. There are almost 12 options
available that how text appears in HTML and XHTML.
1) Bold Text
If you write anything within <b>............</b> element, is shown in bold letters.
Output:
2) Italic Text
If you write anything within <i>............</i> element, is shown in italic letters.
Output:
If you want to mark or highlight a text, you should write the content within <mark>.........</mark>.
Output:
4) Underlined Text
If you write anything within <u>.........</u> element, is shown in underlined text.
Output:
5) Strike Text
Anything written within <strike>.......................</strike> element is displayed with strikethrough. It is a thin
line which cross the statement.
Output:
6) Monospaced Font
If you want that each letter has the same width then you should write the content within <tt>.............</tt>
element.
11
ACMS
Note: We know that most of the fonts are known as variable-width fonts because different letters have
different width. (for example: 'w' is wider than 'i'). Monospaced Font provides similar space among every
letter.
Output:
7) Superscript Text
If you put the content within <sup>..............</sup> element, is shown in superscript ; means it is displayed
half a character's height above the other characters.
Output:
8) Subscript Text
If you put the content within <sub>..............</sub> element, is shown in subscript ; means it is displayed
half a character's height below the other characters.
Output:
9) Deleted Text
12
ACMS
Output:
Hello
Output:
Output:
13
ACMS
Output:
HTML Heading
HTML Heading
A HTML heading or HTML h tag can be defined as a title or a subtitle which you want to display on the
webpage. When you place the text within the heading tags <h1>.........</h1>, it is displayed on the browser
in the bold format and size of the text depends on the number of heading.
There are six different HTML headings which are defined with the <h1> to <h6> tags.
h1 is the largest heading tag and h6 is the smallest one. So h1 is used for most important heading and h6
is used for least important.
Output:
Heading no. 1
Heading no. 2
14
ACMS
Heading no. 3
Heading no. 4
Heading no. 5
Heading no. 6
Heading elements (h1....h6) should be used for headings only. They should not be used just to
make text bold or big.
HTML Paragraph
HTML paragraph or HTML p tag is used to define a paragraph in a webpage. Let's take a simple example
to see how it work. It is a notable point that a browser itself add an empty line before and after a
paragraph.
Output:
1. <p>
2. I am
3. going to provide
4. you a tutorial on HTML
5. and hope that it will
6. be very beneficial for you.
7. </p>
15
ACMS
8. <p>
9. Look, I put here a lot
10. of spaces but I know, Browser will ignore it.
11. </p>
12. <p>
13. You cannot determine the display of HTML</p>
14. <p>because resized windows may create different result.
15. </p>
Output:
I am going to provide you a tutorial on HTML and hope that it will be very beneficial for you.
Look, I put here a lot of spaces but I know, Browser will ignore it.
As you can see, all the extra lines and unnecessary spaces are removed by the browser.
HTML Anchor
The HTML anchor tag defines a hyperlink that links one page to another page. The "href" attribute is the
most important attribute of the HTML a tag.
The href attribute is used to define the address of the file to be linked. In other words, it points out the
destination page.
16
ACMS
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an empty tag that contains
attributes only, closing tags are not used in HTML image element.
Output:
1) src
It is a necessary attribute that describes the source or path of the image. It instructs the browser where to
look for the image on the server.
2) alt
The alt attribute defines an alternate text for the image, if it can't be displayed. The value of the alt
attribute describe the image in words. The alt attribute is considered good for SEO prospective.
17
ACMS
3) width
It is an optional attribute which is used to specify the width to display the image. It is not recommended
now. You should apply CSS in place of width attribute.
4) height
It specifies the height of the image. The HTML height attribute also supports iframe, image and object
elements. It is not recommended now. You should apply CSS in place of height attribute.
HTML Table
HTML table tag is used to display data in tabular form (row * column). There can be many columns in a
row.
HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content,
footer section etc. But it is recommended to use div tag over table to manage the layout of the page .
<col> It is used with <colgroup> element to specify column properties for each
column.
18
ACMS
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Output:
In the above html table, there are 5 rows and 3 columns = 5 * 3 = 15 values.
You can use border attribute of table tag in HTML to specify border. But it is not recommended now.
1. <table border="1">
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. }
5. </style>
You can collapse all the borders in one border by border-collapse property.
1. <style>
2. table, th, td {
3. border: 2px solid black;
4. border-collapse: collapse;
5. }
6. </style>
Output:
The cellpadding attribute of HTML table tag is obselete now. It is recommended to use CSS. So let's see
the code of CSS.
1. <style>
2. table, th, td {
20
ACMS
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 5px;
8. }
9. </style>
HTML code:
1. <table style="width:100%">
2. <tr>
3. <th>Name</th>
4. <th colspan="2">Mobile No.</th>
5. </tr>
6. <tr>
7. <td>Ajeet Maurya</td>
21
ACMS
8. <td>7503520801</td>
9. <td>9555879135</td>
10. </tr>
11. </table>
Output:
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
HTML code:
1. <table>
2. <tr><th>Name</th><td>Ajeet Maurya</td></tr>
3. <tr><th rowspan="2">Mobile No.</th><td>7503520801</td></tr>
4. <tr><td>9555879135</td></tr>
5. </table>
Output:
7503520801
Mobile No.
9555879135
22
ACMS
1. <table>
2. <caption>Student Records</caption>
3. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
4. <tr><td>Vimal</td><td>Jaiswal</td><td>70</td></tr>
5. <tr><td>Mike</td><td>Warn</td><td>60</td></tr>
6. <tr><td>Shane</td><td>Warn</td><td>42</td></tr>
7. <tr><td>Jai</td><td>Malhotra</td><td>62</td></tr>
8. </table>
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. table#alter tr:nth-child(even) {
10. background-color: #eee;
11. }
12. table#alter tr:nth-child(odd) {
13. background-color: #fff;
14. }
15. table#alter th {
16. color: white;
17. background-color: gray;
18. }
19. </style>
Output:
23
ACMS
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one or more list elements. There
are three different types of HTML lists:
1. <ol>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ol>
Output:
1. Aries
2. Bingo
3. Leo
4. Oracle
Click here for full details of HTML ordered list. HTML Ordered List
1. <ul>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ul>
24
ACMS
Output:
Aries
Bingo
Leo
Oracle
Click here for full details of HTML unordered list. HTML Unordered List
The definition list is very appropriate when you want to present glossary, list of terms or other name-value
list.
1. <dl>
2. <dt>Aries</dt>
3. <dd>-One of the 12 horoscope sign.</dd>
4. <dt>Bingo</dt>
5. <dd>-One of my evening snacks</dd>
6. <dt>Leo</dt>
7. <dd>-It is also an one of the 12 horoscope sign.</dd>
8. <dt>Oracle</dt>
9. <dd>-It is a multinational technology corporation.</dd>
10. </dl>
Output:
Aries
-One of the 12 horoscope sign.
Bingo
-One of my evening snacks
Leo
-It is also an one of the 12 horoscope sign.
Oracle
25
ACMS
To represent different ordered lists, there are 5 types of attributes in <ol> tag.
Type Description
Type "1" This is the default type. In this type, the list items are numbered with numbers.
Type "I" In this type, the list items are numbered with upper case roman numbers.
Type "i" In this type, the list items are numbered with lower case roman numbers.
Type "A" In this type, the list items are numbered with upper case letters.
Type "a" In this type, the list items are numbered with lower case letters.
1. <ol>
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Output:
1. HTML
2. Java
3. JavaScript
4. SQL
26
ACMS
ol type="I"
Let's see the example to display list in roman number uppercase.
1. <ol type="I">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Output:
I. HTML
II. Java
III. JavaScript
IV. SQL
ol type="i"
Let's see the example to display list in roman number lowercase.
1. <ol type="i">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Output:
i. HTML
ii. Java
iii. JavaScript
iv. SQL
ol type="A"
Let's see the example to display list in alphabet uppercase.
1. <ol type="A">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
27
ACMS
Output:
A. HTML
B. Java
C. JavaScript
D. SQL
ol type="a"
Let's see the example to display list in alphabet lowercase.
1. <ol type="a">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Output:
a. HTML
b. Java
c. JavaScript
d. SQL
start attribute
The start attribute is used with ol tag to specify from where to start the list items.
<ol type="1" start="5"> : It will show numeric values starting with "5".
<ol type="A" start="5"> : It will show capital alphabets starting with "E".
<ol type="a" start="5"> : It will show lower case alphabets starting with "e".
<ol type="I" start="5"> : It will show Roman upper case value starting with "V".
<ol type="i" start="5"> : It will show Roman lower case value starting with "v".
Output:
v. HTML
vi. Java
vii. JavaScript
viii. SQL
disc
circle
square
none
To represent different ordered lists, there are 4 types of attributes in <ul> tag.
Type Description
Type "disc" This is the default style. In this style, the list items are marked with
bullets.
Type "circle" In this style, the list items are marked with circles.
Type "square" In this style, the list items are marked with squares.
Type "none" In this style, the list items are not marked .
Output:
HTML
Java
JavaScript
SQL
29
ACMS
ul type="circle"
1. <ul type="circle">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="square"
1. <ul type="square">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Output:
HTML
Java
JavaScript
SQL
ul type="none"
1. <ul type="none">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Output:
HTML
Java
JavaScript
30
ACMS
SQL
1. <dl>
2. <dt>HTML</dt>
3. <dd>is a markup language</dd>
4. <dt>Java</dt>
5. <dd>is a programming language and platform</dd>
6. <dt>JavaScript</dt>
7. <dd>is a scripting language</dd>
8. <dt>SQL</dt>
9. <dd>is a query language</dd>
10. </dl>
Output:
HTML
is a markup language
Java
is a programming language and platform
JavaScript
is a scripting language
SQL
is a query language
HTML Form
An HTML form is a section of a document which contains controls such as text fields, password fields,
checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for processing.
31
ACMS
For example: If a user want to purchase some items on internet, he/she must fill the form such as
shipping address and credit/debit card details so that item can be sent to the given address.
Tag Description
<form> It defines an HTML form to enter inputs by the used side.
Tag Description
32
ACMS
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
If you click on the label tag, it will focus on the text control. To do so, you need to have for attribute in
label tag that must be same as id attribute of input tag.
1. <form>
2. <label for="firstname">First Name: </label>
3. <input type="text" id="firstname" name="firstname"/> <br/>
4. <label for="lastname">Last Name: </label>
5. <input type="text" id="lastname" name="lastname"/> <br/>
6. </form>
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password"/> <br/>
4. </form>
33
ACMS
1. <form>
2. <label for="email">Email: </label>
3. <input type="email" id="email" name="email"/> <br/>
4. </form>
If you use one name for all the radio buttons, only one radio button can be selected at a time.
1. <form>
2. <label for="gender">Gender: </label>
3. <input type="radio" id="gender" name="gender" value="male"/>Male
4. <input type="radio" id="gender" name="gender" value="female"/>Female <br/>
5. </form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
1. <form>
2. Hobby:<br>
3. <input type="checkbox" id="cricket" name="cricket" value="cricket"/>
4. <label for="cricket">Cricket</label>
5. <input type="checkbox" id="football" name="football" value="football"/>
6. <label for="football">Football</label>
7. <input type="checkbox" id="hockey" name="hockey" value="hockey"/>
8. <label for="hockey">Hockey</label>
9. </form>
1. <form action="#">
2. <table>
3. <tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter name:</label></td>
5. <td><input type="text" name="name" value= id="register_name" style="width:160px"/></td>
6. </tr>
7. <tr>
8. <td class="tdLabel"><label for="register_password" class="label">Enter password:</label></td>
9. <td><input type="password" name="password" id="register_password" style="width:160px"/></td>
10. </tr>
11. <tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter Email:</label></td>
13. <td
14. ><input type="email" name="email" value= id="register_email" style="width:160px"/></td>
34
ACMS
15. </tr>
16. <tr>
17. <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</label></td>
18. <td>
19. <input type="radio" name="gender" id="register_gendermale" value="male"/>
20. <label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfemale" value="female"/>
22. <label for="register_genderfemale">female</label>
23. </td>
24. </tr>
25. <tr>
26. <td class="tdLabel"><label for="register_country" class="label">Select Country:</label></td>
27. <td><select name="country" id="register_country" style="width:160px">
28. <option value="india">india</option>
29. <option value="pakistan">pakistan</option>
30. <option value="africa">africa</option>
31. <option value="china">china</option>
32. <option value="other">other</option>
33. </select>
34. </td>
35. </tr>
36. <tr>
37. <td colspan="2"><div align="right"><input type="submit" id="register_0" value="register"/>
38. </div></td>
39. </tr>
40. </table>
41. </form>
Marquee HTML
The Marquee HTML tag is a non-standard HTML element which is used to scroll a image or text
horizontally or vertically.
In simple words, you can say that it scrolls the image or text up, down, left or right automatically.
Marquee tag was first introduced in early versions of Microsoft's Internet Explorer. It is compared with
Netscape's blink element.
Output:
35
ACMS
Attribute Description
behavior It facilitates user to set the behavior of the marquee to one of the three
different types: scroll, slide and alternate.
direction defines direction for scrolling content. It may be left, right, up and down.
Output:
36
ACMS
Output:
Output:
Output:
2) Since Marquee text moves, so it is more difficult to click static text, depending on the scrolling speed.
4) It draws user's attention needlessly and makes the text harder to read.
HTML Textarea
The HTML <textarea> tag is used to define a multi-line text input control.
It can hold unlimited number of characters and the texts are displayed in a fixed-width font (usually
courier).
The size of the HTML textarea is defined by <cols> and <rows> attribute, or it can also be defined through
CSS height and width properties.
Output:
38
ACMS
maxlength It specifies the maximum number of characters allowed in the text area.
placeholder It specifies a short hint that describes the expected value of a textarea.
wrap It specifies that how the texts in the textarea are wrapped at the time of the submission
of the form.
Output:
S u b m it
Name:
39
ACMS
The textarea element above is outside the form , but it is still the part of the form.
HTML Style
HTML Style is used to change or add the style on existing HTML elements. There is a default style for
every HTML element e.g. background color is white, text color is black etc.
The style attribute can by used with any HTML tag. To apply style on HTML tag, you should have the basic
knowledge of css properties e.g. color, background-color, text-align, font-family, font-size etc.
1. style= "property:value"
Let's see a simple example of styling html tags by color property of css.
Output:
The background-color property is used to define background color for the HTML tag.
Output:
Output:
Output:
41
ACMS
If you want to put heading at center or left, use "text-align:center" or "text-align:left" respectively.
Output:
HTML5 doesn't support <center> tag which is supported in older version of HTML.
HTML Title
HTML title tag is used to provide a title name for your webpage. It is necessary for Search Engine
Optimization (SEO).
The HTML title tag must be used inside the <head> tag.
The title of the page is displayed on the title bar of the browser.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>First web page.</title>
5. </head>
6. <body>
7. <p>Welcome to my first web page.</p>
8. </body>
42
ACMS
9. </html>
Here you see that we are using two elements, the head tag and the title tag. The whole title element is
within the head tag.
The head element which appears before body element just contains the information about the page but it
doesn't display on the browser window. So, to display a title name on the web page, title element is used.
If you look at the above example, you will see that "First web page" will be displayed on the tab/ title bar of
the browser. Content(text) between <title>.............</title> is shown on the title bar.
We know that every tag has a specific purpose e.g. p tag is used to specify paragraph, <h1> to <h6> tag
are used to specify headings but the <div> tag is just like a container unit which is used to encapsulate
other page elements and divides the HTML documents into sections.
The div tag is generally used by web developers to group HTML elements together and apply CSS styles
to many elements at once. For example: If you wrap a set of paragraph elements into a div element so
you can take the advantage of CSS styles and apply font style to all paragraphs at once instead of coding
the same style for each paragraph element.
Output:
43
ACMS
HTML div element is used to wrap large HTML span element is used to wrap
sections of elements. small portion of texts, image etc.
It is widely used to display language examples e.g. Java, C#, C, C++ etc because it displays the code as it
is typed.
Output:
44
ACMS
Output:
package com.atharva;
public class FirstJava{
public static void main(String args[]){
System.out.println("hello java");
}
}
If you remove pre tag from the above example, all the text will be displayed in a single line.
Output:
EMAIL-ID:
PHONE NO:
<button> tag supports all global attributes and some specific additional attributes.
Attribute Description
autofocus It specifies that a button should automatically get focus while the
loading of the page.
form It specifies one or more forms that the button belongs to.
formaction It is used for submit type. It specifies where to send the form data
when form is submitted.
formtarget It specifies that where to display the response after submitting the
form.
HTML hr tag
46
ACMS
HTML <hr> tag is used to specify a paragraph-level thematic break in HTML document. It is used when
you abruptly change your topic in your HTML document. It draw a horizontal line between them. It is also
called a Horizontal Rule in HTML.
HTML hr tag
1. <h2>HTML</h2>
2. <p>HTML is a language for describing web pages.</p>
3. <hr/>
4. <h2>HR Tag </h2>
5. <p> HR tag is used to draw a horizontal line within the texts to sepate content.<p>
Output:
HTML
HTML is a language for describing web pages.
HR Tag
HR tag is used to draw a horizontal line within the texts to separate content.
HTML br tag
HTML <br> tag or element is used to break line in a paragraph.
Don't use br tag for margin between two paragraphs, use CSS margin property instead.
JavaScript is used for image manipulation, form validation, and dynamic content.
47
ACMS
1. <script>
2. //code to be executed
3. </script>
defer It is a boolean value which is used to indicate that HTML 4.01, HTML5
script is executed after document has been parsed.
1. <script type="text/javascript">
2. document.write("JavaScript is a simple language for atharva learners")
3. </script>
Output:
48
ACMS
Let's see the example to have script tag within HTML head tag.
1. <script type="text/javascript">
2. function msg(){
3. alert("Hello Atharva");
4. }
5. </script>
49
ACMS
HTML5
HTML5 provides details of all 40+ HTML tags including audio, video, header, footer, data, datalist, article
etc. This HTML tutorial is designed for beginners and professionals.
HTML5 is a next version of HTML. Here, you will get some brand new features which will make HTML
much easier. These new introducing features make your website layout clearer to both website designers
and users. There are some elements like <header>, <footer>, <nav> and <article> that define the layout of
a website.
It facilitate you to design better forms and build web applications that work offline.
It provides you advance features for that you would normally have to write JavaScript to do.
The most important reason to use HTML 5 is, we believe it is not going anywhere. It will be here to serve
for a long time according to W3C recommendation.
HTML 5 Example
Let's see a simple example of HTML5.
1. <!DOCTYPE>
2. <html>
3. <body>
4. <h1>Write Your First Heading</h1>
5. <p>Write Your First Paragraph.</p>
6. </body>
7. </html>
HTML 5 Tags
There is a list of newly included tags in HTML 5. These HTML 5 tags (elements) provide a better
50
ACMS
document structure. This list shows all HTML 5 tags in alphabetical order with description.
1. mp3
2. wav
3. ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar technologies are used to
play the multimedia items.
This table defines that which web browser supports which audio file format.
1. <audio controls>
2. <source src="koyal.mp3" type="audio/mpeg">
3. Your browser does not support the html audio tag.
4. </audio>
Output:
Let's see the example to play ogg file using HTML audio tag.
1. <audio controls>
2. <source src="koyal.ogg" type="audio/ogg">
51
ACMS
Attribute Description
controls It defines the audio controls which is displayed with play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, every time when it is
completed.
preload It specifies the author view to upload audio file when the page loads.
ogg audio/ogg
wav audio/wav
HTML <meter> tag is used to measure data within a given range. It defines a scalar
measurement with range. It is also known as a gause.
The HTML meter tag is new in HTML5 so you must use new browsers.
Attributes Description
form It specifies one or more forms to which meter element belongs to.
optimum It specifies the optimum value for the gauge.It is an optional attribute.
1. <p>Display a gauge:</p>
2. <meter value="30" min="1" max="100">30 out of 100</meter><br>
3. <meter value="0.8">80%</meter>
Output:
Display a gauge:
30 out of 100
80%
53
ACMS
Styling Meter
You can apply CSS code on meter tag.
1. meter{
2. width: 300px;
3. height: 30px;
4. }
Output:
The <datalist> tag should be used with an <input> element that contains a "list" attribute.
The value of "list" attribute is linked with the datalist id.
The HTML datalist tag supports global and event attributes also.
1. <label>
2. Enter your favorite cricket player: Press any character<br />
3. <input type="text" id="favCktPlayer" list="CktPlayers">
4. <datalist id="CktPlayers">
5. <option value="Sachin Tendulkar">
6. <option value="Brian Lara">
7. <option value="Jacques Kallis">
8. <option value="Ricky Ponting">
9. <option value="Rahul Dravid">
10. <option value="Shane Warne">
11. <option value="Rohit Sharma">
12. <option value="Donald Bradman">
13. <option value="Saurav Ganguly ">
14. <option value="AB diVilliers">
15. <option value="Mahendra Singh Dhoni">
16. <option value="Adam Gilchrist">
17. </datalist>
18. </label>
54
ACMS
Output:
Attribute Description
open It specifies that the details will be displayed (open) to the user.
Output:
Copyright 2011-2014.
Note: The details tag is currently only supported in Opera, Chrome, and in Safari 6.
55
ACMS
56
ACMS
CSS Index
o CSS Border
57
ACMS
What is CSS
CSS is an acronym stands for Cascading Style Sheets. It is a style sheet language which is used to
describe the look and formatting of a document written in markup language. It provides an additional
feature to HTML. It is generally used with HTML to change the style of web pages and user interfaces. It
can also be used with any kind of XML documents including plain XML, SVG and XUL.
CSS is used along with HTML and JavaScript in most websites to create user interfaces for web
applications and user interfaces for many mobile applications.
o You can completely change the look of your website with only a few changes in CSS code.
CSS Syntax
A CSS rule set contains a selector and a declaration block.
58
ACMS
Selector: Selector indicates the HTML element you want to style. It could be any tag like <h1>, <title> etc.
Declaration Block: The declaration block can contain one or more declarations separated by a semicolon.
For the above example, there are two declarations:
1. color: yellow;
2. font-size: 11 px;
Property: A Property is a type of attribute of HTML element. It could be color, border etc.
Value: Values are assigned to CSS properties. In the above example, value "yellow" is assigned to color
property.
CSS Selector
CSS selectors are used to select the content you want to style. Selectors are the part of CSS rule set. CSS
selectors select HTML elements according to its id, class, type, attribute etc.
2. CSS Id Selector
59
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p{
6. text-align: center;
7. color: blue;
8. }
9. </style>
10. </head>
11. <body>
12. <p>This style will be applied on every paragraph.</p>
13. <p id="para1">Me too!</p>
14. <p>And me!</p>
15. </body>
16. </html>
17. Output:
18. This style will be applied on every paragraph.
19. Me too!
20. And me!
2) CSS Id Selector
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.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #para1 {
6. text-align: center;
7. color: blue;
8. }
9. </style>
10. </head>
11. <body>
60
ACMS
Output:
Hello atharva.com
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. .center {
6. text-align: center;
7. color: blue;
8. }
9. </style>
10. </head>
11. <body>
12. <h1 class="center">This heading is blue and center-aligned.</h1>
13. <p class="center">This paragraph is blue and center-aligned.</p>
14. </body>
15. </html>
Output:
61
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p.center {
6. text-align: center;
7. color: blue;
8. }
9. </style>
10. </head>
11. <body>
12. <h1 class="center">This heading is not affected</h1>
13. <p class="center">This paragraph is blue and center-aligned.</p>
14. </body>
15. </html>
Output:
1. <!DOCTYPE html>
2. <html>
62
ACMS
3. <head>
4. <style>
5. * {
6. color: green;
7. font-size: 20px;
8. }
9. </style>
10. </head>
11. <body>
12. <h2>This is heading</h2>
13. <p>This style will be applied on every paragraph.</p>
14. <p id="para1">Me too!</p>
15. <p>And me!</p>
16. </body>
17. </html>
Output:
This is heading
Me too!
And me!
Grouping selector is used to minimize the code. Commas are used to separate each selector in grouping.
1. h1 {
2. text-align: center;
3. color: blue;
4. }
5. h2 {
6. text-align: center;
63
ACMS
7. color: blue;
8. }
9. p {
10. text-align: center;
11. color: blue;
12. }
As you can see, you need to define CSS properties for all the elements. It can be grouped in following
ways:
1. h1,h2,p {
2. text-align: center;
3. color: blue;
4. }
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h1, h2, p {
6. text-align: center;
7. color: blue;
8. }
9. </style>
10. </head>
11. <body>
12. <h1>Hello atharva.com</h1>
13. <h2>Hello atharva.com (In smaller font)</h2>
14. <p>This is a paragraph.</p>
15. </body>
16. </html>
Output:
Hello atharva.com
Hello atharva.com (In smaller font)
This is a paragraph.
64
ACMS
1. Inline CSS
2. Internal CSS
3. External CSS
1) Inline CSS
Inline CSS is used to apply CSS on a single line or element.
For example:
2) Internal CSS
Internal CSS is used to apply CSS on a single document or page. It can affect all the elements of the page.
It is written inside the style tag within head section of html.
For example:
1. <style>
2. p{color:blue}
3. </style>
3) External CSS
External CSS is used to apply CSS on multiple pages or all pages. Here, we write all the CSS code in a css
file. Its extension must be .css for example style.css.
For example:
1. p{color:blue}
65
ACMS
You need to link this style.css file to your html pages like this:
CSS Comments
CSS comments are generally written to explain your code. It is very helpful for the users who reads your
code so that they can easily understand the code.
Comments are single or multiple lines statement and written within /*............*/ .
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. color: blue;
7. /* This is a single-line comment */
8. text-align: center;
9. }
10. /* This is
11. a multi-line
12. comment */
13. </style>
14. </head>
15. <body>
16. <p>Hello atharva.com</p>
17. <p>This statement is styled with CSS.</p>
18. <p>CSS comments are ignored by the browsers and not shown in the output.</p>
19. </body>
20. </html>
CSS Background
CSS background property is used to define the background effects on element. There are 5 CSS
background properties that affects the HTML elements:
66
ACMS
1. background-color
2. background-image
3. background-repeat
4. background-attachment
5. background-position
1) CSS background-color
The background-color property is used to specify the background color of the element.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h2,p{
6. background-color: #b0d4de;
7. }
8. </style>
9. </head>
10. <body>
11. <h2>My first CSS page.</h2>
12. <p>Hello atharva. This is an example of CSS background-color.</p>
13. </body>
14. </html>
Output:
2) CSS background-image
The background-image property is used to set an image as a background of an element. By default the
image covers the entire element. You can set the background image for a page like this.
67
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. background-image: url("paper1.gif");
7. margin-left:100px;
8. }
9. </style>
10. </head>
11. <body>
12. <h1>Hello atharva.com</h1>
13. </body>
14. </html>
Note: The background image should be chosen according to text color. The bad combination of text and
background image may be a cause of poor designed and not readable webpage.
3) CSS background-repeat
By default, the background-image property repeats the background image horizontally and vertically.
Some images are repeated only horizontally or vertically.
background-repeat: repeat-x;
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. background-image: url("gradient_bg.png");
7. background-repeat: repeat-x;
8. }
9. </style>
10. </head>
11. <body>
12. <h1>Hello atharva.com</h1>
68
ACMS
13. </body>
14. </html>
background-repeat: repeat-y;
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. background-image: url("gradient_bg.png");
7. background-repeat: repeat-y;
8. }
9. </style>
10. </head>
11. <body>
12. <h1>Hello atharva.com</h1>
13. </body>
14. </html>
4) CSS background-attachment
The background-attachment property is used to specify if the background image is fixed or scroll with the
rest of the page in browser window. If you set fixed the background image then the image will not move
during scrolling in the browser. Let?s take an example with fixed background image.
5) CSS background-position
The background-position property is used to define the initial position of the background image. By
default, the background image is placed on the top-left of the webpage.
1. center
69
ACMS
2. top
3. bottom
4. left
5. right
CSS Border
The CSS border is a shorthand property used to set the border on an element.
The CSS border properties are use to specify the style, color and size of the border of an element. The
CSS border properties are given below
o border-style
o border-color
o border-width
o border-radius
1) CSS border-style
The Border style property is used to specify the border type which you want to display on the web page.
There are some border style values which are used with border-style property to define a border.
Value Description
70
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p.none {border-style: none;}
6. p.dotted {border-style: dotted;}
7. p.dashed {border-style: dashed;}
8. p.solid {border-style: solid;}
9. p.double {border-style: double;}
10. p.groove {border-style: groove;}
11. p.ridge {border-style: ridge;}
12. p.inset {border-style: inset;}
13. p.outset {border-style: outset;}
14. p.hidden {border-style: hidden;}
15. </style>
16. </head>
17. <body>
18. <p class="none">No border.</p>
19. <p class="dotted">A dotted border.</p>
20. <p class="dashed">A dashed border.</p>
21. <p class="solid">A solid border.</p>
22. <p class="double">A double border.</p>
23. <p class="groove">A groove border.</p>
24. <p class="ridge">A ridge border.</p>
25. <p class="inset">An inset border.</p>
26. <p class="outset">An outset border.</p>
27. <p class="hidden">A hidden border.</p>
71
ACMS
28. </body>
29. </html>
Output:
No border.
A dotted border.
A dashed border.
A solid border.
A double border.
A groove border.
A ridge border.
An inset border.
An outset border.
A hidden border.
2) CSS border-width
The border-width property is used to set the border's width. It is set in pixels. You can also use the one of
the three pre-defined values, thin, medium or thick to set the width of the border.
Note: The border-width property is not used alone. It is always used with other border properties
like "border-style" property to set the border first otherwise it will not work.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p.one {
6. border-style: solid;
7. border-width: 5px;
8. }
72
ACMS
9. p.two {
10. border-style: solid;
11. border-width: medium;
12. }
13. p.three {
14. border-style: solid;
15. border-width: 1px;
16. }
17. </style>
18. </head>
19. <body>
20. <p class="one">Write your text here.</p>
21. <p class="two">Write your text here.</p>
22. <p class="three">Write your text here.</p>
23. </body>
24. </html>
3) CSS border-color
There are three methods to set the color of the border.
o RGB: It specifies the RGB value of the color. For example: "rgb(255,0,0)".
o Hex: It specifies the hex value of the color. For example: "#ff0000".
There is also a border color named "transparent". If the border color is not set it is inherited from the color
property of the element.
Note: The border-color property is not used alone. It is always used with other border properties
like "border-style" property to set the border first otherwise it will not work.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p.one {
6. border-style: solid;
7. border-color: red;
73
ACMS
8. }
9. p.two {
10. border-style: solid;
11. border-color: #98bf21;
12. }
13. </style>
14. </head>
15. <body>
16. <p class="one">This is a solid red border</p>
17. <p class="two">This is a solid green border</p>
18. </body>
19. </html>
CSS Display
CSS display is the most important property of CSS which is used to control the layout of the element. It
specifies how the element is displayed.
Every element has a default display value according to its nature. Every element on the webpage is a
rectangular box and the CSS property defines the behavior of that rectangular box.
default value
inherited
animation supporting
version
javascript syntax
Syntax
1. display:value;
There are following CSS display values which are commonly used.
1. display: inline;
2. display: inline-block;
3. display: block;
4. display: none;
o <span>
o <a>
o <em>
o <b> etc.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. display: inline;
7. }
8. </style>
9. </head>
10. <body>
11. <p>Hello atharva.com</p>
12. <p>Java Tutorial.</p>
13. <p>SQL Tutorial.</p>
14. <p>HTML Tutorial.</p>
15. <p>CSS Tutorial.</p>
16. </body>
17. </html>
75
ACMS
Output:
Hello atharva.com Java Tutorial. SQL Tutorial. HTML Tutorial. CSS Tutorial.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. display: inline-block;
7. }
8. </style>
9. </head>
10. <body>
11. <p>Hello atharva.com</p>
12. <p>Java Tutorial.</p>
13. <p>SQL Tutorial.</p>
14. <p>HTML Tutorial.</p>
15. <p>CSS Tutorial.</p>
16. </body>
17. </html>
Output:
Hello atharva.com Java Tutorial. SQL Tutorial. HTML Tutorial. CSS Tutorial.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
76
ACMS
5. p {
6. display: block;
7. }
8. </style>
9. </head>
10. <body>
11. <p>Hello atharva.com</p>
12. <p>Java Tutorial.</p>
13. <p>SQL Tutorial.</p>
14. <p>HTML Tutorial.</p>
15. <p>CSS Tutorial.</p>
16. </body>
17. </html>
Output:
Hello atharva.com
Java Tutorial.
SQL Tutorial.
HTML Tutorial.
CSS Tutorial.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h1.hidden {
6. display: none;
7. }
8. </style>
9. </head>
77
ACMS
10. <body>
11. <h1>This heading is visible.</h1>
12. <h1 class="hidden">This is not visible.</h1>
13. <p>You can see that the hidden heading does not contain any space.</p>
14. </body>
15. </html>
Output:
Property-value Description
78
ACMS
CSS Float
The CSS float property is a positioning property. It is used to push an element to the left or right, allowing
other element to wrap around it. It is generally used with images and layouts.
To understand its purpose and origin, let's take a look to its print display. In the print display, image is set
into the page such that text wraps around it as needed.
79
ACMS
How it works
Elements are floated only horizontally. So it is possible only to float elements left or right, not up or down.
1. A floated element may be moved as far to the left or the right as possible. Simply, it means that a
floated element can display at extreme left or extreme right.
2. The elements after the floating element will flow around it.
4. If the image floated to the right, the texts flow around it, to the left and if the image floated to the
left, the text flows around it, to the right.
clear The clear property is used to avoid left, right, both, none, inherit
elements after the floating
elements which flow around it.
80
ACMS
Value Description
none It specifies that the element is not floated, and will be displayed just where it occurs
in the text. this is a default value.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. img {
6. float: right;
7. }
8. </style>
9. </head>
10. <body>
11. <p>The following paragraph contains an image with style
12. <b>float:right</b>. The result is that the image will float to the right in the paragraph.</p>
13. <img src="good-morning.jpg" alt="Good Morning Friends"/>
14. This is some text. This is some text. This is some text.
15. This is some text. This is some text. This is some text.
16. This is some text. This is some text. This is some text.
17. This is some text. This is some text. This is some text.
81
ACMS
18. This is some text. This is some text. This is some text.
19. This is some text. This is some text. This is some text.
20. This is some text. This is some text. This is some text.
21. This is some text. This is some text. This is some text.
22. This is some text. This is some text. This is some text.
23. This is some text. This is some text. This is some text.
24. This is some text. This is some text. This is some text.
25. This is some text. This is some text. This is some text.
26. This is some text. This is some text. This is some text.
27. </p>
28. </body>
29. </html>
CSS Font
CSS Font property is used to control the look of texts. By the use of CSS font property you can change the
text size, color, style and more. You have already studied how to make text bold or underlined. Here, you
will also know how to resize your font using percentage.
1. CSS Font color: This property is used to change the color of the text. (standalone attribute)
2. CSS Font family: This property is used to change the face of the font.
3. CSS Font size: This property is used to increase or decrease the size of the font.
4. CSS Font style: This property is used to make the font bold, italic or oblique.
o By a color name
o By hexadecimal value
o By RGB
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. font-size: 100%;
7. }
8. h1 { color: red; }
9. h2 { color: #9000A1; }
10. p { color:rgb(0, 220, 98); }
11. }
12. </style>
13. </head>
14. <body>
15. <h1>This is heading 1</h1>
16. <h2>This is heading 2</h2>
17. <p>This is a paragraph.</p>
18. </body>
19. </html>
Output:
This is heading 1
This is heading 2
This is a paragraph.
o Font family: It specifies the font family name like Arial, New Times Roman etc.
Serif: Serif fonts include small lines at the end of characters. Example of serif: Times new roman, Georgia
etc.
Sans-serif: A sans-serif font doesn't include the small lines at the end of characters. Example of Sans-
serif: Arial, Verdana etc.
83
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. font-size: 100%;
7. }
8. h1 { font-family: sans-serif; }
9. h2 { font-family: serif; }
10. p { font-family: monospace; }
11. }
12. </style>
13. </head>
14. <body>
15. <h1>This heading is shown in sans-serif.</h1>
16. <h2>This heading is shown in serif.</h2>
17. <p>This paragraph is written in monospace.</p>
18. </body>
19. </html>
Output:
CSS font size property is used to change the size of the font.
These are the possible values that can be used to set the font size:
1. <html>
2. <head>
3. <title>Practice CSS font-size property</title>
4. </head>
5. <body>
6. <p style="font-size:xx-small;"> This font size is extremely small.</p>
7. <p style="font-size:x-small;"> This font size is extra small</p>
8. <p style="font-size:small;"> This font size is small</p>
9. <p style="font-size:medium;"> This font size is medium. </p>
10. <p style="font-size:large;"> This font size is large. </p>
85
ACMS
Output:
86
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. font-size: 100%;
7. }
8. h2 { font-style: italic; }
9. h3 { font-style: oblique; }
10. h4 { font-style: normal; }
11. }
12. </style>
13. </head>
14. <body>
15. <h2>This heading is shown in italic font.</h2>
16. <h3>This heading is shown in oblique font.</h3>
17. <h4>This heading is shown in normal font.</h4>
18. </body>
19. </html>
Output:
CSS Margin
CSS Margin property is used to define the space around elements. It is completely transparent and
doesn't have any background color. It clears an area around the element.
Top, bottom, left and right margin can be changed independently using separate properties. You can also
change all properties at once by using shorthand margin property.
87
ACMS
Property Description
Value Description
length It is used to specify a margin pt, px, cm, etc. its default value is 0px.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. background-color: pink;
88
ACMS
7. }
8. p.ex {
9. margin-top: 50px;
10. margin-bottom: 50px;
11. margin-right: 100px;
12. margin-left: 100px;
13. }
14. </style>
15. </head>
16. <body>
17. <p>This paragraph is not displayed with specified margin. </p>
18. <p class="ex">This paragraph is displayed with specified margin.</p>
19. </body>
20. </html>
Output:
There are four types to specify the margin property. You can use one of them.
4. margin 50px;
89
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. background-color: pink;
7. }
8. p.ex {
9. margin: 50px 100px 150px 200px;
10. }
11. </style>
12. </head>
13. <body>
14. <p>This paragraph is not displayed with specified margin. </p>
15. <p class="ex">This paragraph is displayed with specified margin.</p>
16. </body>
17. </html>
Output:
It identifies that:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. background-color: pink;
7. }
8. p.ex {
9. margin: 50px 100px 150px;
10. }
11. </style>
12. </head>
13. <body>
14. <p>This paragraph is not displayed with specified margin. </p>
15. <p class="ex">This paragraph is displayed with specified margin.</p>
16. </body>
17. </html>
Output:
It identifies that:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p {
6. background-color: pink;
7. }
8. p.ex {
9. margin: 50px 100px;
10. }
11. </style>
12. </head>
13. <body>
14. <p>This paragraph is not displayed with specified margin. </p>
15. <p class="ex">This paragraph is displayed with specified margin.</p>
16. </body>
17. </html>
Output:
4) margin: 50px;
It identifies that:
1. <!DOCTYPE html>
2. <html>
92
ACMS
3. <head>
4. <style>
5. p {
6. background-color: pink;
7. }
8. p.ex {
9. margin: 50px;
10. }
11. </style>
12. </head>
13. <body>
14. <p>This paragraph is not displayed with specified margin. </p>
15. <p class="ex">This paragraph is displayed with specified margin.</p>
16. </body>
17. </html>
Output:
CSS Opacity
The CSS opacity property is used to specify the transparency of an element. In simple word, you can say
that it specifies the clarity of the image.
In technical terms, Opacity is defined as degree in which light is allowed to travel through an object.
93
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. img.trans {
6. opacity: 0.4;
7. filter: alpha(opacity=40); /* For IE8 and earlier */
8. }
9. </style>
10. </head>
11. <body>
12. <p>Normal Image</p>
13. <img src="rose.jpg" alt="normal rose">
14. <p>Transparent Image</p>
15. <img class="trans" src="rose.jpg" alt="transparent rose">
16. </body>
17. </html>
Output:
Normal Image
Transparent Image
94
ACMS
Note 1: Chrome, Firefox, Opera, Safari, and IE9 use the opacity property for transparency. The
opacity value ranges from 0.1 to 1.0. Lower value produces the greater opacity.
Note 2: The older versions of IE use filter: alpha(opacity=x). Here x value varies from 0 to 100.
Lower value produces the greater opacity.
CSS Overflow
The CSS overflow property specifies how to handle the content when it overflows its block level container.
We know that every single element on a page is a rectangular box and the size, positioning and behavior
of these boxes are controlled via CSS.
Let's take an example: If you don't set the height of the box, it will grow as large as the content. But if you
set a specific height or width of the box and the content inside cannot fit then what will happen. The CSS
overflow property is used to overcome this problem. It specifies whether to clip content, render scroll
bars, or just display content.
Value Description
Visible It specifies that overflow is not clipped. it renders outside the element's box.this is
a default value.
hidden It specifies that the overflow is clipped, and rest of the content will be invisible.
Scroll It specifies that the overflow is clipped, and a scroll bar is used to see the rest of
the content.
Auto It specifies that if overflow is clipped, a scroll bar is needed to see the rest of the
content.
95
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div.scroll {
6. background-color: #00ffff;
7. width: 100px;
8. height: 100px;
9. overflow: scroll;
10. }
11.
12. div.hidden {
13. background-color: #00FF00;
14. width: 100px;
15. height: 170px;
16. overflow: hidden;
17. }
18. </style>
19. </head>
20. <body>
21. <p>The overflow property specifies what to do if the content of an element exceeds the size of the eleme
nt's box.</p>
22. <p>overflow:scroll</p>
23. <div class="scroll">You can use the overflow property when you want to have better control of the layout.
Output:
96
ACMS
The overflow property specifies what to do if the content of an element exceeds the size of the element's
box.
overflow:scroll
You can use the overflow property when you want to have better control of the layout. The default value is
visible.
overflow:hidden
You can use the overflow property when you want to have better control of the layout. The default value
is
CSS Padding
CSS Padding property is used to define the space between the element content and the element border.
It is different from CSS margin in the way that CSS margin defines the space around elements. CSS
padding is affected by the background colors. It clears an area around the content.
Top, bottom, left and right padding can be changed independently using separate properties. You can
also change all properties at once by using shorthand padding property.
Property Description
97
ACMS
Value Description
Output:
98
ACMS
CSS Position
The CSS position property is used to set position for an element. it is also used to place an element
behind another and also useful for scripted animation effect.
You can position an element using the top, bottom, left and right properties. These properties can be used
only after position property is set first. A position element's computed position property is relative,
absolute, fixed or sticky.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. p.pos_fixed {
6. position: fixed;
7. top: 50px;
8. right: 5px;
9. color: blue;
10. }
11. </style>
12. </head>
13. <body>
14.
99
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h2.pos_left {
6. position: relative;
7. left: -30px;
8. }
9. h2.pos_right {
10. position: relative;
11. left: 30px;
12. }
13. </style>
14. </head>
15. <body>
16. <h2>This is a heading with no position</h2>
17. <h2 class="pos_left">This heading is positioned left according to its normal position</h2>
18. <h2 class="pos_right">This heading is positioned right according to its normal position</h2>
19. <p>The style "left:-30px" subtracts 30 pixels from the element's original left position.</p>
20. <p>The style "left:30px" adds 30 pixels to the element's original left position.</p>
21. </body>
22. </html>
The absolute positioning is used to position an element relative to the first parent element that has a
position other than static. If no such element is found, the containing block is HTML.
With the absolute positioning, you can place an element anywhere on a page.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. h2 {
6. position: absolute;
7. left: 150px;
8. top: 250px;
9. }
10. </style>
11. </head>
12. <body>
13. <h2>This heading has an absolute position</h2>
14. <p> The heading below is placed 150px from the left and 250px from the top of the page.</p>
15. </body>
16. </html>
What it does
1. It is applied to inline or inline-block elements.
2. It affects the alignment of the element, not its content. (except table cells)
3. When it applied to the table cells, it affect the cell contents, not the cell itself.
101
ACMS
Output:
102
ACMS
Value Description
normal This is a default value. in this value, text is wrapped when necessary. sequences
of white space will collapse into a single whitespace.
nowrap Sequences of white space will collapse into a single whitespace. in this value,
text will never wrap to the next line and only break when <br> tag is used.
Pre Whitespace is preserved by the browser. it is act like html <pre> tag. text will only
wrap on line breaks.
pre-line Sequences of white space will collapse into a single whitespace. texts are
wrapped when necessary, and on line break.
pre-wrap Whitespace is preserved by the browser. texts are wrapped when necessary, and
103
ACMS
on line break.
CSS Width
The CSS width property is used to set the width of the content area of an element.
It does not include padding borders or margins. It sets width of the area inside the padding, border, and
margin of the element.
Value Description
104
ACMS
105
ACMS
Output:
This is a paragraph.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. img.normal {
6. width: auto;
7. }
8. img.big {
9. width: 50%;
10. }
11. img.small {
12. width: 10%;
13. }
14. </style>
15. </head>
16. <body>
17. <img class="normal" src="good-morning.jpg" width="95" height="84"><br>
18. <img class="big" src="good-morning.jpg" width="95" height="84"><br>
19. <img class="small" src="good-morning.jpg" width="95" height="84">
20. </body>
106
ACMS
21. </html>
Output:
CSS Outline
CSS outline is just like CSS border property. It facilitates you to draw an extra border around an element to
get visual attention.
1. <!DOCTYPE html>
2. <html>
3. <style type="text/css">
4. .box {
5. background-color: #eee;
6. outline: 3px solid red;
7. border: 3px solid lightgreen;
8. padding: 5px 10px;
9. }
10. </style>
11. <div class="box">Welcome to Atharva</div>
12. </body>
13. </html>
107
ACMS
o It is not possible to apply a different outline width, style and color for the four sides of an element
while in border; you can apply the provided value for all four sides of an element.
o The border is a part of element's dimension while the outline is not the part of element's
dimension. Means, it doesn't matter how thick an outline you apply to the element, the
dimensions of it won't change.
The outline property is a shorthand property. It can be divided into outline-width, outline-style and outline-
color properties. It facilitates you to use any of the property alone, if you need it.
1. <!DOCTYPE html>
2. <html>
3. <style type="text/css">
4. .box {
5. background-color: #eee;
6. border: 3px solid Lightgreen;
7. padding: 5px 10px;
8. outline-width: 3px;
9. outline-style: solid;
10. outline-color: red;
11. }
12. </style>
13. <div class="box">Welcome to Atharva</div>
14. </body>
15. </html>
In the above example, you can see the three outline properties:
Outline-width:It is similar to margin and padding. It can be either an absolute value or a relative value or
one of the predefined outline width values i.e. thin, medium or thick. It is preferred to use either an
absolute value or a relative value because different browsers interpret differently while using predefined
outline width values like thin, medium or thick.
Outline-color:It specifies the color that you use for the outline. It supports all the colors available in HTML
and CSS.
Outline-style:In the above example, we have used only solid outline style while there are a lot of outline
108
ACMS
style i.e. hidden, dotted, dashed, solid, double, groove, ridge, inset and outset.
1. <!DOCTYPE html>
2. <html>
3. <style type="text/css">
4. .box {
5. outline-color: red;
6. outline-width: 4px;
7. margin: 10px;
8. float: left;
9. border: 2px solid lightgreen;
10. padding: 5px 10px;
11. }
12. </style>
13. <div class="box" style="outline-style: dashed;">This is dashed outline.</div>
14. <div class="box" style="outline-style: dotted;">This is dotted outline.</div>
15. <div class="box" style="outline-style: double;">This is double outline.</div>
16. <div class="box" style="outline-style: groove;">This is groove outline.</div>
17. <div class="box" style="outline-style: inset;">This is inset outline.</div>
18. <div class="box" style="outline-style: outset;">This is outset outline.</div>
19. <div class="box" style="outline-style: ridge;">This is ridge outline.</div>
20. <div class="box" style="outline-style: solid;">This is solid outline.</div>
21. </body>
22. </html>
Outline offset
The outline offset is used to create a distance between outline and border.
It takes a CSS length unit and the empty space between the border and the outline will be transparent and
then it takes the background color of the parent element. So you can see a visible difference between
outline and border.
Let's take an example to see the difference between outline and border.
109
ACMS
1. <!DOCTYPE html>
2. <html>
3. <style type="text/css">
4. .box {
5. background-color: #eee;
6. outline: 3px solid red;
7. outline-offset: 6px;
8. border: 3px solid Lightgreen;
9. padding: 5px 10px;
10. }
11. </style>
12. <div class="box">Welcome to Atharva</div>
13. </body>
14. </html>
110
ACMS
CSS Counters
CSS counters are similar to variables. These are maintained by CSS and those values can be incremented
by CSS rules to track how many times they are used.
CSS counters facilitate simple CSS based incrementing and display of a number for generated content.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. counter-reset: section;
7. }
8. h2::before {
9. counter-increment: section;
10. content: "Section " counter(section) ": ";
11. }
12. </style>
13. </head>
14. <body>
111
ACMS
Note: In the above example you can see that a counter is created for the page in the body selector
and it increments the counter value for each <h2> element and adds "Section <value of the
counter>:" to the beginning of each <h2> element.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body {
6. counter-reset: section;
7. }
8. h1 {
9. counter-reset: subsection;
10. }
11. h1::before {
12. counter-increment: section;
13. content: "Section " counter(section) ". ";
14. }
15. h2::before {
16. counter-increment: subsection;
17. content: counter(section) "." counter(subsection) " ";
18. }
19. </style>
112
ACMS
20. </head>
21. <body>
22. <h1>Java tutorials:</h1>
23. <h2>Core Java tutorial</h2>
24. <h2>Servlet tutorial</h2>
25. <h2>JSP tutorial</h2>
26. <h2>Spring tutorial</h2>
27. <h2>Hibernate tutorial</h2>
28.
29. <h1>Web technology tutorials:</h1>
30. <h2>HTML tutorial</h2>
31. <h2>CSS tutorial</h2>
32. <h2>jQuery tutorial</h2>
33. <h2>Bootstrap tutorial</h2>
34.
35. <h1>Database tutorials:</h1>
36. <h2>SQL tutorial</h2>
37. <h2>MySQL tutorial</h2>
38. <h2>PL/SQL tutorial</h2>
39. <h2>Oracle tutorial</h2>
40. <p><strong>Note:</strong> IE8 supports these properties only if a !DOCTYPE is specified.</p>
41. </body>
42. </html>
Note:In the above example you can see that a counter is created for the section and another nesting
counter named subsection is created within section.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. ol {
113
ACMS
6. counter-reset: section;
7. list-style-type: none;
8. }
9.
10. li::before {
11. counter-increment: section;
12. content: counters(section,".") " ";
13. }
14. </style>
15. </head>
16. <body>
17. <h2>Different level of Nesting counters</h2>
18. <ol>
19. <li>item</li>
20. <li>item
21. <ol>
22. <li>item</li>
23. <li>item</li>
24. <li>item
25. <ol>
26. <li>item</li>
27. <li>item</li>
28. <li>item</li>
29. </ol>
30. </li>
31. <li>item</li>
32. </ol>
33. </li>
34. <li>item</li>
35. <li>item</li>
36. </ol>
37. <p><b>Note:</b> IE8 supports these properties only if a !DOCTYPE is specified.</p>
38. </body>
39. </html>
114
ACMS
CSS Visibility
The CSS visibility property is used to specify whether an element is visible or not.
Note: An invisible element also take up the space on the page. By using display property you can create
invisible elements that don't take up space.
Syntax:
1. visibility: visible|hidden|collapse|initial|inherit;
hidden:It specifies that the element is invisible (but still takes up space).
collapse:It is used only for table elements. It is used to remove a row or column, but it does not affect the
table layout.
The space taken up by the row or column will be available for other content.
JavaScript Syntax:
1. object.style.visibility="hidden"
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #myDIV {
6. margin: auto;
7. width: 400px;
8. height: 200px;
9. background-color: lightpink;
10. border: 1px solid black;
11. }
12. </style>
13. </head>
14. <body>
15. <p>Click the "Try it" button to set the visibility property and hide the div element.</p>
16. <button onclick="myFunction()">Try it</button>
17. <div id="myDIV">This is my DIV element.</div>
18. <p><strong>Note:</strong> An invisible element also take up the space on the page. </p>
19. <script>
20. function myFunction() {
21. document.getElementById("myDIV").style.visibility = "hidden";
22. }
23. </script>
24. </body>
25. </html>
116
ACMS
117
ACMS
CSS Animation
CSS Animation property is used to create animation on the webpage. It can be used as a replacement of
animation created by Flash and JavaScript.
The animation could be bound to the selector by specifying at least these two properties:
Property Description
animation This is a shorthand property, used for setting all the properties,
except the animation-play-state and the animation-fill- mode
property.
animation-fill-mode it specifies the static style of the element. (when the animation is
not playing)
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
-webkit-animation: myfirst 6s; /* Chrome, Safari, Opera */
animation: myfirst 5s;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes myfirst {
from {background: red;}
to {background: green;}
}
119
ACMS
/* Standard syntax */
@keyframes myfirst {
from {background: red;}
to {background: green;}
}
</style>
</head>
<body>
<p><b>Note:</b> The IE 9 and earlier versions don't support CSS3 animation property. </p>
<div></div>
</body>
</html>
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div {
6. width: 100px;
7. height: 100px;
8. background: red;
9. position: relative;
10. -webkit-animation: myfirst 5s; /* Chrome, Safari, Opera */
11. animation: myfirst 5s;
12. }
13. /* Chrome, Safari, Opera */
14. @-webkit-keyframes myfirst {
15. 0% {background:red; left:0px; top:0px;}
16. 25% {background:yellow; left:300px; top:0px;}
17. 50% {background:blue; left:200px; top:300px;}
18. 75% {background:green; left:0px; top:200px;}
19. 100% {background:red; left:0px; top:0px;}
20. }
21. /* Standard syntax */
120
ACMS
CSS Gradient
CSS gradient is used to display smooth transition within two or more specified colors.
o It provides better look to the element when zoomed, because the gradient is generated by the
browser.
1. Linear gradients
2. Radial gradients
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #grad1 {
6. height: 100px;
7. background: -webkit-linear-gradient(red, green); /* For Safari 5.1 to 6.0 */
8. background: -o-linear-gradient(red, green); /* For Opera 11.1 to 12.0 */
9. background: -moz-linear-gradient(red, green); /* For Firefox 3.6 to 15 */
10. background: linear-gradient(red, green); /* Standard syntax (must be last) */
11. }
12. </style>
13. </head>
14. <body>
15. <h3>Linear Gradient - Top to Bottom</h3>
16. <p>This linear gradient starts at the top. It starts red, transitioning to green:</p>
17. <div id="grad1"></div>
18. </body>
19. </html>
Output:
This linear gradient starts at the top. It starts red, transitioning to green:
1. <!DOCTYPE html>
2. <html>
122
ACMS
3. <head>
4. <style>
5. #grad1 {
6. height: 100px;
7. background: -webkit-linear-gradient(left, red, green); /* For Safari 5.1 to 6.0 */
8. background: -o-linear-gradient(right, red, green); /* For Opera 11.1 to 12.0 */
9. background: -moz-linear-gradient(right, red, green); /* For Firefox 3.6 to 15 */
10. background: linear-gradient(to right, red , green); /* Standard syntax (must be last) */
11. }
12. </style>
13. </head>
14. <body>
15. <h3>Linear Gradient - Left to Right</h3>
16. <p>This linear gradient starts at the left. It starts red, transitioning to green:</p>
17. <div id="grad1"></div>
18. </body>
19. </html>
Output:
This linear gradient starts at the left. It starts red, transitioning to green:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #grad1 {
6. height: 100px;
7. background: -webkit-linear-gradient(left top, red , green); /* For Safari 5.1 to 6.0 */
8. background: -o-linear-gradient(bottom right, red, green); /* For Opera 11.1 to 12.0 */
9. background: -moz-linear-gradient(bottom right, red, green); /* For Firefox 3.6 to 15 */
10. background: linear-gradient(to bottom right, red , green); /* Standard syntax (must be last) */
11. }
123
ACMS
12. </style>
13. </head>
14. <body>
15. <h3>Linear Gradient - Diagonal</h3>
16. <p>This linear gradient starts at top left. It starts red, transitioning to green:</p>
17. <div id="grad1"></div>
18. </body>
19. </html>
Output:
This linear gradient starts at top left. It starts red, transitioning to green:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #grad1 {
6. height: 150px;
7. width: 200px;
8. background: -webkit-radial-gradient(blue, green, red); /* Safari 5.1 to 6.0 */
9. background: -o-radial-gradient(blue, green, red); /* For Opera 11.6 to 12.0 */
10. background: -moz-radial-gradient(blue, green, red); /* For Firefox 3.6 to 15 */
11. background: radial-gradient(blue, green, red); /* Standard syntax (must be last) */
12. }
13. </style>
14. </head>
124
ACMS
15. <body>
16. <h3>Radial Gradient - Evenly Spaced Color Stops</h3>
17. <div id="grad1"></div>
18. </body>
19. </html>
Output:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. #grad1 {
6. height: 150px;
7. width: 200px;
8. background: -webkit-radial-gradient(blue 5%, green 15%, red 60%); /* Safari 5.1 to 6.0 */
9. background: -o-radial-gradient(blue 5%, green 15%, red 60%); /* For Opera 11.6 to 12.0 */
10. background: -moz-radial-gradient(blue 5%, green 15%, red 60%); /* For Firefox 3.6 to 15 */
11. background: radial-gradient(blue 5%, green 15%, red 60%); /* Standard syntax (must be last) */
12. }
13. </style>
14. </head>
15. <body>
16. <h3>Radial Gradient - Differently Spaced Color Stops</h3>
17. <div id="grad1"></div>
18. </body>
19. </html>
Output:
CSS Transition
125
ACMS
The CSS transitions are effects that are added to change the element gradually from
one style to another, without using flash or JavaScript.
Let's take an example which defines transition effect on width property and duration of
3 seconds.
Note: If you don't specify the duration part, the transition will have no effect because its
default value is 0. The transition effect is started when you move cursor over an element.
Note: The transition property is not supported by IE9 and earlier version.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. width: 100px;
7. height: 100px;
8. background: orange;
9. -webkit-transition: width 1s; /* For Safari 3.1 to 6.0 */
10. transition: width 1s;
11. }
12. div:hover {
13. width: 300px;
14. }
15. </style>
16. </head>
17. <body>
18. <div></div>
19. <p>Move the cursor over the div element above, to see the transition effect.</p>
20. </body>
21. </html>
Note: When you take mouse cursor out of the element, it gains its original style gradually.
Let's take an example. Here, the transition effects on width, height and transformation.
126
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div {
6. padding:15px;
7. width: 150px;
8. height: 100px;
9. background: violet;
10. -webkit-transition: width 2s, height 2s, -webkit-transform 2s; /* For Safari 3.1 to 6.0 */
11. transition: width 2s, height 2s, transform 2s;
12. }
13. div:hover {
14. width: 300px;
15. height: 200px;
16. -webkit-transform: rotate(360deg); /* Chrome, Safari, Opera */
17. transform: rotate(360deg);
18. }
19. </style>
20. </head>
21. <body>
22. <div><b>Atharva.com</b><p> (Move your cursor on me to see the effect)</p></div>
23. </body>
24. </html>
CSS sticky
The CSS position property is used to set the position for an element. It is also used to place an item
behind another element and also useful for the scripted animation effect. The "position: sticky;" is
used to position the element based on the scroll position of the user.
This CSS property allows the elements to stick when the scroll reaches to a certain point. Depends
upon the scroll position, a sticky element toggles in between fixed and relative. The element will be
positioned relative until the specified position of offset is met in the viewport. Then, similar
to position: fixed, the element sticks in one place.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. body{
6. text-align:center;
7. }
127
ACMS
8. .stick{
9. position: sticky;
10. top:50px;
11. padding: 10px;
12. font-size:20px;
13. font-weight:bold;
14. background-color: lightblue;
15. border: 1px solid blue;
16. }
17. </style>
18. </head>
19. <body>
20. <h1>Scroll and see the effect!</h1>
21. <div class = "stick">Sticky Element</div>
22. <div style = "padding-bottom:2000px">
23. <h2>Hello World</h2>
24. <h2>Welcome to javaTpoint.com</h2>
25. </div>
26. </body>
27. </html>
CSS Tooltips
CSS Tooltips are a great way to display extra information about something when the
user moves the mouse cursor over an element.
1. <!DOCTYPE html>
2. <html>
128
ACMS
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
7. border-bottom: 1px dotted black;
8. }
9. .tooltip .tooltiptext {
10. visibility: hidden;
11. width: 120px;
12. background-color: red;
13. color: #fff;
14. text-align: center;
15. border-radius: 6px;
16. padding: 5px 0;
17. position: absolute;
18. z-index: 1;
19. }
20. .tooltip:hover .tooltiptext {
21. visibility: visible;
22. }
23. </style>
24. <body style="text-align:center;">
25. <p>Move the mouse over the text below:</p>
26. <div class="tooltip">Hover over me
27. <span class="tooltiptext">This is tooltip text</span>
28. </div>
29. </body>
30. </html>
By using tooltips, you can display the position of the tooltip information in four ways:
Top Tooltip
The top tooltip specifies that if you move your mouse cursor over the element, the
tooltip information will be displayed on the top of the element.
1. <!DOCTYPE html>
2. <html>
129
ACMS
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
7. border-bottom: 1px dotted black;
8. }
9. .tooltip .tooltiptext {
10. visibility: hidden;
11. width: 120px;
12. background-color: red;
13. color: #fff;
14. text-align: center;
15. border-radius: 6px;
16. padding: 5px 0;
17. position: absolute;
18. z-index: 1;
19. bottom: 100%;
20. left: 50%;
21. margin-left: -60px;
22. }
23. .tooltip:hover .tooltiptext {
24. visibility: visible;
25. }
26. </style>
27. <body style="text-align:center;">
28. <h2>Top Tooltip Example</h2>
29. <p>Move your mouse cursor over the below heading</p>
30. <div class="tooltip"><strong> Welcome to Atharva</strong>
31. <span class="tooltiptext">A solution of all technology.</span>
32. </div>
33. </body>
34. </html>
Bottom Tooltip
The bottom tooltip specifies that if you move your mouse cursor over the element, the
tooltip information will be displayed on the bottom of the element.
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
130
ACMS
Left Tooltip
The left tooltip specifies that if you move your mouse cursor over the element, the
tooltip information will be displayed on the left side of the element.
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
7. border-bottom: 1px dotted black;
8. }
9. .tooltip .tooltiptext {
131
ACMS
Right Tooltip
The right tooltip specifies that if you move your mouse cursor over the element, the
tooltip information will be displayed on the right side of the element.
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
7. border-bottom: 1px dotted black;
8. }
9. .tooltip .tooltiptext {
10. visibility: hidden;
11. width: 120px;
12. background-color: red;
13. color: #fff;
14. text-align: center;
132
ACMS
Let's take an example to demonstrate the CSS tooltip animation. In this example, the
fade in time is 5 second.
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .tooltip {
5. position: relative;
6. display: inline-block;
7. border-bottom: 1px dotted black;
8. }
9. .tooltip .tooltiptext {
10. visibility: hidden;
11. width: 120px;
12. background-color: red;
13. color: #fff;
14. text-align: center;
15. border-radius: 6px;
16. padding: 5px 0;
133
ACMS
Tablet: 768px
Netbook: 1024px
Desktop: 1600px
This example specifies that if you resize your window less than 500px, the background
134
ACMS
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
5. <style>
6. body {
7. background-color:yellow;
8. }
9.
10. @media only screen and (max-width: 500px) {
11. body {
12. background-color:green;
13. }
14. }
15. </style>
16. </head>
17. <body>
18. <p>If you resize the browser window and the width of this document is less than 500 pix
els, the background-color is "green", otherwise it is "yellow"</p>
19. </body>
20. </html>
135