0% found this document useful (0 votes)
4 views46 pages

Lesson 3. Cascading Style Sheets

This instructional material provides an overview of Cascading Style Sheets (CSS), including its definition, history, and various applications in web development. It explains CSS syntax, selectors, and the importance of CSS in controlling the presentation of web pages. The document also covers different types of selectors and how they can be used to apply styles to HTML elements effectively.

Uploaded by

pint0antips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views46 pages

Lesson 3. Cascading Style Sheets

This instructional material provides an overview of Cascading Style Sheets (CSS), including its definition, history, and various applications in web development. It explains CSS syntax, selectors, and the importance of CSS in controlling the presentation of web pages. The document also covers different types of selectors and how they can be used to apply styles to HTML elements effectively.

Uploaded by

pint0antips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT

Santa Rosa Branch INSTRUCTIONAL MATERIAL

Lesson 4. Cascading Style Sheets

Lesson 4.1 Introduction to Cascading Style Sheets

What is CSS?
Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to
transform the presentation of a Web Pages as well as many ostensibly nonweb environments.
CSS handles the look and feel part of a web page. Using CSS, you can control the color of the
text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what
background images or colors are used, layout designs,variations in display for different devices
and screen sizes as well as a variety of other effects.

CSS is easy to learn and understand but it provides powerful control over the presentation of an
HTML document. Most commonly, CSS is combined with the markup languages HTML or XHTML.
Strictly speaking CSS is not a programming language but it does require abstract thought. It is
also not purely a design tool, but it does require some creativity.

Where do we use CSS?


CSS is being used extensively in web and non web based applications :
• All modern websites make use of CSS to beautify their web pages.
• Embedded-device displays often use CSS to style their user interfaces.
• RSS clients also let you apply CSS to feeds and feed entries.
• Instant message clients also use CSS to format chat windows.

Aspects of CSS can be found in the syntax used by JavaScript and its frameworks, so we can
say CSS is everywhere!

History of CSS

Cascading Style Sheets level 1 (CSS1) came out of W3C as a recommendation in December
1996. This version describes the CSS language as well as a simple visual formatting model for
all the HTML tags.

CSS2 became a W3C recommendation in May 1998 and builds on top of CSS1. This version
adds support for media-specific style sheets e.g. printers and aural devices, downloadable fonts,
element positioning and tables.

CSS3 became a W3C recommendation in June 2012 and builds on older versions CSS. it has
divided into documentations called as Modules and here each module having new extension
features defined in CSS2.
Year Description

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

HÃ¥kon Wium Lie proposed the idea of CSS to allow web designers to change the
1994
layout, colors, and fonts of their websites.

The first version of CSS was released while the newly established CSS Working
1996
Group moved forward with CSS2.

The second version of CSS was released and work on CSS-3 started at the same
1998
time.

A clarified version of CSS2 called CSS2.1, was released, which fixed the errors found
2011
in CSS 2

As of June 2012, there are over fifty CSS modules published from the CSS-3 Working
2012
Group.
Style Sheets Origin
The stylesheets you add to your web page aren’t the only ones the browser applies. There are
different types, or origins, of stylesheets:
• User agent styles - This is the default style which browser applies to any web page.
• Author styles - Your stylesheets are called author styles which override user agent styles.
• User stylesheet - Some browsers let users define a user stylesheet and these are rarely
used.

Who Maintains CSS?


CSS is created and maintained through a group of people within the W3C called the CSS Working
Group. The CSS Working Group creates documents called specifications. When a specification
has been discussed and officially ratified by the W3C members, it becomes a recommendation.
These ratified specifications are called recommendations because the W3C has no control over
the actual implementation of the language. Independent companies and organizations create that
software.

The World Wide Web Consortium, or W3C is a group that makes recommendations about how
the Internet works and how it should evolve.

CSS Modules
A CSS Module is a CSS file in which all class names and animation names are scoped locally by
default. There are number of modules available CSS3, we are going to list a few of them:
• Selectors
• Box Model
• Backgrounds and Borders
• Image Values and Replaced Content
• Text Effects
• 2D/3D Transformations
• Animations
• Multiple Column Layout
• User Interface
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Lesson 4.2 CSS Syntax

A CSS comprises of style rules that are interpreted by the browser and then applied to the
corresponding elements in your document. A style rule is made of three parts −
• Selector − A selector is an HTML tag at which a style will be applied. This could be any
tag like <h1> or <table> etc.
• Property − A property is a type of attribute of HTML tag. Put simply, all the HTML attributes
are converted into CSS properties. They could be color, border etc.
• Value − Values are assigned to properties. For example, color property can have value
either red or #F1F1F1 etc.

You can put CSS Style Rule Syntax as follows –

selector { property: value }

Example − You can define a table border as follows −


table{ border :1px solid #C00; }

Here table is a selector and border is a property and given value 1px solid #C00 is the value of
that property.

You can define selectors in various simple ways based on your comfort. Let me put these selectors
one by one.

The Type Selectors


This is the same selector we have seen above. Again, one more example to give a color to all
level 1 headings –

h1 {
color: #36CFFF;
}

The Universal Selectors


Rather than selecting elements of a specific type, the universal selector quite simply matches the
name of any element type −
*{
color: #000000;
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

This rule renders the content of every element in our document in black.

The Descendant Selectors


Suppose you want to apply a style rule to a particular element only when it lies inside a particular
element. As given in the following example, style rule will apply to <em> element only when it lies
inside <ul> tag.
ul em {
color: #000000;
}

The Class Selectors


You can define style rules based on the class attribute of the elements. All the elements having
that class will be formatted according to the defined rule.
.black {
color: #000000;
}

This rule renders the content in black for every element with class attribute set to black in our
document. You can make it a bit more particular. For example −
h1.black {
color: #000000;
}

This rule renders the content in black for only <h1> elements with class attribute set to black.
You can apply more than one class selectors to given element. Consider the following example −
<p class = "center bold">
This para will be styled by the classes center and bold.
</p>

The ID Selectors
You can define style rules based on the id attribute of the elements. All the elements having
that id will be formatted according to the defined rule.
#black {
color: #000000;
}

This rule renders the content in black for every element with id attribute set to black in our
document. You can make it a bit more particular. For example −
h1#black {
color: #000000;
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

This rule renders the content in black for only <h1> elements with id attribute set to black.
The true power of id selectors is when they are used as the foundation for descendant selectors,
For example −
#black h2 {
color: #000000;
}

In this example all level 2 headings will be displayed in black color when those headings will lie
with in tags having id attribute set to black.

The Child Selectors


You have seen the descendant selectors. There is one more type of selector, which is very similar
to descendants but have different functionality. Consider the following example −
body > p {
color: #000000;
}

This rule will render all the paragraphs in black if they are direct child of <body> element. Other
paragraphs put inside other elements like <div> or <td> would not have any effect of this rule.
The Attribute Selectors
You can also apply styles to HTML elements with particular attributes. The style rule below will
match all the input elements having a type attribute with a value of text −
input[type = "text"] {
color: #000000;
}

The advantage to this method is that the <input type = "submit" /> element is unaffected, and the
color applied only to the desired text fields.
There are following rules applied to attribute selector.
• p[lang] − Selects all paragraph elements with a lang attribute.
• p[lang="fr"] − Selects all paragraph elements whose lang attribute has a value of exactly
"fr".
• p[lang~="fr"] − Selects all paragraph elements whose lang attribute contains the word
"fr".
• p[lang|="en"] − Selects all paragraph elements whose lang attribute contains values that
are exactly "en", or begin with "en-".

Multiple Style Rules


You may need to define multiple style rules for a single element. You can define these rules to
combine multiple properties and corresponding values into a single block as defined in the
following example −
h1 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

margin-bottom: 1em;
text-transform: lowercase;
}

Here all the property and value pairs are separated by a semicolon (;). You can keep them in a
single line or multiple lines. For better readability, we keep them in separate lines.
For a while, don't bother about the properties mentioned in the above block. These properties will
be explained in the coming chapters and you can find complete detail about properties in CSS
References

Grouping Selectors
You can apply a style to many selectors if you like. Just separate the selectors with a comma, as
given in the following example −
h1, h2, h3 {
color: #36C;
font-weight: normal;
letter-spacing: .4em;
margin-bottom: 1em;
text-transform: lowercase;
}

This define style rule will be applicable to h1, h2 and h3 element as well. The order of the list is
irrelevant. All the elements in the selector will have the corresponding declarations applied to
them.

You can combine the various id selectors together as shown below −


#content, #footer, #supplement {
position: absolute;
left: 510px;
width: 200px;
}

Lesson 4.3 CSS Selectors

CSS selectors are patterns used to select and style HTML elements on a web page. They allow
you to target specific elements or groups of elements to apply styles like colors, fonts, margins,
and more. CSS selectors are a fundamental part of Cascading Style Sheets (CSS), which is a
language used to control the presentation and layout of web documents.

The element or elements that are selected by the selector are referred to as subject of the
selector.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Selector lists
If same CSS is used by more than one selector, then these selectors can be combined together
to form a selector list. Thus the CSS rule is applied to all the individual selectors.
For example, if the same CSS, color: crimson is applied to p element and .sample class, it is
written as:

p{
color: crimson;
}

.sample {
color: crimson;
}

But, we can combine these two rules into one selector list, by adding a comma to separate them
as shown below:
p, .sample {
color: crimson;
}

Following syntax will be deemed invalid, as one of the selector is invalid (..sample - is an incorrect
way of defining a class).
p{
color: crimson;
}

..sample {
color: crimson;
}
p, ..sample {
color: crimson;
}
• A white space is acceptable before or after the comma in a selector list declaration.
• If any of the selectors in the selector list is invalid, the whole rule gets ignored and deemed
invalid.
• It is advisable to define each selector in a new line, as it makes it more legible.
CSS Selector - Type Selector
A type selector targets an HTML element, such as <h1>, <p>, etc.
p{
color: green;
}

h1 {
text-decoration-line: underline;
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Following example demonstrates the use of a type selector:


<html>
<head>
<style>
div {
border: 5px inset gold;
width: 300px;
text-align: center;
}

p{
color: green;
}

h1 {
text-decoration-line: underline;
}
</style>
</head>
<body>
<div>
<h1>Type selector</h1>
<p>div with border and text-aligned to center</p>
<p>paragraph with green color</p>
<p>h1 with an underline</p>
</div>
</body>
</html>

CSS Selector - Class Selector


A class selector targets an element with a specific value for its class attribute.
.style-h1 {
text-decoration-line: underline;
}

.style-p {
color: green;
font-size: 25px;
}
Following example demonstrates the use of a class selector, where .style-p, .style-h1 and .style-
div are class selectors:
<html>
<head>
<style>
.style-div {

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

border: 5px inset gold;


width: 300px;
text-align: center;
}

.style-p {
color: green;
font-size: 25px;
}

.style-h1 {
text-decoration-line: underline;
}
</style>
</head>
<body>
<div class="style-div">
<h1 class="style-h1">class selector</h1>
<p class="style-p">class .style-p applied</p>
<p>No class applied on this p element</p>
</div>
</body>
</html>
CSS Selector - ID Selector
An ID selector targets an element with a specific value for its id attribute.
#style-p {
color: green;
font-size: 25px;
}

#style-h1 {
text-decoration-line: underline;
color: red;
}
Following example demonstrates the use of an id selector, where #style-p, #style-h1 and #style-
div are the ide selectors applied on the elements:
<html>
<head>
<style>
#style-div {
border: 5px inset purple;
width: 300px;
text-align: center;
background-color: lightgoldenrodyellow;
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

#style-p {
color: green;
font-size: 25px;
}

#style-h1 {
text-decoration-line: underline;
color: red;
}
</style>
</head>
<body>
<div id="style-div">
<h1 id="style-h1">ID selector</h1>
<p id="style-p">id #style-p applied</p>
<p>No id applied on this p element</p>
</div>
</body>
</html>

CSS Selector - Attribute Selector


An attribute selector targets an element based on a specific attribute or attribute values on an
element.
a[target] {
background-color: peachpuff;
}
You can also specify the element with an attribute having a specific value.
a[href="https://www.tutorialspoint.com"] {
background-color: peachpuff;
}
Following example demonstrates the use of an attribute selector:
<html>
<head>
<style>
a[target] {
background-color: peachpuff;
color: blueviolet;
font-size: 2em;
}
</style>
</head>
<body>
<h2>Attribute selector</h2>
<p>Styling applied to anchor element with target attribute:</p>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<a href="#">Tutorialspoint</a>
<a href="#" target="_blank">google</a>
<a href="#" target="_self">wikipedia</a>
</body>
</html>

CSS Selector - Pseudo-class Selector


A pseudo-class selector is used to style a specific state of an element, such as :hover is used to
style an element when hovered.
For a detailed list of pseudo-class selectors, refer this link.
a :hover {
background-color: peachpuff;
color: green;
font-size: 2em;
}
Following example demonstrates the use of a pseudo-class selector:
<html>
<head>
<style>
a:hover {
background-color: peachpuff;
color: green;
font-size: 2em;
}
</style>
</head>
<body>
<h2>Pseudo-class selector</h2>
<p>Styling applied to anchor element with a pseudo-class:</p>
<a href="#">Tutorialspoint</a>
</body>
</html>

CSS Selector - Pseudo-element Selector


A pseudo-element selector is used to style a specific part of an element rather than the element
itself.
For a detailed list of pseudo-element selectors, refer this link.
a::before {
content: url();
}
Following example demonstrates the use of a pseudo-element selector (::before):
<html>
<head>
<style>
a::before {

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

content: url('images/smiley.png');
}

a::after {
content: " Pseudo-element ::after applied";
color: red;
background-color: chartreuse;
}
</style>
</head>
<body>
<h2>Pseudo-element selector</h2>
<p>Styling applied to anchor element with a pseudo-element:</p>
<a href="#">Tutorialspoint</a>
</body>
</html>

Combinators
Combinator shows the relationship between the selectors. Two or more simple selectors can be
combined using a combinator, to form a selector. You can read more about combinator here.
Following example demonstrates the use of a descendant selector (space) and child combinator:
<html>
<head>
<style>
/* style applied to only div */
div {
border: 2px solid black;
width: 300px;
}
/* style applied to all li elements directly under ul */
ul li {
background-color: lightpink;
color: purple;
font-size: 1.5em;
padding: 5px;
margin-right: 15px;
}

/* style applied to all li elements that are child element to ol element */


ol > li {
background-color: bisque;
color: black;
font-size: 0.75em;
padding: 5px;
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</style>
</head>
<body>
<div>
<ul>
<li>Item One</li>
<li>Item Two
<ol>
<li>Nested 1</li>
<li>Nested 2</li>
</ol></li>
<li>Item Three</li>
<li>Item Four</li>
<li>Item Five
<ol>
<li>Nested 3</li>
<li>Nested 4</li>
</ol>
</li>
</ul>
</div>
</body>
</html>

CSS Selector - Universal Selector


Universal selector, denoted by an asterisk mark (*), is a special selector that matches any and all
elements in an HTML document.
/* Selects and styles all elements on the page */
*{
margin: 0;
padding: 0;
}
As per the above syntax, the universal selector is used to apply a margin and padding of 0 to all
HTML elements.
Following example demonstrates the use of a universal selector (*):
<html>
<head>
<style>
*{
background-color: peachpuff;
color: darkgreen;
font-size: 25px;
}
</style>
</head>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<body>
<h1>Universal selector (*)</h1>

<div>Parent element
<p>Child paragraph 1</p>
<p>Child paragraph 2</p>
</div>

<p>Paragraph 3</p>
</body>
</html>

CSS Selector - & nesting selector


CSS nesting allows to nest one style rule inside another rule, with the selector of the child rule
relative to the selector of the parent rule.
The nesting selector shows the relationship between the parent and child rules.
• When the nested selectors are parsed by the browser, it automatically adds a whitespace
between the selectors, thus creating a new CSS selector rule.
• In situations where the nested rule needs to be attached to the parent rule (without any
whitespace), like while using the pseudo-class or compound selectors, the & nesting
selector must be prepended immediately to achieve the desired result.
• In order to reverse the context of rules, the & nesting selector can be appended.
• There can be multiple instances of & nesting selector.
Following example demonstrates the use of a & nesting selector (&):
<html>
<head>
<style>
#sample {
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 1.5rem;
&a{
color: crimson;
&:hover,
&:focus {
color: green;
background-color: yellow;
}
}
}
</style>
</head>
<body>
<h1>& nesting selector</h1>
<p id="sample">
Hover <a href="#">over the link</a>.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</p>
</body>
</html>

Lesson 4.4 CSS Colors

CSS uses color values to specify a color. Typically, these are used to set a color either for the
foreground of an element (i.e. its text) or else for the background of the element. They can also
be used to affect the color of borders and other decorative effects.

Syntax
CSS allows to set colors of an element in a variety of ways. Let's check all the possible available
syntax to set the height of an element.

Named Colors
A CSS named color is the name of a color, such as red, blue, black, or lightseagreen.

color: blue;
border: 1px solid red;
background: aliceblue;

RGB Hexadecimal Colors


color: #f09;
border: 1px solid #ff0099;
background: #eee;

RGB (Red, Green, Blue) Colors


color: rgb(255 0 153);
border: 1px solid rgb(255 0 153);
background: rgb(255 0 153 / 80%);

HSL (Hue, Saturation, Lightness) Colors


color: hsl(150 30% 60%);
border: 1px solid hsl(150 30% 60%);
background: hsl(150 30% 60% / 0.8);

HWB (Hue, Whiteness, Blackness) Colors


color: hwb(12 50% 0%);
border: 1px solid hwb(12 50% 0%);
background: hwb(194 0% 0% / 0.5);

LAB (Lightness, A-axis, B-axis) Colors


color: lab(50% 40 59.5);
border: 1px solid lab(50% 40 59.5);
background: lab(50% 40 59.5 / 0.5);

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

LCH (Lightness, Chroma, Hue) Colors


color: lch(52.2% 72.2 50);
border: 1px solid lch(52.2% 72.2 50);
background: lch(52.2% 72.2 50 / 0.5);

Oklab (Lightness, A-axis, B-axis) Colors


color: oklab(59% 0.1 0.1);
border: 1px solid oklab(59% 0.1 0.1);
background: oklab(59% 0.1 0.1 / 0.5);

Oklch (Lightness, Chroma, Hue) Colors


color: oklch(60% 0.15 50);
border: 1px solid oklch(60% 0.15 50);
background: oklch(60% 0.15 50 / 0.5);

These formats are explained in more detail in the following sections −


CSS Colors - Keyword
CSS supports the color names to be directly passed to the property background-color and color.
140 standard color names are supported by CSS.
Few of the examples are listed in the table below:
Color Color Name

Black

Red

Blue

Green

Aquamarine

Example
Here is an example:
<html>
<head>
<style>
div {
background-color: aqua;
padding: 10px;
}
</style>
</head>
<body>
<h3>Color Keyword - example</h3>
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<p>As the keyword passed is aqua, the background will appear as aqua colored..</p>
<div>
This div element has a colored background based on the color keyword passed, i.e aqua.
</div>
</body>
</html>

CSS Colors - Hexadecimal Codes


A hexadecimal is a 6 digit representation of a color. The first two digits(RR) represent a red value,
the next two are a green value(GG), and the last are the blue value(BB).
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc
Paintshop Pro, or even using Advanced Paint Brush.
Each hexadecimal code will be preceded by a pound or hash sign '#'. Following are the examples
of hexadecimal notation.
To specify the hexadecimal codes, you can use upper case or lower case letters.
Color Color Hexadecimal Code

#000000

#FF0000

#00FF00

#0000FF

#FFFF00

#00FFFF

#FF00FF

#C0C0C0

#FFFFFF
Example
Here is an example:
<html>
<head>
<style>
div{
background-color: #00ff00;
padding: 10px;
}
</style>
</head>
<body>
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<h3>Hexadecimal code - example</h3>


<p>As the hexadecimal code is #00ff00 the background will appear green.</p>
<div>
This div element has a green background.
</div>
</body>
</html>

CSS Colors - Short Hexadecimal Codes


This is a shorter form of the six-digit notation. In this format, each digit is replicated to arrive at an
equivalent six-digit value. For example: #6A7 becomes #66AA77.
A hexadecimal value can be taken from any graphics software like Adobe Photoshop, Jasc
Paintshop Pro, or even using Advanced Paint Brush.
Each short hexadecimal code will be preceded by a pound or hash sign '#'. Following are the
examples of short hexadecimal notation.
Color Short Hexadecimal Code

#000

#F00

#0F0

#0FF

#FF0

#0FF

#F0F

#FFF
Example
Here is an example:
<html>
<head>
<style>
div{
background-color: #00f;
padding: 10px;
color:#fff;
}
</style>
</head>
<body>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<h3>Short Hexadecimal code - example</h3>


<p>As the short hexadecimal code is #00f the background will appear blue.</p>
<div>
This div element has a blue background.
</div>
</body>
</html>

CSS Colors - RGB Values


• This color value is specified using the rgb( ) property.
• It takes three values, one each for red, green, and blue.
• The value can be an integer between 0 and 255 or a percentage.
All the browsers does not support rgb() property of color so it is recommended not to use it.
Following is the example to show few colors using RGB values.
Color Color RGB

rgb(0,0,0)

rgb(255,0,0)

rgb(0,255,0)

rgb(0,0,255)

rgb(255,255,0)

rgb(0,255,255)

rgb(255,0,255)

rgb(192,192,192)

rgb(255,255,255)
Example
Here is an example:
<html>
<head>
<style>
div{
background-color: rgb(255,0,255);
padding: 10px;
}
</style>
</head>
<body>
<h3>RGB - example</h3>
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<p>As the rgb(255,0,255) is set the background will appear accordingly.</p>


<div>
This div element has a colored background based on the rgb values.
</div>
</body>
</html>

CSS Colors – RGBA Values


• This color value is specified using the rgba( ) property.
• It takes four values, one each for red, green, and blue and the last value as the alpha
(transparency) value.
• The alpha value can be any value between 0 and 1.
All the browsers does not support rgba() property of color so it is recommended not to use it.
Following is the example to show few colors using RGBA values.

Example
Here is an example:
<html>
<head>
<style>
div {
background-color: rgba(255,0,255,0.2);
padding: 10px;
}
</style>
</head>
<body>
<h3>RGBA - example</h3>
<p>As the rgba(255,0,255,0.2) is set the background will appear with transparency value of
0.2.</p>
<div>
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

This div element has a colored background based on the rgba values.
</div>
</body>
</html>

CSS Colors - HSL Values


• This color value is specified using the hsl() function.
• HSL stands for hue, saturation and lightness.
• Hue is represented in degrees (0-360), saturation and lightness are represented as
percentages (0% - 100%).
Following is the example to show few colors using HSL property.
Color Color HSL

hsl(0,0%,50%)

hsl(255,80%,70%)

hsl(290,100%,60%)

hsl(360,70%,20%)

hsl(89,80%,67%)

Example
Here is an example:
<html>
<head>
<style>
div{
background-color: hsl(355,70%,50%);
padding: 10px;
}
</style>
</head>
<body>
<h3>HSL - example</h3>
<p>As the hsl(355,70%,50%) is set the background will appear based on the hsl values
passed.</p>
<div>
This div element has a colored background based on the hsl values hsl(355,70%,50%).
</div>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

CSS Colors – HSLA Values


• This color value is specified using the hsl() function.
• HSLA stands for hue, saturation, lightness and alpha.
• It takes four values, first for hue, second for saturation, third for lightness and fourth is the
alpha (transparency) value.
• Hue is represented in degrees (0-360), saturation and lightness are represented as
percentages (0% - 100%), and alpha value can be in between 0 and 1.
Following is the example to show few colors using HSLA property.

Example
Here is an example:
<html>
<head>
<style>
div{
background-color: hsla(355,70%,50%,0.4);
padding: 10px;
}
</style>
</head>
<body>
<h3>HSLA - example</h3>
<p>As the hsla(355,70%,50%,0.4) is set the background will appear based on the hsla values
passed, with high transparency.</p>
<div>
This div element has a colored background based on the hsl values hsla(355,70%,50%,0.4).
</div>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

CSS colors - currentcolor keyword


The currentcolor keyword takes the value of the color property of an element. It can be passed
to any other styling property using the keyword currentcolor.
Example
Here is an example:
<html>
<head>
<style>
div{
color: red;
border: 5px solid currentcolor;
}
</style>
</head>
<body>
<h2>The currentcolor Keyword</h2>
<p>As the currentcolor keyword is used for border after color property is set as red, the border
will also appear red.</p>
<div>
This div element has a red text color and a red border.
</div>
</body>
</html>

Lesson 4.5 CSS Backgrounds

This chapter teaches you how to set backgrounds of various HTML elements. You can set the
following background properties of an element −

• The background-color property is used to set the background color of an element.


• The background-image property is used to set the background image of an element.
• The background-repeat property is used to control the repetition of an image in the
background.
• The background-position property is used to control the position of an image in the
background.
• The background-attachment property is used to control the scrolling of an image in the
background.
• The background property is used as a shorthand to specify a number of other
background properties.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Set the Background Color


Following is the example which demonstrates how to set the background color for an element.
<html>
<head>
</head>

<body>
<p style = "background-color:yellow;">
This text has a yellow background color.
</p>
</body>
</html>

Set the Background Image


We can set the background image by calling local stored images as shown below −

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-color: #cccccc;
}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>
<html>

Repeat the Background Image


The following example demonstrates how to repeat the background image if an image is small.
You can use no-repeat value for background-repeat property if you don't want to repeat an image,
in this case image will display only once.
By default background-repeat property will have repeat value.

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-repeat: repeat;
}
</style>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</head>

<body>
<p>Tutorials point</p>
</body>
</html>

The following example which demonstrates how to repeat the background image vertically.

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-repeat: repeat-y;
}
</style>
</head>

<body>
<p>Tutorials point</p>
</body>
</html>

The following example demonstrates how to repeat the background image horizontally.

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-repeat: repeat-x;
}
</style>
</head>

<body>
<p>Tutorials point</p>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Set the Background Image Position


The following example demonstrates how to set the background image position 100 pixels away
from the left side.

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-position:100px;
}
</style>
</head>

<body>
<p>Tutorials point</p>
</body>
</html>

The following example demonstrates how to set the background image position 100 pixels away
from the left side and 200 pixels down from the top.

<html>
<head>
<style>
body {
background-image: url("/css/images/css.jpg");
background-position:100px 200px;
}
</style>
</head>

<body>
<p>Tutorials point</p>
</body>
</html>

Set the Background Attachment


Background attachment determines whether a background image is fixed or scrolls with the rest
of the page.
The following example demonstrates how to set the fixed background image.

<!DOCTYPE html>
<html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>

<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>

The following example demonstrates how to set the scrolling background image.

<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('/css/images/css.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-attachment:scroll;
}
</style>
</head>

<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

<p>The background-image is fixed. Try to scroll down the page.</p>


<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>

Shorthand Property
You can use the background property to set all the background properties at once. For example

<p style = "background:url(/https/www.scribd.com/images/pattern1.gif) repeat fixed;">
This parapgraph has fixed repeated background image.
</p>

Lesson 4.6 CSS Fonts

A font is a set of text characters with a consistent design and style. It includes the shape, size,
weight, and other attributes of the characters in a typeface.
• Fonts are used to display and represent text in various mediums, such as print, digital
screens, and graphic design.
• Fonts can be chosen to convey a specific mood or aesthetic, enhance readability, or align
with a brand's identity.
• Fonts play a crucial role in communication and design.
• Fonts can evoke different emotions and convey specific messages to the audience.
This chapter demonstrates how to set fonts of a content, available in an HTML element. You can
set following font properties of an element −
• font: It is a shorthand for all the other font-related properties that can be passed in one
single declaration.
• font-family: Specifies the font family or list of font families to be used for text.
• font-feature-settings: Controls advanced typographic features in OpenType fonts, such
as swashes, small caps and ligatures.
• font-kerning: Determines the way specific pairs of letters are spaced.
• font-language-override: Overrides the typeface behaviour for a particular language.
• font-optical-sizing: Sets whether rendering of text should be optimized to view at different
sizes.
• font-palette: Allows you to specify one of the various palettes that are contained in a font.
• font-size: Sets the size of the text. It can be specified in pixels (px), points (pt),
percentages (%), ems (em), or other units.
• font-size-adjust: Sets the size of the lowercase letters in accordance with the current font
size.
• font-stretch: Sets the expanded, condensed or a normal font face.
• font-style: Specifies the style of the text, such as "italic", "oblique", or "normal".
• font-weight: Determines the thickness or boldness of the text. Common values are
"normal" and "bold", though numeric values (e.g., 100, 200, 300) and keywords (e.g.,
"lighter", "bolder") can also be used.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

• font-synthesis: Determines whether or not the browser should synthesize the bold, italic,
and / or small-caps typefaces that are missing in a font-family.
• font-synthesis-small-caps: Determines whether or not the browser should synthesize
the small-caps typeface, that is missing in a font-family.
• font-synthesis-style: Determines whether or not the browser should synthesize the
oblique typeface, that is missing in a font-family.
• font-synthesis-weight: Determines whether or not the browser should synthesize the
bold typeface, that is missing in a font-family.
• font-variant: Controls the use of small caps for lowercase letters in the text. Values can
be "normal" or "small-caps".
• font-variant-alternates: Controls the usage of alternate glyphs.
• font-variant-caps: Controls the usage of alternate glyphs for capital letters.
• font-variant-east-asian: Controls the usage of alternate glyphs for East-Asian scripts like
Chinese and Japanese.
• font-variant-ligatures: Controls the textual content of element as to which ligature or
contextual form should be used.
• font-variant-numeric: Controls the usage of alternate glyphs for numbers, fractions and
ordinal markers.
• font-variant-position: Controls the usage of alternate, smaller glyphs, positioned as
superscript or subscript.
• font-variation-settings: Specifies the four-letter axis names of variable font
characteristics.
• line-height: Sets the height of the line box. Also sets the distance between the lines of
text.
CSS Font Shorthand
In order to shorten the code, CSS allows a shorthand property for font where all the following
properties can be specified in one single declaration:
The font property is a shorthand for:
• font-style
• font-variant
• font-weight
• font-stretch
• font-size
• line-height
• font-family
Points to remember:
• The properties font-style, font-variant and font-weight must always precede font-size.
• The values normal and small-caps may only be specified with the property font-variant.
• The property font-stretch may only be a single keyword value.
• The property line-height must follow the property font-size, preceded by "/". For
example: "20px/3".
• The property font-family must be the last value specified.
The values for font-family and font-size are required, and in case any of the values is missing,
the default values are used.
System Font Values

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

There is a list of system font values, which is as follows:


• caption: Used for captioned controls, such as, buttons, dropdowns, etc.
• icon: Used for label icons
• menu: Used in menus, such as, dropdown menus or list menus.
• message-box: Used in dialog boxes.
• small-caption: Used for labeling small controls.
• status-bar: Used in window status bars.
• Prefixed system font keywords: Implemented by browsers, such as, -moz-window, -
moz-document, -moz-desktop, -moz-info, -moz-dialog, -moz-button, -moz-pull-down-
menu, -moz-list, and -moz-field.
Example
Here is an example:
<html>
<head>
<style>
p{
border: 2px solid blue;
}
</style>
</head>
<body>
<h2>Font Shorthand Property</h2>
<p style = "font: oblique normal bold 20px Arial, sans-serif;">
Shorthand Property Font
</p>
</body>
</html>
CSS Font Family
The selection of an appropriate font-family is very important, as it affects and reflects different
styles, emotions and readability. Each classification has its own connotations and usages.
For example, while serif fonts have small embellishments or strokes at the end of
characters, sans-serif fonts have a cleaner and more modern appearance.
Choosing the right font is an important aspect of graphic design and branding. It can help establish
a visual identity and reinforce the message being conveyed.
Possible values for this property are as follows:
• <family-name>: Name of font-family. Name with whitespaces should be quoted.
• <generic-name>: This is the fallback mechanism. Should be the last value in the list of
font-family names.
o serif: Glyphs with finishing strokes, flared, or tapered-ends. Example: Lucida
Bright, Palatino, etc.
o sans-serif: Glyphs with plain stroke endings. Example: Open Sans, Lucida Sans,
etc.
o monospace: Same width glyphs. Example: Consolas, Monaco, monospace, etc.
o cursive: Glyphs in cursive fonts with partially or fully joined strokes. Example:
Brush Script MT, Lucida Calligraphy, etc.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

o fantasy: Decorative fonts containing playful representation of characters.


Example: Curlz MT, fantasy, etc.
o system-ui: Glyphs taken from default user interface font on any given platform.
o ui-serif: Default user interface (UI) serif font
o ui-sans-serif: Default UI sans-serif font
o ui-monospace: Default UI monospace font.
o ui-rounded: Default UI font with rounded features.
o math: Font representing mathematical operations such as superscript, subscript,
brackets, nesting expressions, etc.
o emoji: Emoji rendering fonts.
o fangsong: Style of Chinese characters that are between serif-style Song and
cursive-style Kai.
Here is an example:
<html>
<head>
<style>
p{
padding: 5px;
border: 2px solid blue;
}
</style>
</head>
<body>
<h2>Font-family</h2>
<p style = "font-family: 'Times New Roman', Times, serif;">
The text will be either 'Times New Roman', Times, or serif.
</p>
<p style = "font-family: Arial, Helvetica, sans-serif;">
The text will be either 'Arial', Helvetica, or sans-serif.
</p>
</body>
</html>
CSS Font Feature Settings
The font-feature-settings property is provided by CSS to control advanced typographic features
in OpenType fonts, such as swashes, small caps and ligatures.
Note: The font-feature-settings property should not be used to enable the small caps. It should
be used only in special cases of OpenType fonts.
Possible values for this property are as follows:
• normal: Default value. Default font settings are laid out.
• <feature-tag-value>: Specified as a tuple, separated by space, having a tag name and
an optional value.
o Tag name is always a <string> of four ASCII characters, else it is invalid.
o Optional value can be an integer or keyword on(1) or off(0). Default is 0.
Syntax
/* use small-cap */

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

font-feature-settings: "smcp" on;

/* convert both upper and lowercase to small caps */


font-feature-settings: "c2sc", "smcp";

/* use zeros with a slash through them to differentiate from "O" */


font-feature-settings: "zero";

/* enable historical forms */


font-feature-settings: "hist";

/* enable common ligatures */


font-feature-settings: "liga" 1;

/* enable tabular (monospaced) figures */


font-feature-settings: "tnum";

/* enable automatic fractions */


font-feature-settings: "frac", on;

/* use the second available swash character */


font-feature-settings: "swsh" 2;
Example
Here is an example:
<html>
<head>
<style>
div{
border: 1px solid red;
margin: 5px;
width: 300px;
}
p.allcaps{
padding: 8px; font-weight: bold; font-style: italic; font-feature-settings: 'c2sc', 'smcp';
}
p.small-caps{
padding: 8px; font-weight: bold; font-variant:small-caps; font-feature-settings: 'smcp', off;
}
</style>
</head>
<body>
<h2>Font feature settings</h2>
<div>
<p class="allcaps">
Font feature settings-all caps

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</p>
<p class="small-caps">
Font feature settings-small caps
</p>
</div>
</body>
</html>
CSS Font Kerning
The font-kerning property provided by CSS is useful in determining the way specific pairs of
letters are spaced.
Every character has a set space on its left and right edges and when two characters are placed
side-by-side, their side bearings get added up from its actual space.
In order to adjuts these side bearings of characters, the font-kerning property is used for. You
can enable or disable this property.
Possible values for this property are as follows:
• auto: Browser decides whether font kerning should be applied or not.
• normal: Information of font kerning stored in the font must be used.
• none: Information of font kerning stored in the font is disabled.
Example
Here is an example:
<html>
<head>
<style>
div {
font-size: 2rem;
font-family: serif;
}
#nokern {
font-kerning: none;
}
#kern {
font-kerning: normal;
}
#auto {
font-kerning: auto;
}
</style>
</head>
<body>
<h2>Font kerning</h2>
<div id="kern">AV</div>
<div id="nokern">AV</div>
<div id="auto">AV</div>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

CSS Font Language Override


The font-language-override property of CSS is used to override the typeface behaviour for a
particular language.
Possible values for this property are as follows:
• normal: Specifies the browser to use the glyphs for the language specified by
the lang attribute. It is the default value.
• <string>: Specifies the browser to use the glyphs for the language specified by the
<string>. For example: "KOR" for Korean, "ENG" for English, "DAN" for Danish, etc.
Example
Here is an example:
<html>
<head>
<style>
.my-text {
font-family: Arial, sans-serif;
font-language-override: "TRK";
}
</style>
</head>
<body>
<p>This is some text with language-specific glyphs: ğüşöçİ</p>
<p class="my-text">This is some text with language-specific glyphs: ğüşöçİ</p>
</body>
</html>
CSS Font Optical Sizing
The font-optical-sizing property of CSS is used to set whether rendering of text should be
optimized to view at different sizes.
Possible values for this property are as follows:
• none: Shape of glyphs not modified for optimal viewing by the browser.
• auto: Shape of glyphs modified for optimal viewing by the browser.
By default optical sizing is enabled for fonts. Small text sizes are displayed with thicker and bigger
fonts, whereas larger text is displayed in a more delicate manner, when optical sizing is used.
Example
Here is an example:
<html>
<head>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap">
<style>
p{
margin-bottom: 5px;
border: 2px solid red;
}
.eng {
font-family: "Montserrat", sans-serif;

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

}
.opt-no {
font-optical-sizing: none;
}
.opt-yes {
font-optical-sizing: auto;
}
</style>
</head>
<body>
<h3>Optical sizing -none</h3>
<p class="eng opt-no">Check the optical sizing</p>

<h3>Optical sizing -auto</h3>


<p class="eng opt-yes">Check the optical sizing</p>
</body>
</html>
CSS Font Palette
The font-palette property provided by CSS allows you to specify one of the various palettes that
are contained in a font.
Possible values for this property are as follows:
• normal: Sets default color palette or the glyph colorization. The palette at index 0 is
rendered.
• light: Sets the first palette that matches with 'light'. If no match is found, it behaves
like normal.
• dark: Sets the first palette that matches with 'dark'. If no match is found, it behaves
like normal.
• <palette identifier>: Allows a to specify your own palette using the @font-palette-
values at-rule.
Example
Here is an example:
<html>
<head>
<style>
@import url(https://fonts.googleapis.com/css2?family=Bungee+Spice);
@font-palette-values --bungee-more-spicy {
font-family: "Bungee Spice";
override-colors:
0 Orange,
1 Yellow;
}
h2 {
font-family: "Bungee Spice";
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

h2.more-spicy {
font-palette: --bungee-more-spicy;
}
</style>
</head>
<body>
<h2>Font face</h2>
<h2 class="more-spicy">Hot & burning</h2>
</body>
</html>
CSS Font Size
Font size refers to the height of the characters in relation to the text's baseline. Larger fonts are
typically used for headlines or titles to grab attention, while smaller fonts are suitable for body text
or captions to ensure readability.
The possible values for font-size in CSS are:
• Absolute size keywords: These values are based on the default size of uesr's font-size
(medium). It includes:
o xx-small
o x-small
o small
o medium
o large
o large
o x-large
o xx-large
o xxx-large
• Relative size keywords: These values are relatively larger or smaller to the font-size of
the parent element. It includes:
o larger
o smaller
• <length>: These are predefined positive <length> value. It includes em, ex, rem, px, in,
etc.
• <percentage>: A positive <percentage> value, relative to the font-size of the parent
element.
• math: It is the computed value of font-size for math elements relative to the font-size of
the parent element.
Example
Here is an example:
<html>
<head>
<style>
p{
padding: 5px;
border: 2px solid blue;
}

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</style>
</head>
<body>
<h2>Font-size</h2>
<p style = "font-size: large;">
The font-size is large.
</p>
<p style = "font-size: 15px">
The font-size is 15px.
</p>
<p style = "font-size: x-small;">
The font-size is x-small.
</p>
<p style = "font-size: 60%;">
The font-size is 60%.
</p>
<p style = "font-size: 2vw;">
The font-size 2vw (viewport width). Change the viewport size to see the effect.
</p>
</body>
</html>
CSS Font Size Adjust
The font-size-adjust property can be used to specify a font's aspect value (numeric ratio) that
controls the x-height (height of lowercase letters) of the font.
This ensures that the fallback font maintains a consistent visual size and proportion relative to the
specified font.
The font-size-adjust property can take one of the following values:
• <number>: Specifies a numerical value that represents the aspect value, which is the
ratio of the x-height of the font to the x-height of the font specified by the font-
family property.
• none: Specifies that no font size adjustment is made based on the x-height.
• <keyword>: Specifies the font metric to normalize on:
o ex-height: x-height divided by font-size.
o cap-height: Using cap-height by font-size.
o ch-width: Horizontal narrow pitch of the fonts is normalized.
o ic-width: Horizontal wide pitch of the fonts is normalized.
o ic-height: Vertical wide pitch of the fonts is normalized.
The browser support for font-size-adjust may vary, and it is not widely used in modern web
development. The 'Firefox' and Safari browser supports this property.
Here is an example (check the result on Firffox or Safari browser):
<html>
<head>
<style>
p{
padding: 5px;

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

border: 2px solid blue;


}
p.p1 {
font-family: 'Courier New', Courier, monospace;
font-size-adjust:none;
}
p.p2 {
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 20pt;
font-size-adjust: 0.6;
}
p.p3 {
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 20pt;
font-size-adjust: ex-height 0.6;
}
</style>
</head>
<body>
<h2>Font-size</h2>
<p class="p1">
The font-size-adjust is none.
</p>
<p class="p2">
The font-size-adjust is 0.6 on font-size 20pt.
</p>
<p class="p3">
The font-size-adjust is ex-height and 0.6 on font-size 20pt.
</p>
</body>
</html>
CSS Font Stretch
Certain font-families provide additional faces in which the characters can be either narrower or
broader than their normal appearance. The font-stretch property allows adjusting the width of
the text (condensed or expanded).
Note: If the font face you are using does not support condensed or expanded forms, the font-
stretch property will have no effect.
Possible values for this property are as follows:
• normal: Specifies a normal font face.
• semi-condensed, condensed, extra-condensed, ultra-condensed: Specifies a
condensed font face than normal.
• semi-expanded, expanded, extra-expanded, ultra-expanded: Specifies an expanded
font face than normal.
• <percentage>: A percentage value, which can be 50% to 200%.
• initial: Sets the value to initial value.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

• inherit: Inherits the value from the parent value.


The mapping of keyword and respective percentage value:
Keyword Percentage

ultra-condensed 50%

extra-condensed 62.5%

condensed 75%

semi-condensed 87.5%

normal 100%

semi-expanded 112.5%

expanded 125%

extra-expanded 150%

ultra-expanded 200%
Example
Here is an example:
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h2>Font-stretch</h2>
<p style = "font-stretch: normal;">
Normal
</p>
<p style = "font-stretch: condensed;">
Condensed
</p>
<p style = "font-stretch: expanded;">
Expanded
</p>
<p style = "font-stretch: 170%;">
170% stretched
</p>
</body>
IM Developed by: Date Created: Revision No.
COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</html>
CSS Font Style
Font styles are used to change the appearance or style of text. The font-style property is used
to specify the font style for the selected text.
There are three main font styles available in CSS:
• normal: Default font style where the text is displayed normally, without any slant or
obliqueness.
• italic: Text appears in an italicized style, with a slight slant to the right.
• oblique: Text appears similar to italic but with a more exaggerated slant or angularity.
• oblique <angle>: An oblique text with an angle to specify the slantness of the text.
o If no oblique font face available, the browser will slant the text by specified angle.
o Valid values for angle are degree values between -90deg to 90deg inclusive.
o If no angle specified, 14deg is set by the browser.
o Positive angle value slants the text to the end of line.
o Negative angle values slant the text towards the beginning.
o Larger angle values are preferred.
These font styles can be applied to any HTML elements using CSS selectors and can be
combined with other font properties like font-family, font-size, etc., to create desired text styles.
Note: The browser compatible for the font-style:oblique <angle> is firefox.
Example
Here is an example:
<html>
<head>
<style>
p{
padding: 5px;
border: 2px solid blue;
}
</style>
</head>
<body>
<h2>Font-style</h2>
<p style = "font-style: normal;">
The text will be normal.
</p>
<p style = "font-style: italic;">
The text will be italic.
</p>
<p style = "font-style: oblique;">
The text will be obligue.
</p>
<p style = "font-style: oblique 45deg;">
The text will be obligue and slanted 45deg.
</p>
</body>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</html>
CSS Font Weight
Font weight refers to the thickness or boldness of the characters. Different weights within a font
family can be used to create visual hierarchy or emphasis within a text.
The possible values for font-weight are as follows:
• normal: Font weight normal. Equivalent to 400.
• bold: Font weight bold. Equivalent to 700.
• <number>: Value between 1 and 1000 define thickness of font. Higher numbers represent
weights that are bolder than (or as bold as) lower numbers.
• lighter: Lighter font weight relative to the parent element's font weight.
• bolder: Bolder font weight relative to the parent element's font weight.
Here is an example:
<html>
<head>
<style>
p{
padding: 5px;
border: 2px solid blue;
}
</style>
</head>
<body>
<h2>Font-weight</h2>
<p style = "font-weight: normal;">
The font-weight is normal.
</p>
<p style = "font-weight: bold;">
The font-weight is bold.
</p>
<p style = "font-weight: 500;">
The font-weight is 500 (medium).
</p>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Lesson 4.7 CSS Texts

A text refers to a piece of written or printed information in the form of words or characters that can
be read and understood. Texts can include content such as books, articles, emails, messages,
web pages, etc. Styling a text involves modifying its appearance to make it more visually
appealing or to convey a particular message.
Text Formatting using CSS
CSS provides a number of properties to format text in beautiful way. This tutorial demonstrates
how to format text using CSS properties. Following properties provided by CSS can be used to
format the text:
• color: Sets the color of the text.
• text-align Sets the alignment of the text.
• text-align-last: Sets the alignment of the last line of a block of text.
• direction: Sets the direction of the text of an element.
• text-indent: Sets the indentation of the first line of the text.
• letter-spacing: Specifies the space between the letters or characters that make up a word
or text.
• word-spacing: Specifies the space between the words in a text.
• white-space: Controls the white space flow inside the text in an element.
• text-decoration: Adds an underline, overline, and strikethrough over a piece of text.
• text-decoration-skip: Determines what part of the content of the element, where text
decoration is affecting, needs to be skipped.
• text-decoration-skip-ink: Specifies how the overline and underline text decoration lines
are drawn around glyph ascenders and descenders.
• text-transform: Converts text to uppercase or lowercase letters.
• text-emphasis: Applies emphasis marks to text (except spaces and control characters).
• text-shadow: Adds shadow to the text.
• line-break: Controls how to set the rule for a line break.
• word-break: Controls how to set the rule for a word break.
CSS - Setting Text Color
Altering the color of the text can add visual interest or align with a specific design scheme.
The CSS color property is used to set the color of the text. The possible values for this property
are as follows:
• Color Name: Example = red, blue, green.
• Hexadecimal value: Example = #ff00ff.
• RGB value: Example = rgb(125, 255, 0).
Example
Here is an example:
<html>
<head>
</head>
<body>
<h2>Text Color</h2>
<p style = "color: blueviolet;">
Color Name

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

</p>
<p style = "color:#ff00ff;">
Hexadecimal value
</p>
<p style = "color: rgb(255,124,100);">
RGB value
</p>
</body>
</html>
CSS - Setting Text Alignment
The position or placement of text on a page is called its alignment. The text is aligned based on
the left and right margins of the page.
The CSS property text-align defines the alignment of the text on a web page. The text-
align property is used to set the horizontal alignment of the text.
Following are the possible values which can be used to set text-align property.
• start: Same as left, if direction is LTR and right if direction is RTL.
• end: Same as right, if direction is LTR and left if direction is RTL.
• left: Aligned with the left-margin.
• right: Aligned with the right-margin.
• center: Aligned at the center of the page.
• justify: Aligned with both the margins.
• justify-all: Same as justify, making the last line justified as well.
• match-parent: Similar to inherit. Values of start and right taken from parent's value and
replaced by left and right.
When the value of direction is ltr, the default alignment is left-aligned and when the value
of direction is rtl, the default alignment is right-aligned.
Example
Here is an example:
<html>
<head>
</head>
<body>
<h2>Setting Text Alignment using CSS</h2>
<p style="text-align: left;">Text Left Alignment.</p>
<p style="text-align: right;">Text Right Alignment.</p>
<p style="text-align: center;">Text Center Alignment.</p>
<p style="text-align: justify; border: 2px solid red; width: 200px; height: 100px;">
Text Justify Alignment. This alignment aligns the text based on both the margins, left and
right.
</p>
</body>
</html>
CSS - Setting Vertical Alignment
The CSS vertical-align property sets Vertical Alignment of an inline, inline-block or table-cell
box.

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

The vertical-align property can have one of the following values:


• baseline: Baseline of the element is aligned with the baseline of its parent element.
• sub: Baseline of the element is lowered to the point appropriate for subscripted text.
• super: Baseline of the element is raised to the point appropriate for superscripted text.
• top: Top of the element's box is aligned with the top of the line box, in the context of inline
content, or with the top of the table cell in the context of tables.
• text-top: Top of the element's box is aligned with the top of the highest inline box in the
line.
• middle: Baseline of the element is aligned with the point defined by the baseline of the
parent element plus half the x-height of the parent element's font, in the context of inline
content.
• bottom: Bottom of the element's box is aligned with the bottom of the line box, in the
context of inline content, or with the bottom of the table cell in the context of tables.
• text-bottom: Bottom of the element's box is aligned with the bottom of the lowest inline
box in the line.
• percentage: Baseline of the element is raised or lowered by the given percentage of the
value for the property line-height.
• length: Baseline of the element is raised or lowered by the given length value. Negative
length values are permitted for this property. A length value of 0 for this property has the
same effect as the value baseline.
Example
Here is an example. You can try this example using different values for vertical-align:
<html>
<head>
<style>
table, td {
height:100px;
width:400px;
border:1px solid red;
}
</style>
</head>
<body>
<h4>Setting Text Vertical Alignment</h4>
<table>
<tr>
<td style="vertical-align: baseline">baseline</td>
<td style="vertical-align: top">top</td>
<td style="vertical-align: middle">middle</td>
<td style="vertical-align: bottom">bottom</td>
<td><p>No vertical alignment </p></td>
</tr>
</table>
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

Lesson 4.8 CSS Images

Images play an important role in any webpage. Though it is not recommended to include a lot of
images, but it is still important to use good images wherever required.
CSS plays a good role to control image display. You can set the following image properties using
CSS.
• The border property is used to set the width of an image border.
• The height property is used to set the height of an image.
• The width property is used to set the width of an image.
• The -moz-opacity property is used to set the opacity of an image.

The Image Border Property


The border property of an image is used to set the width of an image border. This property can
have a value in length or in %.
A width of zero pixels means no border.
Here is the example −

<html>
<head>
</head>

<body>
<img style = "border:0px;" src = "/css/images/logo.png" />
<br />
<img style = "border:3px dashed red;" src = "/css/images/logo.png" />
</body>
</html>

The Image Height Property


The height property of an image is used to set the height of an image. This property can have a
value in length or in %. While giving value in %, it applies it in respect of the box in which an image
is available.
Here is an example −

<html>
<head>
</head>

<body>
<img style = "border:1px solid red; height:100px;" src = "/css/images/logo.png" />
<br />
<img style = "border:1px solid red; height:50%;" src = "/css/images/logo.png" />
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor
Polytechnic University of the Philippines COMP 20163 WEB DEVELOPMENT
Santa Rosa Branch INSTRUCTIONAL MATERIAL

The Image Width Property


The width property of an image is used to set the width of an image. This property can have a
value in length or in %. While giving value in %, it applies it in respect of the box in which an image
is available.
Here is an example −

<html>
<head>
</head>

<body>
<img style = "border:1px solid red; width:150px;" src = "/css/images/logo.png" />
<br />
<img style = "border:1px solid red; width:100%;" src = "/css/images/logo.png" />
</body>
</html>

The -moz-opacity Property


The -moz-opacity property of an image is used to set the opacity of an image. This property is
used to create a transparent image in Mozilla. IE uses filter:alpha(opacity=x) to create
transparent images.
In Mozilla (-moz-opacity:x) x can be a value from 0.0 - 1.0. A lower value makes the element more
transparent (The same things goes for the CSS3-valid syntax opacity:x).
In IE (filter:alpha(opacity=x)) x can be a value from 0 - 100. A lower value makes the element
more transparent.
Here is an example −

<html>
<head>
</head>

<body>
<img style = "border:1px solid red; -moz-opacity:0.4; filter:alpha(opacity=40);" src =
"/css/images/logo.png" />
</body>
</html>

IM Developed by: Date Created: Revision No.


COMP 20163 WEB DEVELOPMENT Page No.
Mr. Owen Harvey Balocon INSTRUCTIONAL MATERIAL October 24, 2023 2023 - 000 ___ of ___
Instructor

You might also like