CSS Tutorial || Introduction
Introduction to CSS
Result
mystyle.css
- CSS stands for Cascading Style Sheet.
- CSS is an extension of basic HTML that allows you to style your web pages.
- External stylesheets are stored in CSS files
- <!DOCTYPE>
- <html>
- <head>
- <style>
- h1{
- color:white;
- background-color:red;
- padding:5px;
- }
- p{
- color:green;
- }
- </style>
- </head>
- <body>
- <h1>hello!</h1>
- <p>This is Paragraph.</p>
- </body>
- </html>
Result
hello!
This is Paragraph.
CSS Syntax
Selector
It indicates the HTML element you want to style. It could be any tag like <p>, <title> etc.
Declaration
Each declaration includes a CSS property name and a value, separated by a colon.
- color: red;
- font-size: 10 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 "red" is assigned to color property.
Insert CSS
three ways of inserting a style sheet
- External CSS
- Internal CSS
- Inline CSS
1.External CSS
External styles are defined within the <link> element, inside the <head> section
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>heading</h1>
<p>paragraph1.</p>
</body>
</html>
An external style sheet can be written in any text editor, and must be saved with a .css extension.
mystyle.css
body {
background-color: red;}
h1 {
color: blue;
margin-left: 20px;}
2.Internal CSS
Internal styles are defined within the <style> element, inside the <head> section of an HTML page
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: red;}
h1 {
color: blue;
margin-left: 20px;}</style>
</head>
<body>
<h1>heading</h1>
<p>paragraph1.</p>
</body>
</html>
3.Inline CSS
Inline styles are defined within the style="" attribute of the relevant element
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;text-align:center;font-size:122px">heading</h1>
<p style="color:red;">paragraph.</p>
</body>
</html>