Webtechnologypart 2
Webtechnologypart 2
CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation, formatting,
and layout of a document written in HTML. CSS allows you to separate the design and layout from
the structure and content, providing flexibility and better maintenance of your web application.
Types of CSS
There are three main types of CSS: Inline CSS, Internal CSS, and External CSS. Below is a
detailed explanation of each type with examples.
1. Inline CSS
• Applied directly within an HTML element using the style attribute.
• Best suited for quick styling or testing but not recommended for large-scale projects.
Example 1: Change text color and font size
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS Example</title>
</head>
<body>
<h1 style="color: blue; font-size: 36px;text-align:center;">Hello,
World!</h1>
<p style="color: green; font-size: 18px;font-
family:jokerman;border:dotted;margin:10px;">This is a paragraph with inline
CSS.</p>
</body>
</html>
2. Internal CSS
• Defined within a <style> block inside the <head> section of the HTML document.
• Useful for styling a single document and keeping all styles in one place.
Example 1: Styling headings and paragraphs
html
<!DOCTYPE html>
<html>
<head>
<title>Internal CSS Example</title>
<style>
h1 {
color: red;
font-size: 40px;
}
p {
color: blue;
font-size: 20px;
text-align: justify;
}
h2:hover{
background-color:red;
width:fit-content;
</style>
</head>
<body>
<h2> HOVER </h2>
<h1>Internal CSS Example</h1>
<p>This paragraph is styled using internal CSS.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightgray;
}
div {
border: 2px solid black;
padding: 10px;
margin: 20px;
}
</style>
</head>
<body>
<div>This is a styled div using internal CSS.</div>
</body>
</html>
3. External CSS
• Stored in an external file with the .css extension.
• Linked to the HTML document using the <link> tag in the <head> section.
• Ideal for large projects as it separates content from design, ensuring consistency across
multiple pages.
Example 1: Using an external CSS file
HTML File:
html
<!DOCTYPE html>
<html>
<head>
<title>External CSS Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Welcome to External CSS</h1>
<p>This is a paragraph styled using external CSS.</p>
</body>
</html>
h1 {
color: purple;
font-size: 50px;
text-align: center;
}
p {
color: darkgray;
font-size: 18px;
line-height: 1.5;
}