SlideShare a Scribd company logo
CSS
(CASCADING STYLE SHEETS)
1
WHAT IS CSS?
 Styles were added to HTML 4.0 to solve a problem
 HTML is used to structure content where as CSS is
used for formatting structured content.
 Unlike HTML, CSS doesn’t create anything.
 Instead it decorates, aligns and positions (etc) elements
in HTML.
 In a nut shell, CSS takes the normal HTML output &
adds a few rules to how it is actually displayed.
2
“CSS stands for Cascading Style Sheets”
“CSS is a style language that defines layout of HTML
documents.”
“Styles define how to display HTML elements”
STYLES SOLVED A BIG PROBLEM
 HTML was never intended to contain tags for formatting
a document.
 HTML was intended to define the content of a
document, like:
o <h1>This is a heading</h1>
o <p>This is a paragraph.</p>
 When tags like <font>, and color attributes were added
to the HTML 3.2 specification, it started a nightmare for
web developers. Development of large web sites, where
fonts and color information were added to every single
page, became a long and expensive process.
 To solve this problem, the World Wide Web Consortium
(W3C) created CSS.
 In HTML 4.0, all formatting could be removed from the
HTML document, and stored in a separate CSS file.
 All browsers support CSS today. 3
CSS SAVES A LOT OF WORK!
 Cascading Style Sheets are now the standard
way to define the presentation of your HTML pages.
They are much more efficient than using HTML on
every page to define the look of your site.
 A collection of style is commonly referred to as style
sheets.
 Styles are normally saved in external .css files.
External style sheets enable you to change the
appearance and layout of all the pages in a Web
site, just by editing one single file!
4
CSS RULE
5
CSS RULE:
1. Selector this is the HTML tag that you want to style.
2. Property this is the attribute you adjust, control or
modify.
3. Value it is the style you apply to that property
selector
{ property : value;
property : value;
property : value; }
EXAMPLE:
1. h1 this is the HTML element that you want to
style.
2. color this is the attribute you adjust, control or
modify.
3. blue it is the style you apply to that property
7
h1 { color : blue;}
 Each selector can have multiple properties.
 Each property within the selector can have
independent values.
 The property & value are separated with a
colon & contained within curly brackets.
 Multiple properties are separate by a semi-
colon.
 Multiple values within a property are
separated by commas.
 Value in CSS doesn’t require quotation
marks except if the value has multiple
words.
8
HOW TO ADD CSS TO WEB PAGES?
9
HOW TO ADD CSS IN WEBPAGES:
There are three ways of inserting a
style sheet:
External
style sheet
Internal
style sheet
Inline style 10
ADDING CSS TO WEB PAGES:
1. It can be inserted within the header of a web page 
Internal style sheet
2. It can be inserted within the body of a web page
(usually in certain sections or individual elements)
Inline style sheet
3. It can be inserted within a separate web page 
External style sheet
1.INTERNAL STYLE SHEET
<head>
<style type=“text/css”>
h1 { color : blue;}
</style>
</head>
•The <STYLE> element is used in HEAD section to indicate style
information for the entire document.
•type It declares the type of data which is being linked to the
document. In case of CSS, the only allowed value is text/css.
2.INLINE STYLE SHEETS
 The value of style attribute is any combination of
style declarations.
 Also note that there aren’t any curly braces used
here, but the colon/semicolon rule still applies.
<element style=“…styles…”>
<p style="color: blue; font-family: Arial;
">
3.EXTERNAL STYLE SHEETS
<link rel=“stylesheet” type=“text/css” href=“” >
The <LINK> is a special HEAD element which indicates a
relationship between the current document & some other object. It
is mostly used to link style sheets.
rel It describes the relation of the linked file to the document itself. There
are 2 possible values:
1. stylesheet used to control the way the current document is
rendered.
2. alternate stylesheet used to control the way the current
document is rendered, but will not be used by default if a
"rel='stylesheet'" stylesheet is present and successfully loaded.
type It declares the type of data which is being linked to the document. In
case of CSS, the only allowed value is text/css.
href It is the URL of the external style sheet. Either relative or absolute
URLs may be needed. This attribute is required.
15
DOCUMENT TREE
html
head
Title
Body
h1 p
em
Example1. html
When you nest one element inside another, the nested element
will inherit the properties assigned to the containing element.
Unless you modify the inner element values independently.
COMMENTS IN CSS
/* comment goes here */
A CSS comment begins with
"/*", and ends with "*/", like this:
GROUPING SELECTORS
 In style sheets there are often elements with the
same style.
 To minimize the code, you can group selectors.
 To group selectors, separate them with comma.
h1{color:green;}
h2{color:green;}
p{color:green;}
h1,h2,p {color:green;}
View Example
CONTEXTUAL SELECTORS
 Contextual selectors define styles that are only applied
when certain tags are nested within other tags.
 This allows to use a tag & not have it adopt the CSS
attribute each time it is used.
 The selectors are separated by a space.
p i strong {color: red}
View Example
CLASS SELECTOR
o What would you do if you want some of the
paragraphs to appear bold while other ones do
not?
o Use a class selector!
o Class selectors allow you to associate a class
with a particular subset or class of elements.
GET INTO ACTION!
CLASS SELECTOR
 To create a class selector, use a period (.) followed
by the name you want for the class.
 This allows you to set a particular style for any
HTML elements with the same class.
.col {color:red;}
<p class=“col">
This is an example of multiple
classes.
</p>
GET INTO ACTION!
DIFFERENT INSTANCES OF A CLASS
SELECTOR
p.col {color:red;}
i.col{color:blue;}
• To create a class that can only apply to particular
elements, you need to specify that element in
selector.
• You can create generic selectors that can apply to
every HTML element.
MULTIPLE CLASSES
.applylarge
{
font-size:20px;
}
.applyred
{
color:#FF0000;
}
<p
class="applylarge
applyred">
This is an example
of multiple classes.
</p>
DEFINING CLASS IN CSS STYLE IN HTML <BODY>
ID SELECTOR
 The id selector is used to specify a style for a single,
unique element.
 It is defined by using a # symbol.
GET INTO ACTION!
#red{color:red;}
<h1 id="red"> ID selectors </h1>
CLASS VS ID
 The style is used in various places through out the document.
 The style is very general.
Use class if:
• The style is only used once ever in the document.
• The style is specific to a certain area of the
document.
Use ID if:

More Related Content

ODP
An Introduction to Cascading Style Sheets (CSS3)
PPT
Introduction to Cascading Style Sheets
PPT
Advanced Cascading Style Sheets
PDF
Week 2-intro-html
PPT
cascading style sheet ppt
PPT
How Cascading Style Sheets (CSS) Works
PDF
HTML Foundations, pt 2
PPTX
An Introduction to Cascading Style Sheets (CSS3)
Introduction to Cascading Style Sheets
Advanced Cascading Style Sheets
Week 2-intro-html
cascading style sheet ppt
How Cascading Style Sheets (CSS) Works
HTML Foundations, pt 2

What's hot (20)

PPTX
Web Design Assignment 1
PDF
CSS notes
PPTX
HTML, CSS And JAVASCRIPT!
PPT
Css Ppt
PPTX
css.ppt
PPT
PPTX
Cascading Style Sheet
PPT
Span and Div tags in HTML
PPTX
Html (1)
ODP
CSS Basics
PDF
Intro to HTML and CSS basics
PPTX
Css types internal, external and inline (1)
PDF
Basic-CSS-tutorial
PDF
Html / CSS Presentation
PPT
Css lecture notes
PPTX
Cascading style sheet
PPTX
Html training slide
Web Design Assignment 1
CSS notes
HTML, CSS And JAVASCRIPT!
Css Ppt
css.ppt
Cascading Style Sheet
Span and Div tags in HTML
Html (1)
CSS Basics
Intro to HTML and CSS basics
Css types internal, external and inline (1)
Basic-CSS-tutorial
Html / CSS Presentation
Css lecture notes
Cascading style sheet
Html training slide
Ad

Viewers also liked (16)

PPT
Css advanced – session 4
PPS
Cascading Style Sheets
PPTX
Cashcading stylesheets
PPT
Cascading style sheets (css)
PPT
Cascading Style Sheets
PDF
Html Css
PPT
Cascading Style Sheets By Mukesh
PPTX
Cascading style sheets - CSS
PPT
Cascading Style Sheets(CSS)
PDF
CSS Selectors
PPSX
CSS-Cascading Style Sheets - Introduction
PPT
CSS, CSS Selectors, CSS Box Model
PPTX
Cascading Style Sheets - CSS
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
Css advanced – session 4
Cascading Style Sheets
Cashcading stylesheets
Cascading style sheets (css)
Cascading Style Sheets
Html Css
Cascading Style Sheets By Mukesh
Cascading style sheets - CSS
Cascading Style Sheets(CSS)
CSS Selectors
CSS-Cascading Style Sheets - Introduction
CSS, CSS Selectors, CSS Box Model
Cascading Style Sheets - CSS
LinkedIn SlideShare: Knowledge, Well-Presented
Ad

Similar to Introduction to CSS (20)

PPTX
Lecture 9 CSS part 1.pptxType Classification
PPT
CSS Training in Bangalore
PPTX
Lecture 3CSS part 1.pptx
PPTX
4_css_intro.pptx. this ppt is based on css which is the required of web deve...
PPTX
Web Development - Lecture 5
PPT
css-presentation.ppt
PPTX
chitra
PPTX
cascadingstylesheets,introduction.css styles-210909054722.pptx
PDF
4. Web Technology CSS Basics-1
PPTX
Cascading style sheets
PPTX
Cascading style sheets
PPTX
basic programming language AND HTML CSS JAVApdf
PPT
IP - Lecture 6, 7 Chapter-3 (3).ppt
PPT
Unit 2-CSS & Bootstrap.ppt
PPTX
CSS Basics (Cascading Style Sheet)
PPTX
uptu web technology unit 2 Css
PDF
Css tutorial
PDF
Introduction to css
Lecture 9 CSS part 1.pptxType Classification
CSS Training in Bangalore
Lecture 3CSS part 1.pptx
4_css_intro.pptx. this ppt is based on css which is the required of web deve...
Web Development - Lecture 5
css-presentation.ppt
chitra
cascadingstylesheets,introduction.css styles-210909054722.pptx
4. Web Technology CSS Basics-1
Cascading style sheets
Cascading style sheets
basic programming language AND HTML CSS JAVApdf
IP - Lecture 6, 7 Chapter-3 (3).ppt
Unit 2-CSS & Bootstrap.ppt
CSS Basics (Cascading Style Sheet)
uptu web technology unit 2 Css
Css tutorial
Introduction to css

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Week 4 Term 3 Study Techniques revisited.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial diseases, their pathogenesis and prophylaxis
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

Introduction to CSS

  • 2. WHAT IS CSS?  Styles were added to HTML 4.0 to solve a problem  HTML is used to structure content where as CSS is used for formatting structured content.  Unlike HTML, CSS doesn’t create anything.  Instead it decorates, aligns and positions (etc) elements in HTML.  In a nut shell, CSS takes the normal HTML output & adds a few rules to how it is actually displayed. 2 “CSS stands for Cascading Style Sheets” “CSS is a style language that defines layout of HTML documents.” “Styles define how to display HTML elements”
  • 3. STYLES SOLVED A BIG PROBLEM  HTML was never intended to contain tags for formatting a document.  HTML was intended to define the content of a document, like: o <h1>This is a heading</h1> o <p>This is a paragraph.</p>  When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process.  To solve this problem, the World Wide Web Consortium (W3C) created CSS.  In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file.  All browsers support CSS today. 3
  • 4. CSS SAVES A LOT OF WORK!  Cascading Style Sheets are now the standard way to define the presentation of your HTML pages. They are much more efficient than using HTML on every page to define the look of your site.  A collection of style is commonly referred to as style sheets.  Styles are normally saved in external .css files. External style sheets enable you to change the appearance and layout of all the pages in a Web site, just by editing one single file! 4
  • 6. CSS RULE: 1. Selector this is the HTML tag that you want to style. 2. Property this is the attribute you adjust, control or modify. 3. Value it is the style you apply to that property selector { property : value; property : value; property : value; }
  • 7. EXAMPLE: 1. h1 this is the HTML element that you want to style. 2. color this is the attribute you adjust, control or modify. 3. blue it is the style you apply to that property 7 h1 { color : blue;}
  • 8.  Each selector can have multiple properties.  Each property within the selector can have independent values.  The property & value are separated with a colon & contained within curly brackets.  Multiple properties are separate by a semi- colon.  Multiple values within a property are separated by commas.  Value in CSS doesn’t require quotation marks except if the value has multiple words. 8
  • 9. HOW TO ADD CSS TO WEB PAGES? 9
  • 10. HOW TO ADD CSS IN WEBPAGES: There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style 10
  • 11. ADDING CSS TO WEB PAGES: 1. It can be inserted within the header of a web page  Internal style sheet 2. It can be inserted within the body of a web page (usually in certain sections or individual elements) Inline style sheet 3. It can be inserted within a separate web page  External style sheet
  • 12. 1.INTERNAL STYLE SHEET <head> <style type=“text/css”> h1 { color : blue;} </style> </head> •The <STYLE> element is used in HEAD section to indicate style information for the entire document. •type It declares the type of data which is being linked to the document. In case of CSS, the only allowed value is text/css.
  • 13. 2.INLINE STYLE SHEETS  The value of style attribute is any combination of style declarations.  Also note that there aren’t any curly braces used here, but the colon/semicolon rule still applies. <element style=“…styles…”> <p style="color: blue; font-family: Arial; ">
  • 14. 3.EXTERNAL STYLE SHEETS <link rel=“stylesheet” type=“text/css” href=“” >
  • 15. The <LINK> is a special HEAD element which indicates a relationship between the current document & some other object. It is mostly used to link style sheets. rel It describes the relation of the linked file to the document itself. There are 2 possible values: 1. stylesheet used to control the way the current document is rendered. 2. alternate stylesheet used to control the way the current document is rendered, but will not be used by default if a "rel='stylesheet'" stylesheet is present and successfully loaded. type It declares the type of data which is being linked to the document. In case of CSS, the only allowed value is text/css. href It is the URL of the external style sheet. Either relative or absolute URLs may be needed. This attribute is required. 15
  • 16. DOCUMENT TREE html head Title Body h1 p em Example1. html When you nest one element inside another, the nested element will inherit the properties assigned to the containing element. Unless you modify the inner element values independently.
  • 17. COMMENTS IN CSS /* comment goes here */ A CSS comment begins with "/*", and ends with "*/", like this:
  • 18. GROUPING SELECTORS  In style sheets there are often elements with the same style.  To minimize the code, you can group selectors.  To group selectors, separate them with comma. h1{color:green;} h2{color:green;} p{color:green;} h1,h2,p {color:green;} View Example
  • 19. CONTEXTUAL SELECTORS  Contextual selectors define styles that are only applied when certain tags are nested within other tags.  This allows to use a tag & not have it adopt the CSS attribute each time it is used.  The selectors are separated by a space. p i strong {color: red} View Example
  • 20. CLASS SELECTOR o What would you do if you want some of the paragraphs to appear bold while other ones do not? o Use a class selector! o Class selectors allow you to associate a class with a particular subset or class of elements. GET INTO ACTION!
  • 21. CLASS SELECTOR  To create a class selector, use a period (.) followed by the name you want for the class.  This allows you to set a particular style for any HTML elements with the same class. .col {color:red;} <p class=“col"> This is an example of multiple classes. </p> GET INTO ACTION!
  • 22. DIFFERENT INSTANCES OF A CLASS SELECTOR p.col {color:red;} i.col{color:blue;} • To create a class that can only apply to particular elements, you need to specify that element in selector. • You can create generic selectors that can apply to every HTML element.
  • 23. MULTIPLE CLASSES .applylarge { font-size:20px; } .applyred { color:#FF0000; } <p class="applylarge applyred"> This is an example of multiple classes. </p> DEFINING CLASS IN CSS STYLE IN HTML <BODY>
  • 24. ID SELECTOR  The id selector is used to specify a style for a single, unique element.  It is defined by using a # symbol. GET INTO ACTION! #red{color:red;} <h1 id="red"> ID selectors </h1>
  • 25. CLASS VS ID  The style is used in various places through out the document.  The style is very general. Use class if: • The style is only used once ever in the document. • The style is specific to a certain area of the document. Use ID if: