SlideShare a Scribd company logo
Web Programming
SYED SHAHZAIB SOHAIL
Lecture 5
Introduction to CSS
Contents
• What is CSS?
• Why use CSS?
• Ways to use CSS
• Big Problem
• CSS Syntax
• CSS Selectors and its types
• Grouping Selectors
• CSS Comments
What is CSS?
• CSS stands for Cascading Style Sheets
• CSS defines the presentation ofWeb Pages
• CSS describes how HTML elements are to be displayed on screen, paper or
in other media
• CSS saves a lot of work. It can control the layout of multiple web pages at
once
Why use CSS?
• CSS is used to defines styles of your web pages, including the design, layout
and variations in display for different devices and screen sizes.
Ways to use CSS
• CSS can be used in 3 different ways.
• Inline CSS
• Internal CSS
• External CSS
Continued…
• Inline CSS
• Inline CSS allows you to apply a unique style to one HTML element at a time.
• You assign CSS to a specific HTML tag by using style attribute with any CSS properties
defined within it.
• Inline CSS style will always override style properties determined in internal or external
files.
<p style=“color: blue;”>This is a paragraph</p>
This is a paragraph
Continued…
• 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.
Continued…
• 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 website by
changing just one file.
• It used the <link> tag on every pages and the <link> tag should be put inside the head section.
<head>
<link rel=“stylesheet” type=“text/css” href=“style.css”>
</head>
• The external style sheet may be written in text editor but must be saved with a .css extension.This
file should not contain HTML elements
•What style will be used when there is more than one
style specified for an HTML element?
Continued…
• If there are multiple style sheets the priority level is defined as following:
1. Inline style sheet
2. Internal style sheet
3. External style sheet
Big Problem
• HTML was never intended to contain tags for formatting a web page
• HTML was created to describe the content of the web page
• 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
websites, where fonts and color information were added to every single page,
became a long and expensive process
• To solve this problem, theWorld Wide Web Consortium (W3C) created CSS that
removed the style formatting from the HTML page
CSS Syntax
• A CSS rule-set consists of a selector and a declaration block:
H1 {color:blue; font-size:12px;}
Selector Declaration Declaration
Property Value Property Value
Continued...
• The selector points to the HTML element you want to style
• The declaration block contains one or more declarations separated by
semicolons
• Each declaration includes a CSS property name and a value, separated by
semicolon
• A CSS declaration always ends with a semicolon and declaration blocks are
surrounded by curly braces
CSS Selectors
• CSS selectors are used to “find” (or select) HTML elements based on their
element name, id, class, attribute and more
Types of CSS Selectors
• There are 3 types of CSS selectors
• Element Selector
• Id Selector
• Class Selector
• Child Selector
• Attribute Selector
Continued…
• Element Selector
• The element selector selects elements based on the element name.
• Id Selector
• The id selector used the id attribute of an HTML element to select a specific element.
• The id of an element should be unique within a page, so the id selector is used to select
one unique element.
• To select an element with a specific id, write a hash character, followed by the id of the
element.
Continued…
• Class Selector
• The class selector selects elements with a specific class attribute.
• To select elements with a specific class, write a period character, followed by the name of
the class.
.center {text-align: center; color: red;}
• You can also specify that only specific HTML elements should be affected by a class.
p. center {text-align: center; color: red;}
• HTML elements can also refer to more than one class.
<p class=“center large”>This paragraph refers to two classes</p>
Continued…
• Child Selector
body > p {color: #000000;}
• Attribute Selector
• You can also apply styles to HTML elements with particular attributes
• input[type=“text”] {color: #000000;}
Grouping Selectors
• If you have elements with the same style definitions, like
• h1 {text-align: center; color: red;}
• h2 {text-align: center; color: red;}
• p {text-align: center; color: red;}
• It will be better to group the selectors, to minimize the code.
• To group selectors, separate each selector with a comma.
• h1, h2, p {text-align: center; color: red;}
CSS Comments
• Comments are used to explain the code, and may help when you edit the
source code at a later date
• Comments are ignored by browsers
• A CSS comment starts with /* and ends with */
• Single Line and Multiline Comments

More Related Content

PPTX
Web Development - Lecture 3
PPTX
Web Development - Lecture 4
PPTX
Web Development - Lecture 2
PPTX
Web Development - Lecture 6
PPTX
CSS Basics (Cascading Style Sheet)
PPTX
Introduction to CSS
Web Development - Lecture 3
Web Development - Lecture 4
Web Development - Lecture 2
Web Development - Lecture 6
CSS Basics (Cascading Style Sheet)
Introduction to CSS

What's hot (20)

PDF
PPT
Introduction to CSS
PPT
Introduction to Cascading Style Sheets (CSS)
PPTX
Responsive web design with html5 and css3
PPTX
Html and css
PPTX
Css types internal, external and inline (1)
PPTX
chitra
PPTX
What is CSS?
PPTX
Ia css
PPTX
CSS (Cascading Style Sheet)
PPT
CSS 101
PPTX
Complete Lecture on Css presentation
PPTX
Cascading Style Sheets - CSS
PDF
Web Development 3 (HTML & CSS)
PPTX
Cascading style sheets
PPTX
CSS Basic Introduction, Rules, And Tips
PDF
Web Development 1 (HTML & CSS)
Introduction to CSS
Introduction to Cascading Style Sheets (CSS)
Responsive web design with html5 and css3
Html and css
Css types internal, external and inline (1)
chitra
What is CSS?
Ia css
CSS (Cascading Style Sheet)
CSS 101
Complete Lecture on Css presentation
Cascading Style Sheets - CSS
Web Development 3 (HTML & CSS)
Cascading style sheets
CSS Basic Introduction, Rules, And Tips
Web Development 1 (HTML & CSS)
Ad

Similar to Web Development - Lecture 5 (20)

PPTX
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
PPTX
Introduction to Wed System And Technologies (1).pptx
PPTX
basic programming language AND HTML CSS JAVApdf
PPTX
WEB TECHNOLOGY Unit-2.pptx
PPTX
Cascading Styling Sheets(CSS) simple design language intended to transform th...
PPTX
Unit 2 WT-CSS.pptx web technology project
PPTX
Cascading style sheet an introduction
PPTX
Cascading Style Sheets for web browser.pptx
PPTX
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx
PPTX
BITM3730 9-19.pptx
PPTX
BITM3730Week4.pptx
PPTX
BITM3730 9-20.pptx
PPTX
Cascading Style Sheets (CSS) LEVELS.pptx
PPTX
PPTX
CSS Introduction
PPTX
cascadingstylesheets,introduction.css styles-210909054722.pptx
PPTX
Cascading style sheets
PPTX
CSS tutorial chapter 1
PPTX
CSS Basics part One
UNIT 3WOP fgfufhbuiibpvihbvpihivbhibvipuuvbiuvboi
Introduction to Wed System And Technologies (1).pptx
basic programming language AND HTML CSS JAVApdf
WEB TECHNOLOGY Unit-2.pptx
Cascading Styling Sheets(CSS) simple design language intended to transform th...
Unit 2 WT-CSS.pptx web technology project
Cascading style sheet an introduction
Cascading Style Sheets for web browser.pptx
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx
BITM3730 9-19.pptx
BITM3730Week4.pptx
BITM3730 9-20.pptx
Cascading Style Sheets (CSS) LEVELS.pptx
CSS Introduction
cascadingstylesheets,introduction.css styles-210909054722.pptx
Cascading style sheets
CSS tutorial chapter 1
CSS Basics part One
Ad

Recently uploaded (20)

PDF
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf
PPTX
Turn ideas into stunning timelines in seconds—powered by smart AI: AI Timelin...
PDF
10 Best UI UX Design Company in UK for User-Centric Solutions
PDF
URBAN DESIGN DESKTOP CASESTUDY IITG.pdf
PPTX
TLE-10-PPTHAJAOSBDJDEKSNbknbtktktmktkttk
PPTX
Simple Business Pitch · SlidesMania 13.pptx
PPTX
Why Great Design Is the Missing Piece in Your ESG Reporting Strategy.pptx
PPTX
503ea471-f798-4324-90e8-275bdab41942.pptx
PDF
SS27 Environments & Design Trend Book Peclers Paris
PDF
High-frequency high-voltage transformer outline drawing
PDF
The Advantages of Working With a Design-Build Studio
DOCX
The story of the first moon landing.docx
PDF
Top 10 UI/UX Design Agencies in Dubai Shaping Digital Experiences
PDF
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
PPTX
KOTA LAMA BANYUMAS.pptxxxxxxxxxxxxxxxxxxxx
DOCX
actividad 20% informatica microsoft project
PDF
AUB Collaborative Book Project - Keiko Toyoda
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PDF
ALDO ROSSI AND MICHAEL GRAVES THEORY OF DESIGN-02 , PRESENTATION _TUSHARECHPL...
PPTX
Riverfront Development maharashtra nagpur
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf
Turn ideas into stunning timelines in seconds—powered by smart AI: AI Timelin...
10 Best UI UX Design Company in UK for User-Centric Solutions
URBAN DESIGN DESKTOP CASESTUDY IITG.pdf
TLE-10-PPTHAJAOSBDJDEKSNbknbtktktmktkttk
Simple Business Pitch · SlidesMania 13.pptx
Why Great Design Is the Missing Piece in Your ESG Reporting Strategy.pptx
503ea471-f798-4324-90e8-275bdab41942.pptx
SS27 Environments & Design Trend Book Peclers Paris
High-frequency high-voltage transformer outline drawing
The Advantages of Working With a Design-Build Studio
The story of the first moon landing.docx
Top 10 UI/UX Design Agencies in Dubai Shaping Digital Experiences
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
KOTA LAMA BANYUMAS.pptxxxxxxxxxxxxxxxxxxxx
actividad 20% informatica microsoft project
AUB Collaborative Book Project - Keiko Toyoda
Fundamental Principles of Visual Graphic Design.pptx
ALDO ROSSI AND MICHAEL GRAVES THEORY OF DESIGN-02 , PRESENTATION _TUSHARECHPL...
Riverfront Development maharashtra nagpur

Web Development - Lecture 5

  • 3. Contents • What is CSS? • Why use CSS? • Ways to use CSS • Big Problem • CSS Syntax • CSS Selectors and its types • Grouping Selectors • CSS Comments
  • 4. What is CSS? • CSS stands for Cascading Style Sheets • CSS defines the presentation ofWeb Pages • CSS describes how HTML elements are to be displayed on screen, paper or in other media • CSS saves a lot of work. It can control the layout of multiple web pages at once
  • 5. Why use CSS? • CSS is used to defines styles of your web pages, including the design, layout and variations in display for different devices and screen sizes.
  • 6. Ways to use CSS • CSS can be used in 3 different ways. • Inline CSS • Internal CSS • External CSS
  • 7. Continued… • Inline CSS • Inline CSS allows you to apply a unique style to one HTML element at a time. • You assign CSS to a specific HTML tag by using style attribute with any CSS properties defined within it. • Inline CSS style will always override style properties determined in internal or external files. <p style=“color: blue;”>This is a paragraph</p> This is a paragraph
  • 8. Continued… • 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.
  • 9. Continued… • 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 website by changing just one file. • It used the <link> tag on every pages and the <link> tag should be put inside the head section. <head> <link rel=“stylesheet” type=“text/css” href=“style.css”> </head> • The external style sheet may be written in text editor but must be saved with a .css extension.This file should not contain HTML elements
  • 10. •What style will be used when there is more than one style specified for an HTML element?
  • 11. Continued… • If there are multiple style sheets the priority level is defined as following: 1. Inline style sheet 2. Internal style sheet 3. External style sheet
  • 12. Big Problem • HTML was never intended to contain tags for formatting a web page • HTML was created to describe the content of the web page • 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 websites, where fonts and color information were added to every single page, became a long and expensive process • To solve this problem, theWorld Wide Web Consortium (W3C) created CSS that removed the style formatting from the HTML page
  • 13. CSS Syntax • A CSS rule-set consists of a selector and a declaration block: H1 {color:blue; font-size:12px;} Selector Declaration Declaration Property Value Property Value
  • 14. Continued... • The selector points to the HTML element you want to style • The declaration block contains one or more declarations separated by semicolons • Each declaration includes a CSS property name and a value, separated by semicolon • A CSS declaration always ends with a semicolon and declaration blocks are surrounded by curly braces
  • 15. CSS Selectors • CSS selectors are used to “find” (or select) HTML elements based on their element name, id, class, attribute and more
  • 16. Types of CSS Selectors • There are 3 types of CSS selectors • Element Selector • Id Selector • Class Selector • Child Selector • Attribute Selector
  • 17. Continued… • Element Selector • The element selector selects elements based on the element name. • Id Selector • The id selector used the id attribute of an HTML element to select a specific element. • The id of an element should be unique within a page, so the id selector is used to select one unique element. • To select an element with a specific id, write a hash character, followed by the id of the element.
  • 18. Continued… • Class Selector • The class selector selects elements with a specific class attribute. • To select elements with a specific class, write a period character, followed by the name of the class. .center {text-align: center; color: red;} • You can also specify that only specific HTML elements should be affected by a class. p. center {text-align: center; color: red;} • HTML elements can also refer to more than one class. <p class=“center large”>This paragraph refers to two classes</p>
  • 19. Continued… • Child Selector body > p {color: #000000;} • Attribute Selector • You can also apply styles to HTML elements with particular attributes • input[type=“text”] {color: #000000;}
  • 20. Grouping Selectors • If you have elements with the same style definitions, like • h1 {text-align: center; color: red;} • h2 {text-align: center; color: red;} • p {text-align: center; color: red;} • It will be better to group the selectors, to minimize the code. • To group selectors, separate each selector with a comma. • h1, h2, p {text-align: center; color: red;}
  • 21. CSS Comments • Comments are used to explain the code, and may help when you edit the source code at a later date • Comments are ignored by browsers • A CSS comment starts with /* and ends with */ • Single Line and Multiline Comments