Unit 5 – Introduction to CSS
Unit 5 – Introduction to CSS
Basic of CSS
Advantages of CSS,
Advantages of CSS
CSS has many advantages that enable developers to design a website. Some of these advantages are:
1. Better Website Speed
For a website to function efficiently, it should have a faster load time. In modern times, people usually
wait for just a couple of seconds for a website to load. So, it’s important to ensure faster speed. For
companies wanting to ensure a faster and smooth website experience, CSS becomes paramount to
their success.
2. Easier to Maintain
CSS is easy to maintain due to less maintenance time. This is because a single line code change affects
the entire web page. Also, if improvements are required, then less effort is required to affect changes in
the webpage code.
3. Consistent Design
You would have seen many websites that are elegant and user-friendly. One thing common to all these
websites is consistency in design. CSS enables developers to ensure the style elements are applied
consistently across several web pages.
4. Time-Saving
Due to faster speed and easier maintenance, CSS saves a lot of time and effort in the web development
process due to faster loading time. Here, lesser time ensures designer efficiency.
5. Better Device Compatibility
People use different smart devices to view a particular website. It can be a smartphone, PC or laptop.
For this purpose, websites are required to be device compatible. CSS ensures the task is done smoothly
by providing better compatibility.
6. Positioning of Design Elements
You can change the position of an HTML tag with the help of CSS. You can place the elements like an
image on any part of the webpage as and when required.
CSS Syntax
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.
1. Selector{Property1: value1; Property2: value2; ..........;}
.A CSS Syntax rule consists of a selector, property, and its value. The selector points to the HTML
element where the CSS style is to be applied. The CSS property is separated by semicolons. It is a
combination of the selector name followed by the property: value pair that is defined for the specific
selector.
<!DOCTYPE html>
<html>
<head>
<!-- Style on h1 elements -->
<style>
h1 {
color: green;
text-align: center;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
</body>
</html>
Internal CSS
The internal style sheet is used to add a unique style for a single document. It is defined in <head>
section of the HTML page inside the <style> tag.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: red;
margin-left: 80px;
}
</style>
</head>
<body>
<h1>The internal style sheet is applied on this heading.</h1>
<p>This paragraph will not be affected.</p>
</body>
1. </html>
External CSS
The external style sheet is generally used when you want to make changes on multiple pages. It is ideal
for this condition because it facilitates you to change the look of the entire web site by changing just
one file.
It uses the <link> tag on every pages and the <link> tag should be put inside the head section.
Example:
1. <head>
2. <link rel="stylesheet" type="text/css" href="mystyle.css">
3. </head>
The external style sheet may be written in any text editor but must be saved with a .css extension. This
file should not contain HTML elements.
Important question
What is CSS? Explain External CSS
Explain the role of CSS in web designing
What is CSS? Explain Advantages of CSS.
Describe Internal and External CSS.