CSS----1---1-_1694424059148
CSS----1---1-_1694424059148
● Using CSS, you can specify a number of style properties for a given
HTML element. Each property has a name and a value, separated by a
colon (:).
● Pages load faster – If you are using CSS, you do not need to write HTML tag
attributes every time. Just write one CSS rule of a tag and apply to all the occurrences of that tag.
So less code means faster download times.
● Easy maintenance – To make a global change, simply change the style, and all elements in
all the web pages will be updated automatically.
● Superior styles to HTML – CSS has a much wider array of attributes than HTML so you can
give far better look to your HTML page in comparison of HTML attributes.
● Global web standards – Now HTML attributes are being deprecated and it is being
recommended to use CSS. So it’s a good idea to start using CSS in all the HTML pages to
make them compatible to future browsers.
Steps for adding CSS to HTML
1. write contents of webpage using html
2. In head tag add CSS using <style> tag.
<html>
<head>
<style>
</style>
</head>
</html>
selector
CSS syntax:
declaration
Eg: h1{color:blue;font-size:12px;}
property value
You can use CSS in three ways in your HTML
document:
External Style Sheet – Define style sheet rules in a
separate .css file and then include that file in your HTML
document using HTML <link> tag.
<html>
<head>
<style>
h1{ text-align:left;}
h2{color:green;}
h3{color:red;text-align:left;}
</style>
</head>
<body>
<h1>education</h1>
<h2>computer</h2>
<h3>class 11</h3>
</body>
</html>
2.2 External Style Sheet
If you need to use your style sheet to various pages, then it’s always recommended
to define a common style sheet in a separate file. A cascading style sheet file will
have extension as css and it will be included in HTML files using <link> tag.
*In this <style> tag is not required,in head section
*only put the <link>tag
The attribute of link tag is relation rel:(defines the relationship between linked file and html document),
type:(defines the type of file used), href:(it defines the URL of the style sheet file)
Eg:
Mystyle.css
h1{ color:orange;text-align:centre;}
h2{color:green;}
h3{color:red;text-align:left;}
<html>
<head>
<link rel=”stylesheet” type=”text/css” href= ”Mystyle.css”>
</head>
<body>
<h1>education</h1>
<h2>computer</h2>
<h3>class 11</h3>
</body>
</html>
2.4 Inline Style Sheet
You can apply style sheet rules directly to any HTML element using style attribute of
the relevant tag. This should be done only when you are interested to make a
particular change in any HTML element only.
Rules defined inline with the element overrides the rules defined in an external CSS
File as well as the rules defined in <style> tag.
Example
Let’s re-write above example once again, but here we will write style sheet rules
Along with the HTML elements using style attribute of those elements.
<html>
<head>
<title>HTML Inline CSS</title>
</head>
<body>
<p style=“color:red;”>This is red</p>
<p style=“font-size:20px;”>This is thick</p>
<p style=“color:green;”>This is green</p>
<p style=“color:green;font-size:20px;”>This is thick and green</p>
</body>
</html>