Why Do We Use Css With HTML
Why Do We Use Css With HTML
An HTML tag is a code that describes how a Web page is formatted. HTML tags are defined by
the characters < and >.
a)<div>
The <div> tag defines a division or a section in an HTML document.
<div id="contentinfo">
<p>Welcome to our website. We provide tutorials on various subjects.</p>
</div>
b)span
c)head
The <head> element can include a title for the document, scripts, styles, meta
information, and more.
<head>
</head>
d)style:
The <style> tag is used to define style information for an HTML document.
Inside the <style> element you specify how HTML elements should render in a
browser.
<style>
h1 {color:red;}
p {color:blue;}
</style>
e)table:
The <tr> element defines a table row, the <th> element defines a table
header, and the <td> element defines a table cell.
f)link:
The <link> tag defines a link between a document and an external resource.
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
The main benefit in CSS, is that it manages to separate the style from the
content on your web page.
- You may want to change the way the HTML output looks. The best way to
do that is with a Cascading Style Sheet (CSS), Font family, type size,
colors,and other styles can be controlled with CSS for each kind of element .
The CSS box model is a box that wraps around every HTML element. It consists
of: margins, borders, padding, and the actual content.
Margin
Border
padding
content
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is transparent
Border - A border that surrounds the padding and content
Margin - Clears an area outside the border. The margin is transparent
The box model allows us to add a border around elements, and to define space
between elements.
Example
div {
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
}
Example
div {
width: 320px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
320px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 0px (left + right margin)
= 350px
Total element width = width + left padding + right padding + left border + right
border + left margin + right margin
Total element height = height + top padding + bottom padding + top border +
bottom border + top margin + bottom margin
Note for old IE: Internet Explorer 8 and earlier versions, include padding and
border in the width property. To fix this problem, add a <!DOCTYPE html> to
the HTML page.
HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files
(text, graphic images, sound, video, and other multimedia files) on the World
Wide Web. HTTP is an application protocol that runs on top of
the TCP/IP suite of protocols
Parameters remain in browser history because they are part of the Parameters are not
URL saved in browser
history.
GET requests are re-executed but may The browser usually alerts the
not be re-submitted to server if the HTML user that data will need to be
is stored in the browser cache. re-submitted.
GET method should not be used when sending POST method used when
passwords or other sensitive information. sending passwords or other
sensitive information.
<p title="I'm a tooltip">
Size Attributes
HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and height)
are all provided as attributes:
<img src="w3schools.jpg" width="104" height="142">
The <hr> element is used to separate content (or define a change) in an HTML
page:
The <head> element is a container for metadata. HTML metadata is data about
the HTML document
<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
Tag Description
<head> A container for all the head elements (title, scripts, styles, meta informati
Output is same with spaces. If <p> is used instead of <pre> the output is it
combines and no spaces are there.
Example:----<body>
</body>
This is subscript and superscri
The HTML <strong> element defines strong text, with added semantic
"strong" importance.(same as bold)
<strong>This text is strong</strong>
The HTML <em> element defines emphasized text, with added semantic
importance.(same as italic)
<em>This text is emphasized</em>
The HTML <small> element defines smaller text:
<h2>HTML <small>Small</small> Formatting</h2>
<h2>HTML <mark>Marked</mark> Formatting</h2>
The HTML <del> element defines deleted (removed) text.
My favorite color is red.
Tag Description
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
Output: WWF's goal is to: “Build a future where people live in harmony with nature.”
Output: For 50 years, WWF has been protecting the future of nature. The
world's leading conservation organization, WWF works in 100 countries and is
supported by 1.2 million members in the United States and close to 5 million
globally.
Here when you place cursor over WHO it shows World Health Organization.
<address>
Visit us at:<br>
Example.com<br>
USA
</address>
Output: The HTML address element defines contact information (author/owner) of a
document or article.
Tag Description
You can add comments to your HTML source by using the following
syntax:
<!-- Write your comments here -->
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet is used to define the style for many HTML pages.
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor. The file must not
contain any HTML code, and must be saved with a .css extension.
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
Example
p {
border: 1px solid powderblue;
}
output:This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
The CSS padding property defines a padding (space) between the text
and the border:
Example
p {
border: 1px solid powderblue;
padding: 30px;
}
This is a paragraph.
This is a paragraph.
This is a paragraph.
Example
p {
border: 1px solid powderblue;
margin: 50px;
}
<html>
<head>
<style>
#p01 {
color: blue;
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
<html>
<head>
<style>
p.error {
color: red;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>55577854</td>
</tr>
<tr>
<td>55577855</td>
</tr>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Output: Coffee
Tea
Milk
With bullets is called unordered list.we use <ul> tag and for data<li>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
IFRAMES:
<iframe src="URL"></iframe>
<iframe src="demo_iframe.htm" height="200" width="300"></iframe>(height and
width)
<iframe src="demo_iframe.htm" style="border:none;"></iframe>(By default, an
iframe has a border around it.remove it by adding border none)
<body>
<p id="demo"></p>
<script>
</script>
</body>
*******example:--<body>
<script>
function myFunction() {
</script>
</body>
This is a demonstration.
<script>
function myFunction() {
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "red";
</script>
-----------------------------------------------------------------------------
Example: <form>
First name:<br>
<br>
Last name:<br>
Last name:
*************radio button
<form>
</form>
****************form action
<body>
<form action="action_page.php">
First name:<br>
<br>
Last name:<br>
<br><br>
</form>
<form action="action_page.php">
<form action="action_page.php" method="get">
or:
<form action="action_page.php" method="post">
If the form submission is passive (like a search engine query), and without
sensitive information.
When you use GET, the form data will be visible in the page address:
POST offers better security because the submitted data is not visible in the page
address.