Web Desigining
Web Desigining
HTML stands for Hyper Text Markup Language, which is the most widely used language on
Web to develop web pages.
HTML was created by Berners-Lee in late 1991 but "HTML 2.0" was the first standard
HTML specification which was published in 1995. HTML 4.01 was a major version of
HTML and it was published in late 1999. Though HTML 4.01 version is widely used but
currently we are having HTML-5 version which is an extension to HTML 4.01, and this
version was published in 2012.
Audience
This tutorial is designed for the aspiring Web Designers and Developers with a need to
understand the HTML in enough detail along with its simple overview, and practical
examples. This tutorial will give you enough ingredients to start with HTML from where you
can take yourself at higher level of expertise.
Prerequisites
Before proceeding with this tutorial you should have a basic working knowledge with
Experience with any text editor like notepad, notepad++, or Edit plus etc.
Audience
.............................................................................................................................................
i
Prerequisites
.............................................................................................................................................
i
Table of Contents
............................................................................................................................................
ii
7 Customize your website with HTML and CSS 2 Hrs Theory + 3 Hrs Practical= 5 Hrs
Total Hrs 50
Web Designing
The collection of all your web pages is called your web site.
To let others view your work, you must publish your web site.
To publish your work, you web site must be copied to a web server.
Most common is to use an Internet Service Provider (ISP) to host web site.
Renting a server from an Internet Service Provider (ISP) is a common option. Here are some
advantages:
Connection Speed
Most ISP providers have very fast connections to the Internet, like full T3 fiber-optic 45Mps
connections equivalent.
Powerful Hardware
Service providers often have many powerful web servers that can be shared by several
companies. You can also expect them to have an effective load balancing, and necessary
backup servers.
Internet Service Providers are specialists on web hosting. Expect their servers to have more
than 99% up time, the latest software patches, and the best virus protection.
24-hour support
Make sure your Internet service provider offers 24-hours support. Toll-free phone could be
vital if you don't want to pay for long distance calls.
Daily Backup
Make sure your service provider runs a secure daily backup routine, otherwise you may lose
some valuable data.
Traffic Volume
Study the provider's traffic volume restrictions. Make sure that you don't have to pay a
fortune for unexpected high traffic if your web site becomes popular.
Study the provider's bandwidth and content restrictions. If you plan to publish pictures or
broadcast video or sound, make sure that you can.
Email Capabilities
Make sure your provider fully supports the email capabilities you need.
Database Access
Make sure your provider fully supports the database access you need if you plan to use
databases from your site
A domain name is a unique name for a web site, like microsoft.com and w3schools.com.
Domain names must be registered. When domain names are registered they are added to a
large domain name register, and information about your site - including your internet IP
address - is stored on a DNS server.
DNS stands for Domain Name System. A DNS server is responsible for informing all other
computers on the Internet about your domain name and your site address.
Domain Name Registration provides registration services for .com .net .org .biz .info .us
.nu .ws .cc and .tv domains.
Newer domain extensions such as .biz .info and .us have more choices available.
The shorter your domain, the easier it is to reach and the less are the chance the user will
make a typographical error while typing it.
Meaningful
Exposure - Search engines index your site and rank it for relevance against terms people
search for online. In order to maximize your sites exposure, consider including a relevant
search term in your domain.
An HTML file can be created using any text editor. NotePad is such an editor and is part of
the typical installation on Windows computers. Here is a simple example based on favorite or
best Web sites for some special hobby or task. Before doing this exercise, you should select a
topic and find two or three Web sites for the topic. You also need to download an image from
each site. Images can be copied from a Web site to your own machine by positioning the
cursor over the image and then clicking on the right mouse button. You will get a dialogue
box with one option, Save Image As. You then get a chance to rename the image and also
locate it in a specific folder.
5. At this point, you should compose a general paragraph on your topic and then a
paragraph about each of the sites you have found. Enter the text below the heading.
Here is a short example:
If you are online and want or need to find out what is happening in the world, you can
go to any of many news sites.
The site I use the most is the online New York Times.
One disadvantage of this site is that to go beyond the first page, you need to subscribe.
It is free, but you need to choose a logon name and a password. However, you can
arrange to save the information on the computer that you typically use. If you do this,
you do not need to be concerned with logging on. The New York Times site is
changed a few times during the day. It contains audio and video.
6. The example we have given above will work as an HTML file. However, it can be
improved in several ways. First of all, even though the text as written appears to have
a paragraph break after the first sentence and another one before ‘One disadvantage..’,
the browser will display this as one continuous piece of text. For the most part,
browsers ignore spacing and line breaks.
7. To put in a break, use the <p> tag in your example to break up the text into
paragraphs. In terms of content, describe the type of owner of each of your examples
and the business purposes, if any, for your site.
8. We want hyperlinks in our example. To do this, we put the phrase ‘Online New York
Times’ between an <a> tag and an </a> tag:
9. Now decide where you want to put your images. Use the img tag. Note: you can insert
the same image more than once.
10. You are now ready to try out your HTML file. Click on File in NotePad and
then Save As. Now give your file a name and also change the extension
from .txt to .htm. Let us say you named it test1.htm
11. Minimize NotePad (by clicking on the underscore in the upper right corner of the
window). Open up Netscape or whatever browser you use. Note: you can do this even
in situations where you usually dial-in to an Internet Service Provider (such as Pace)
first. You may get a message from the browser that it has failed to locate the home
page. If you are doing this in a computer classroom or in the open labs, the computer
is [almost] always online.
Click on OK to close that dialogue box. Now (assuming you are using Netscape),
click on File and then Open Page and Browse. You are opening a local file instead of
going to a Web site. Use the operating system’s procedure for finding the file you just
saved. Click on it and then click on Open. Your HTML file should be displayed in the
browser. Notice any problems and fix them in NotePad. When you get back into the
browser, you will have to click on ReLoad to get the newest version. If reload does
not work, hold down the shift key while clicking on ReLoad. (In Internet Explorer,
use the control key.)
12. One other change you may make to your file is to adjust the size of the images. You
can do this by adding parameters to the img tag. For example,
will align the image to the left. It will also change the width of the image to 100 pixels
and make the height whatever size that will preserve the proportions of the original
image. You can use both width and height parameters to set both values.
13. Lastly, return to the browser and reload your local file. You can now check to see that
your links work correctly.
1. Learn the Basics of HTML
Introduction
HTML Basics
In HTML coding there are various tags that we must consider and include while starting to
code in HTML. These tags help in organization and basic formatting of elements in our script
or web pages. These step by step procedures will guide you through the process of writing
HTML.
What is HTML?
Web pages can be created and modified by using professional HTML editors.
However, for learning HTML we recommend a simple text editor like Notepad (PC) or
TextEdit (Mac).
Below mentioned are the basic HTML tags which divides the whole document into various
parts like head, body etc.
Every HTML document begins with a HTML document tag. Although this is not
mandatory but it is a good convention to start the document with this below mentioned
tag:
<! DOCTYPE html>
<html> : Every HTML code must be enclosed between basic HTML tags. It begins
with <html> and ends with </html> tag.
<head> : The head tag comes next which contains all the header information of the
web page or document like the title of the page and other miscellaneous information.
These information’s are enclosed within head tag which opens with <head> and ends
with </head>. The contents will of this tag will be explained in the later sections of
course.
<title> : We can mention the title of a web page using the <title> tag. This is a header
information and hence mentioned within the header tags. The tag begins
with <title> and ends with </title>
<body> : Next step is the most important of all the tags we have learned so far. The
body tag contains the actual body of the page which will be visible to all the users. This
opens with <body> and ends with </body>. Every content enclosed within this tag will
be shown on the web page be it writings or images or audios or videos or even links.
We will see later in the section how using various tags we may insert mentioned
contents into our web pages.
1)Example
<html>
<head>
<!-- Information about the page -->
<!--This is the comment tag-->
<title>Wel come to Yashaswi</title>
</head>
<body>
<!--Contents of the webpage-->
</body>
</html>
This code won’t display anything. It just shows the basic pattern of how to write the HTML
code and will name the title of the page as Wel Come Yashaswi. <! – – comment here – – >
is the comment tag in HTML and it doesn’t reads the line present inside this tag.
2.HTML Headings
These tags help us to give headings to the content of a webpage. These tags are mainly
written inside the body tag. HTML provides us with six heading tags from <h1> to <h6>.
Every tag displays the heading in a different style and font size.
Example
<html>
<head>
<title>Wel Come Yashaswi</title>
</head>
<body>
<h1> Wel Come Yashaswi </h1>
<h2> Wel Come Yashaswi </h2>
<h3> Wel Come Yashaswi </h3>
<h4> Wel Come Yashaswi </h4>
<h5> Wel Come Yashaswi </h5>
<h6> Wel Come Yashaswi </h6>
</body>
</html>
Output-
These tags help us to write paragraph statements in a webpage. They start with the <p> tag
and ends with <p>. Here the <br> tag is used to break line and acts as a carriage
return. <br> is an empty tag.
Example:
<html>
<head>
<title>Yashaswi</title>
</head>
<body>
<h1>Wel come to Yashaswi</h1>
<p>
A Computer Science portal <br>
A Computer Science portal <br>
A Computer Science portal <br>
</p>
</body>
</html>
Output -
The <hr> tag is used to break the page into various parts, creating horizontal margins with
help of a horizontal line running from left to right hand side of the page. This is also an empty
tag and doesn’t take any additional statements.
Example:
<html>
<head>
<title>Yashaswi</title>
</head>
<body>
<h1>Welcome to Yashaswi</h1>
<p>
A Computer Science portal <br>
A Computer Science portal <br>
A Computer Science portal <br>
</p>
<hr>
<p>
A Computer Science portal <br>
A Computer Science portal <br>
A Computer Science portal <br>
</p>
<hr>
</body>
</html>
Output:
Welcome to Yashaswi
5. HTML Elements
An HTML element is defined by a starting tag. If the element contains other content, it ends
with a closing tag, where the element name is preceded by a forward slash as shown below
with few tags:
<br />
HTML elements can be nested (this means that elements can contain other elements).
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Output:
My First Heading
My first paragraph.
Example Explained
The <html> element is the root element and it defines the whole HTML document.
6.HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name="value"
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link
goes to:
Example
<!DOCTYPE html>
<html>
<body>
<p>HTML links are defined with the a tag. The link address is specified in the href attribute:</p>
</body>
</html>
Output
Visit YASHASWI
If we want to insert an image into a webpage, then we need to use the <img> tag and the src
attribute. We will need to specify the address of the image as the attribute’s value inside the
double quote.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
3) alt Attribute : As the name goes this is an alternate tag that is used to show or display
something if the primary attribute i.e., the <img> tag, fails to display the value assigned to it.
This can also be used to describe the image to a developer who is actually sitting at the
coding end.
Example
<html>
<head>
<title>alt Attribute</title>
</head>
<body>
<!--If the image is not found or the img field
<img src="https://media.geeksforgeeks.org/wp-content/cdn-
uploads/Geek_logi_-low_res.png" alt="The Logo"><br>
<img src="" alt="Since the src value is blank,the alt value is displayed">
</body>
</html>
Output
3)The width and height Attribute : This attribute is used to adjust the width and height of
an image.
Example:
<html>
<head>
</head>
<body>
<img src="https://media.geeksforgeeks.org/wp-content/cdn-
uploads/Geek_logi_-low_res.png" width="300px" height="100px" >
</body>
</html>
Output:
7.HTML | Paragraph
<p> tag:
The <p> tag in HTML defines a paragraph. These have both opening and closing tag. So
anything mentioned within <p> and </p> is treated as a paragraph. Most browsers read a line
as a paragraph even if we don’t use the closing tag i.e, </p>, but this may raise unexpected
results. So, it is both a good convention and we must use the closing tag.
Syntax:
<p> Content </p>
Example
<!DOCTYPE html>
<html>
<head>
<title>Paragraph</title>
</head>
<body>
<p>Wel come to Yashaswi.</p>
<p>It contains well written, well thought articles.</p>
</body>
</html>
Output
As already mentioned, the<p>tag automatically adds space before and after any
paragraph, which is basically margins added by the browser.
If a user adds multiple spaces, the browser reduces them it to a single space.
If a user adds multiple lines, the browser reduces them to a single line.
Example
<!DOCTYPE html>
<html>
<head>
<title>Display_Paragraph</title>
</head>
<body>
<p>
This paragraph has multiple
lines. But HTML reduces them
to a single line, omitting
the carriage return we have used.
</p>
<p>
This paragraph has multiple
spaces. But HTML reduces them
all to a single space, omitting
the extra spaces and line we have used.
</p>
</body>
</html>
Output
This paragraph has multiple lines. But HTML reduces them to a single line, omitting the carriage return we have
used.
This paragraph has multiple spaces. But HTML reduces them all to a single space, omitting the extra spaces and
line we have used.
<br> tag:
There is a way to let the HTML know where does the browser need to change the lines by the
use of <br> tag. These tags do not have any closing tag. So, just a single opening tag will
change the line.
Syntax:
<br>
Example
<!DOCTYPE html>
<html>
<head>
<title>Display_Paragraph</title>
</head>
<body>
<p>
This paragraph has multiple<br>lines.
But HTML reduces them<br>to a single
line, omitting<br>the carriage return
we have used.
</p>
</body>
</html>
Output:
8. HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and
more.
Example
<!DOCTYPE html>
<html>
<body>
<p>I am normal</p>
</body>
</html>
Output:
I am normal
I am red
I am blue
I am big
<!DOCTYPE html>
<html>
<head>
<title>Bold</title>
</head>
<body>
<!--Normal text-->
<p>Wel come all</p>
<!--Text in Bold-->
<p><b>Wel come all</b></p>
<!--Text in Strong-->
<p><strong> Wel come all</strong></p>
</body>
</html>
Output
Wel come all
Example:
<!DOCTYPE html>
<html>
<head>
<title>Italic</title>
</head>
<body>
<!--Normal text-->
<p>Wel come all</p>
<!--Text in Italics-->
<p><i> Wel come all </i></p>
<!--Text in Emphasize-->
<p><em> Wel come all </em></p>
</body>
</html>
Output:
Example:
<!DOCTYPE html>
<html>
<head>
<title>Highlight</title>
</head>
<body>
<!--Text in Normal-->
<p>Wel come all</p>
<!--Text in Highlight-->
<p><mark>Wel come all</mark></p>
</body>
</html>
Output
Example:
<!DOCTYPE html>
<html>
<head>
<title>Superscript and Subscript</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Superscript-->
<p>Hello <sup>GeeksforGeeks</sup></p>
<!--Text in Subcript-->
<p>Hello <sub>GeeksforGeeks</sub></p>
</body>
</html>
Output
Hello GeeksforGeeks
Hello GeeksforGeeks
Hello GeeksforGeeks
5.Making text smaller: The <small> element is used to make the text smaller. The text that
needs to be displayed smaller should be written inside <small> and </small> tag.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Small</title>
</head>
<body>
<!--Text in Normal-->
<p>Wel come all</p>
<!--Text in small-->
<p><small>Wel come all</small></p>
</body>
</html>
Output
6.Striking through the text: The <del> element is used to strike through the text marking
the part as deleted. It also has an opening and a closing tag.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Delete</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Delete-->
<p><del>Hello GeeksforGeeks</del></p>
</body>
</html>
Output:
7.Adding a text: The <ins> element is used to underline a text marking the part as inserted
or added. It also has an opening and a closing tag.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Inserting</title>
</head>
<body>
<!--Text in Normal-->
<p>Hello GeeksforGeeks</p>
<!--Text in Insert-->
<p><ins>Hello GeeksforGeeks</ins></p>
</body>
</html>
Output:
10. HTML Quotations
The Quotation elements in HTML are used to insert quoted texts in a web page, that is,
portion of texts different from the normal texts in the web page.
Below are some of the most used quotation elements of HTML:
1) <q> element:
The <q> element is used to set a set of text inside the quotation marks. It has both opening
and closing tags.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Quotations</title>
</head>
<body>
<h3>Wel Come</h3>
<p>The quick brown fox jumps over the lazy dog<br></p>
<!--Inside quotes-->
<p><q>The quick brown fox jumps over the lazy dog</q></p>
</body>
</html>
Output
Wel Come
2.<blockquote> element:
The <blockquote> element is also used for quotations in a different way. Instead of putting
the text in quotes, it changes the alignment to make it unique from others. It has both opening
and closing tags.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Blockquote</title>
</head>
<body>
<h3>Wel come</h3>
<p>The quick brown fox jumps over the lazy dog<br></p>
<!--Inside blockquotes-->
<p><blockquote>The quick brown fox jumps
over the lazy dog</blockquote></p>
</body>
</html>
Output
Wel come
3. <address> element:
Using the <address> element, we can define an address in a webpage and the text put inside
the address tag will be emphasized. It has both opening and closing tags.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Address</title>
</head>
<body>
<h3>Welcome</h3>
<address>
<p>Address:<br>
</address>
</body>
</html>
Output
Welcome
Address:
710-B, Advant Navis Business Park,
Sector-142, Noida Uttar Pradesh – 201305
11. HTML Tables
A table is an arrangement of data in rows and columns, or possibly in a more complex
structure. Tables are widely used in communication, research, and data analysis.
Tables are useful for various tasks such as presenting text information and numerical
data.
Tables can be used to compare two or more items in tabular form layout.
Tables are used to create databases.
Example:
<!DOCTYPE html>
<html>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output
2)Adding a border to a HTML Table: A border is set using the CSS border
property. If you do not specify a border for the table, it will be displayed without
borders.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output
3)Adding Collapsed Borders in a HTML Table: For borders to collapse into one
border, add the CSS border-collapse property.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output
Example:
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
table {
border-spacing: 5px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output
12.HTML Lists
What is a list?
A list is a record of short pieces of information, such as people’s names, usually
written or printed with a single thing on each line and ordered in a way that makes a
particular thing easy to find.
For example:
A shopping list
To-do list
Lists in HTML
HTML offers three ways for specifying lists of information. All lists must contain one or more
list
elements.
An unordered list starts with the “ul” tag. Each list item starts with the “li” tag.The list items
are marked with bullets i.e small black circles by default.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Grocery list</h2>
<ul>
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ul>
</body>
</html>
Output
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Disc Bullets</h2>
<h2>Grocery List</h2>
<ul style="list-style-type:disc">
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ul>
</body>
</html>
Output :
Output
An ordered list starts with the “ol” tag. Each list item starts with the “li” tag. The list
items are marked with numbers by default.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Grocery List</h2>
<ol>
<li>Bread</li>
<li>Eggs</li>
<li>Milk</li>
<li>Coffee</li>
</ol>
</body>
</html>
Output
13.HTML Images
Images can improve the design and the appearance of a web page.
Example-
<!DOCTYPE html>
<html>
<body>
<h2>HTML Image</h2>
</body>
</html>
Output
14.HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
Each table row is defined with a <tr> tag. Each table header is defined with a <th> tag. Each
table data/cell is defined with a <td> tag.
Example
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
width: 100%;
td, th {
text-align: left;
padding: 8px;
tr:nth-child(even) {
background-color: #dddddd;
</style>
</head>
<body>
Output
HTML Table
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</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>
Output
You cannot have more than one element with the same id in an HTML document.
The id attribute specifies a unique id for an HTML element. The value of the id attribute must
be unique within the HTML document.
The id attribute is used to point to a specific style declaration in a style sheet. It is also used
by JavaScript to access and manipulate the element with the specific id.
The syntax for id is: write a hash character (#) character, followed by an id name. Then,
define the CSS properties within curly braces {}.
In the following example we have an <h1> element that points to the id name "myHeader".
This <h1> element will be styled according to the #myHeader style definition in the head
section:
Example
<!DOCTYPE html>
<html>
<head>
<style>
#myHeader {
background-color: lightblue;
color: black;
padding: 40px;
text-align: center;
</style>
</head>
<body>
<h2>The id Attribute</h2>
</body>
</html>
Output
The id Attribute
Use CSS to style an element with the id "myHeader":
My Header
HTML has several semantic elements that define the different parts of a web page:
<header> - Defines a header for a document or a section
<nav> - Defines a set of navigation links
<section> - Defines a section in a document
<article> - Defines an independent, self-contained content
<aside> - Defines content aside from the content (like a sidebar)
<footer> - Defines a footer for a document or a section
<details> - Defines additional details that the user can open and close on
demand
<summary> - Defines a heading for the <details> element
There are four different techniques to create multicolumn layouts. Each technique has its pros
and cons:
CSS framework
CSS float property
CSS flexbox
CSS grid
1.CSS Introduction
What is 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
External style sheets are stored in CSS files.
CSS Syntax
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded
by curly braces.
Example
In this example all <p> elements will be center-aligned, with a red text color:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
</style>
</head>
<body>
<p>Hello World!</p>
</html>
Output
Hello World!
Example Explained
p is a selector in CSS (it points to the HTML element you want to style: <p>).
color is a property, and red is the property value
text-align is a property, and center is the property value.
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
</style>
</head>
<body>
</body>
</html>
Output:
The universal selector (*) selects all HTML elements on the page.
Example
The CSS rule below will affect every HTML element on the page:
<!DOCTYPE html>
<html>
<head>
<style>
*{
text-align: center;
color: blue;
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>And me!</p>
</body>
</html>
Output
Hello world!
Me too!
And me!
The grouping selector selects all the HTML elements with the same style definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style definitions):
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
Output
Hello World!
Smaller heading!
This is a paragraph.
3.CSS Comments
Comments are used to explain the code, and may help when you edit the source code at a
later date.
A CSS comment is placed inside the <style> element, and starts with /* and ends with */:
Example
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
</style>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
Output
Hello World!
4.CSS Colors
Colors are specified using predefined color names, or RGB, HEX, HSL, RGBA, HSLA
values.
Tomato
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
Violet
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-color:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body>
</html>
Hello World
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat.
Example
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Tomato;">Hello World</h3>
</body>
</html>
Output:
Hello World
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Hello World
Hello World
Hello World
7.CSS Backgrounds
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
CSS background-image
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("Desert.jpg");
</style>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
8.CSS Borders
CSS Border Style
The border-style property can have from one to four values (for the top border, right border,
bottom border, and the left border).
Example
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
</html>
Output
A dotted border.
A dashed border.
A solid border.
A double border.
A groove border.
A ridge border.
An inset border.
An outset border.
No border.
A hidden border.
A mixed border.
9.CSS Margins
The CSS margin properties are used to create space around elements, outside of any defined
borders.
With CSS, you have full control over the margins. There are properties for setting the margin
for each side of an element (top, right, bottom, and left).
CSS has properties for specifying the margin for each side of an element:
margin-top
margin-right
margin-bottom
margin-left
Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: lightblue;
</style>
</head>
<body>
<div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin
of 100px, and a left margin of 80px.</div>
</body>
</html>
CSS Outline
An outline is a line that is drawn around elements, OUTSIDE the borders, to make the element
"stand out".
The outline-style property specifies the style of the outline, and can have one of the following
values:
Example
<!DOCTYPE html>
<html>
<head>
<style>
p {outline-color:red;}
</style>
</head>
<body>
<p class="groove">A groove outline. The effect depends on the outline-color value.</p>
<p class="ridge">A ridge outline. The effect depends on the outline-color value.</p>
<p class="inset">An inset outline. The effect depends on the outline-color value.</p>
<p class="outset">An outset outline. The effect depends on the outline-color value.</p>
</body>
</html>
Output
CSS Text
Text Color
The color property is used to set the color of the text. The color is specified by:
The default text color for a page is defined in the body selector.
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: blue;
}
h1 {
color: green;
</style>
</head>
<body>
<p>This is an ordinary paragraph. Notice that this text is blue. The default text color for a
page is defined in the body selector.</p>
<p>Another paragraph.</p>
</body>
</html>
Output
This is heading 1
This is an ordinary paragraph. Notice that this text is blue. The default text color
for a page is defined in the body selector.
Another paragraph.
CSS Icons
How To Add Icons
The simplest way to add an icon to your HTML page, is with an icon library, such as Font
Awesome.
Add the name of the specified icon class to any inline HTML element (like <i> or <span>).
All the icons in the icon libraries below, are scalable vectors that can be customized with CSS
(size, color, shadow, etc.)
To use the Font Awesome icons, go to fontawesome.com, sign in, and get a code to add in
the <head> section of your HTML page:
<script src="https://kit.fontawesome.com/yourcode.js"></script>
Read more about how to get started with Font Awesome in our Font Awesome 5 tutorial.
Example
<!DOCTYPE html>
<html>
<head>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>
<p>Some Font Awesome icons:</p>
</body>
</html>
Output
CSS Links
Styling Links
Links can be styled with any CSS property (e.g. color, font-family, background, etc.).
Example-
<!DOCTYPE html>
<html>
<head>
<style>
/* unvisited link */
a:link {
color: red;
/* visited link */
a:visited {
color: green;
a:hover {
color: hotpink;
/* selected link */
a:active {
color: blue;
</style>
</head>
<body>
<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS definition in
order to be effective.</p>
<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in order to be
effective.</p>
</body>
</html>
Output
This is a link
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order
to be effective.
Bootstrap is a free front-end framework for faster and easier web development
Bootstrap includes HTML and CSS based design templates for typography, forms,
buttons, tables, navigation, modals, image carousels and many other, as well as
optional JavaScript plugins
Bootstrap also gives you the ability to easily create responsive designs.
If you do not want to use all 12 columns individually, you can group the columns together to
create wider columns:
span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
The classes above can be combined to create more dynamic and flexible
Bootstrap Text/Typography
Bootstrap's Default Settings
Bootstrap's global default font-size is 14px, with a line-height of 1.428.
<h1> - <h6>
By default, Bootstrap will style the HTML headings (<h1> to <h6>) in the
following way:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
</div>
</body>
</html>
Output
Bootstrap Tables
Bootstrap Basic Table
A basic Bootstrap table has a light padding and only horizontal dividers.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Basic Table</h2>
<p>The .table class adds basic styling (light padding and only horizontal dividers) to a
table:</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Output
Basic Table
The .table class adds basic styling (light padding and only horizontal dividers) to a table:
Bootstrap Alerts
Alerts
Bootstrap provides an easy way to create predefined alert messages:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></sc
ript>
</head>
<body>
<div class="container">
<h2>Alerts</h2>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Output
Alerts
Success! This alert box could indicate a successful or positive action.
Warning! This alert box could indicate a warning that might need attention.
Button Styles
Bootstrap provides different styles of buttons:
Basic Default Primary Success Info Warning Danger Link
To achieve the button styles above, Bootstrap has the following classes:
.btn
.btn-default
.btn-primary
.btn-success
.btn-info
.btn-warning
.btn-danger
.btn-link
The following example shows the code for the different button styles:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Button Styles</h2>
</div>
</body>
</html>
Output
Bootstrap Glyphicons
Glyphicons
Bootstrap provides 260 glyphicons from the Glyphicons Halflings set.
Envelope glyphicon:
Print glyphicon:
Search glyphicon:
Download glyphicon:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></sc
ript>
</head>
<body>
<div class="container">
<h2>Glyphicon Examples</h2>
</p>
</button>
</p>
</button>
</p>
</a>
</p>
</div>
</body>
</html>
Output