HTML&CSSContent
HTML&CSSContent
What is Web?
• A Website is a collection of web pages that can be accessed and interacted with by
Internet users
• The collections of files that make up a website are stored on a host machine, or server
• In order to access a site your computer needs to connect to the host machine using the
Internet
• In order to view a website, a special program call Browser, is required. Examples of
browsing software are Internet Explorer, Firefox, Google Chrome, and Safari.
W3C and W3C Members
Exercises
1) Gather more details of WWW on Wikipedia.
2) What is a website?
3) What is a browser?
4) What do you call a set of interconnected computers?
Keyword
document, web page, browser, html, Consortium, standardization, website
2) b
3) c
4) a
5) a
Chapter 2: Introduction
About HTML 5
History of HTML
• 1991–1999: HTML is created by web legend Tim Berners-Lee in 1991, and HTML
versions 1–4 are developed throughout the 1990s by W3C. In these early days of
widespread internet use, HTML efficiently displays the vast majority of web content,
since at this time it largely consists of static, non-interactive sites.
• 2000: W3C recommends XHTML 1.0 – an XML-based markup language that
mirrors/extends HTML. Previous versions of HTML are now showing their age,
struggling to handle the latest generation of multimedia, interactive sites.
• 2004: Development of HTML is closed by W3C, who instead decide to focus on
XHTML. WHATWG is formed to develop HTML further, with the aim of reflecting the
modern dynamic web, while keeping backwards compatibility with existing HTML code.
• 2004–2006: WHATWG gains support from major web browser developers. In 2006,
W3C also announces its support for the project.
• 2008: The first public draft of HTML5 is released by WHATWG.
• 2012: W3C and WHATWG decide to separate development of HTML5. W3C would
work on a definitive standard of HTML5, while WHATWG would pursue development
of a ‘living standard’ – a continual evolution with ongoing improvements.
• 2014: The official HTML5 release date, according to W3C recommendations.
• Addition of Audio and Video Tags. Which allows developers to embed a video or audio
on their website
• Header and Footer tags
• HTML5 allows to use a <figure> element to mark up a photo in a document, and a <fig
caption> element to define a caption for the photo.
• <nav> tags which will provides lots of navigation links
• Progress tags which are used to check the progress of a tasks
Backward Compatibility
Backwards compatibility is nothing but when the obvious one of a version of a
specification with previous versions of the same, and another one of new technologies
with earlier ones can be used
Nobody forgets about the former, because there is nothing the developers of a new
version know so well as the previous version they are trying to replace.
But the latter is less obvious. It is, in a sense, the complement of extensibility and
modularity. Whereas those two stresses the importance of developing technology in such
a way that it will work together with future new technologies, backwards compatibility
stresses the importance of working well with what is already there. No new technology is
designed in a void.
Not only does a new technology normally have to be compatible with earlier ones in
technical matters, but also in the mental models that users have of the old technology.
Introducing new paradigms always has a cost, that has to be set off against future
benefits.
Take the example of CSS: people using HTML, and indeed most word-processors, are
used to attaching stylistic information to concrete elements.
To make style sheets acceptable at all, CSS has to allow people to continue working in
the same way, while expanding their options.
Sometimes a new technology replaces a previous one, although it is rare that it replaces
the old one completely. PNG in principle is able to replace GIF completely, and XHTML
can completely replace HTML. But even in such cases, some form of backward-
compatibility is needed in the form of facilities for mechanical conversion of resources to
the new format.
5) Html is a …. language
a) Programming language
b) Scripting language
c) Markup language
d) Not a language
Exercise
1)Difference between markup and programming language
2)What are the new features of html5
3)What do you mean by a markup language
4)What do you mean by backward compatibility
5)Write a summary on history of Html
Keyword
Scripting, markup, bars, programming, interactive, hyperlinked, facilities,
programming, language, evolution, widespread
2) b
3) c
4) a
5) c
Chapter 3: Basics Of Html
HTML Documents
• A tag is an element inserted into HTML that defines how a particular area of the
document should be formatted.
• Mainly we have two tags opening and closing tags
• An opening tag defines the beginning of a specific behavior, while a closing tag signals
the end of this particular behavior
• For instance, the very first tag in an HTML document would be <html>.
• Likewise, the very last tag in the same document will be</html>
• Opening tags starts with < followed by tag name followed by >
• Closing tags starts with < followed by tag name followed by />
• Ex: - <html> …</html>
Basic Rules
• All HTML documents must start with a document type declaration: <!DOCTYPE html>.
• The HTML document begins with <html> and ends with </html>
• For instance, the very first tag in an HTML document would be <html>. This tells a Web
browser that it is about to read and translate a Web page.
• Likewise, the very last tag in the same document will be </html>.
• The ‘/’ character is the closing marker; and this specific tag tells a browser it is finished
reading a Web page
• Main visible part of html documents starts from <body> tag
Elements in Html
• Elements are nothing but the Combination of start tag, content and the end tag
• Html elements can be used inside other
elements called nested Html Elements
• Some html elements have no content
and no end tag (ex: - <br>)
• The root element is <html> tag
• Example: -
<tag1>
<tag2>
</tag2>
</tag1>
Multiple Choice Questions
2) Tag is an …
a) Element
b) Main tag
c) Not an element
d) Attribute
Important Tags
HTML TAG
Body Tag
Body Tag
Paragraph Tag
Heading Tag
Heading Tag
• HTML headings are defined with the <h1> to <h6> tags.
• All these tags should be inside the body tags otherwise it will not be visible
• <h1> defines the most important heading.
• <h6> defines the least important heading
• Example: -
Code: -
Output: -
Paragraph Tag
• Paragraph tag starts with <p> and ends with </p> tag
• Paragraph tag is used to write a block of text
Code: -
Output: -
• <br> tag is used for break the statement and it has no end tag
Code: -
Output: -
• <hr> tag is used for a horizontal line and it has no end tag
Code: -
Output: -
Code: -
Output: -
Keyword
Break, preformatted, paragraph, horizontal line, vertical line
Formatting Text
Output: -
• <I>. </I> is used for italic text
Code: -
Output: -
Code: -
Output: -
Output: -
Output: -
Output: -
Output: -
• <sup>…. </sup> to create a superscript text
Code: -
Output: -
Code: -
Output: -
Multiple Choice Questions
2) Which of the following element is responsible for making the text bold in
HTML?
a) <br>
b) <b>. </b>
c) <I>. </I>
d) <hr>
3) Is <sup> and format tag
a) True
b) False
Keyword
Text, italic text, superscript, subscript, emphasized, mark, small, big, bold
Comments
• Comments are created by <! comments here --> here <! is the start tag and --> is the end
tag
• Comments are not visible in the web browser
• They are mainly used for documentation in html
• Comments can be also used for hiding content
• everything between the <! -- and the --> will be hidden from the display.
Code: -
Output: -
Attributes in html
• Attributes are mainly used for giving additional information for html elements
• Properties od Attributes
1. All Html elements can have attributes
2. All attributes should be used in the start tag of the element
3. Most of the attributes will be in a name=value pair
Links
Code: -
Output: -
Images
• Image tag <img> is used to insert images on web pages
• In <img> tag we have an attribute called src which is used to give the location of the
image to be displayed
<img src= “destination of the image">
• <img> doesn’t have end tag
Code: -
Output: -
1) Absolute URL
2) Relative URL
2) Relative URL: -When we provide a links to an image where the image is already
present in the same web server then that URL is called relative URL
• width attribute is used for specifying the width of the image to be displayed in the web
page
• height attribute is used for specifying the height of the image to be displayed in the web
page
Code: -
Output: -
• alt attribute is used to specifies an alternate text for an image, if the image for some
reason is not displayed. Then the text will be displayed
Code: -
Output: -
Keyword
Page, attributes, Absolute URL, Relative URL, hyperlink, src
MCQ Answers
1) b
2) a
3) b
Styles
Style Attribute
• Style is an important attribute in html which is used for giving style for the html elements
(colors, font, font size, etc.)
• To use style attribute, we have to follow the below given syntax
<tag name style="property: value;">
1) Background Color
background-color property sets the background color for the HTML elements.
Code: -
Output: -
Output: -
Code: -
Output: -
3) Fonts in html
We can add different fonts for html elements like paragraph, header tags
Code: -
Output:-
4) Font Size
We can add different fonts for html elements like paragraph, header… tags
Code: -
Output:-
Multiple Choice Questions
1) Style is an ….
a) Attribute
b) Tag
c) Element
d) None above
Keyword
Tagname, property, values, size style, tagname, font-type,
2) b
3) c
4) a
5) a
Quotation
The Quotation elements in HTML are used to insert quoted texts into a web page, which
is, different texts different from the normal texts in the web page.
The citation elements are used to provide reference to the text to specify the author,
bibliographies.
There are different tags which we can use to insert quotation in the html page
1) <blockquote> …. </blockquote> is used to quote a text used from other source
cite attribute can be used to provide the link from where the text source is used
Code: -
Output: -
Code: -
Output: -
3) The HTML <barb> tag is mainly used to define an abbreviation or an acronym, like
"HTML", "CSS", "Mr.", "Mrs.", etc.
Code: -
Output: -
Exercise
1)<article>
o The article element is one of the new elements that have been introduced with
HTML5.
o This element has been some confusion of how to use this element.
o But there seems to be an agreement that you use the <article> element when you
markup content, that makes sense on its own.
o But you are not supposed to use the <article> element around every single
paragraph – the point is, whatever you put in the <article> element it is supposed
to make sense on its own.
Code
Output
2)<aside>
The <aside> is one of the HTML5 elements added to define a section with additional
information related to the content around the aside element.
It is generally used to enhance an article with additional information or highlighting parts
that can be interesting to the user.
Content in aside is a stand-alone, non-essential part of the web page, and if you delete it,
the main content will not be affected.
Endnotes, comments, lists of terms, reference information, a collection of links, pull-
quotes, etc. are examples of information that can be within the <aside> element.
The HTML5 <aside> tag shows contents separately next to the main content, such as a
paragraph, at either the right side or the left side.
The contents inside the <aside> tag, usually has contents that are related to the main
content.
You can actually add a few extra lines to explain briefly, what’s inside the main content.
Code
Output
3)<detail>
The <details> HTML element creates a widget in which information is visible only when
the widget is Clicked
details elements have both opening and closing tag
inside these tags we have to write the content
Code
Output
4)<dialog>
In HTML, we can use the <dialog> tag to create a small dialog box inside the any
browser window to show some information easily.
The <dialog> tag can be used to create modal window or pop windows on a webpage to
show some message or some component of the webpage in it.
Code
Output
5) <HEADER>
The <header> tag defines the header of a page or a section.
It usually contains a logo, search, navigational links, etc.
It is mainly used for the main content definition
It contains both opening and closing tag
A <header> element typically contains:
heading elements (<h1> - <h6>)
logo or icon
Main information
Code
Output
6) <Footer>
The <footer> tag defines a footer section for a page or another element.
It usually contains summary information or end content.
Code
Output
3) which html element creates a widget in which information is visible only when the widget is
Clicked
a) <p>
b) <h>
c)<dialog>
d)<detail>
Keywords
Semantic, navigational, logo, agreement
2) d
3) d
4) c
5) b
Chapter 5: Lists
Lists are mainly used to merge related pieces of information so that they are
clearly associated with each other
Lists make the content easy to read
They help create a well-structured, more accessible, easy-to-maintain document
1. Ordered list
2. Unordered list
3. Description list
4. Nested lists
Ordered list
Whenever we want to create a list which will display the list of items in a specific
order, we use ordered lists
An ordered list starts with the <ol> and ends with </ol> tag
And each list items starts with <li> tag inside the <ol> </ol> tags
Code
Output
Unordered list
Whenever we want to create a list which will display the list of items in that don’t
have a particular ordered then we can use unordered lists
An ordered list starts with the <ul> and ends with </ul> tag
And each list items starts with <li> tag inside the <ul> </ul> tags
Code
Output
Description list
Description lists associate specific names and values within a list
Previously called definition lists, but renamed in HTML5
Description lists use one set of <dl></dl> tags wrapped around one or more groups of
<dt></dt> (name) and <dd></dd> (value) tags. You must pair at least one <dt></dt>
with at least one <dd></dd>, and the <dt></dt> should always come first in the
source order.
Code
Output
Nested List
Output
Advantages Of Lists
Flexibility: If you have to change the order of the list items in an ordered list, you
simply move around the list item elements; when the browser renders the list, it will
be properly ordered.
Styling: Using an HTML list allows you to style the list properly using CSS. The list
item tags <li> are different from the other tags in your document, so you can
specifically target CSS rules to them.
Semantics: HTML lists give the content the proper semantic structure. This has
important benefits, such as allowing screen readers to tell users with visual
impairments that they are reading a list, rather than just reading out a confusing
jumble of text and numbers.
Keywords
Ordered, Unordered, Description, Nested, structured, wrapped
3)a
4)c
Chapter 6: Forms
Forms are used to collect the data from the user’s inputs
To use the forms, we use <form> tag
Form has both starting tag <form> and ending tag </form>
We can also say form as a container for different elements for getting the user inputs
Creating Forms
All forms start with the <form> tag and end with </form>. All other form objects go
between these two tags
The syntax for form is
<form>
…..
…..
…..
</form>
Form has two important properties called METHOD AND ACTION
METHOD refers to post or get.
The post attribute will send the information from the form as a text document.
The get attribute is used mostly with search engines, and will not be discussed.
We will generally set METHOD="post".
ACTION usually specifies the location of the CGI script that will process the form data
So, the final syntax will look like below
<FORM METHOD="post" ACTION="mailto:[email protected]"></FORM>
Code
Output
2) label element <label>
label element is used to give the label for the form elements
It is used to tell the users what the form elements is all about
In the above example we don’t know what that text input is all about So we use label to
define it
label element starts with <label> tag and it also has closing tag also </label>
In label tag we use an important attribute called for attribute where the the for-attribute
value should be equal to the id attribute in the <input> tag
This for attribute will bind the <input> tag with the <label > tag
Code
Output
Input Types
Different Type in <input> Tags used
1) text
2) Checkbox
3) Radio
4) Password
5) Button
6) Submit
7) Reset
8) Color
1) Text
Syntax:
<input type=”text”>
It is used to create a single line input text field
Code
Output
2) Checkbox
Syntax
<input type=”checkbox”>
It is used to create a checkbox field
Code
Output
3) Radio
Syntax: -
<input type=” radio”>
To create a radio button
Code
Output
4) password
Syntax: -
<input type=” password”>
To create a password text field where the content will not be shown
Code
Output
5) button
Syntax: -
<input type=” button”>
To create a button
onclick attribute is used to give the button a function to do when it is clicked
Alert is used to alert a message in the browser in the onclick attribute
Code
Output
6) Submit
Syntax: -
<input type=” submit”>
To create a submit button
Here submits button is not handled because we require a form handler
to handle the data, we submit
The form handler is specified in form tag in action attribute
Code
OUTPUT
7) Reset
Syntax: -
<input type=” reset”>
To create a reset button
Code
Output
8) Color:
Color type is used for input field that will contain a color
It will allow the user to pick a random color
Code
Output
9) Date
It is an important type used for date field
It allows us to pick a data
Code
Output
Multiple Choice Questions
1) Choose the correct option.
A. text box.
B. radio button.
C. submit button.
D. All of these.
A. <label> tag in HTML is used for creating a tag for form elements.
B. <label> can be used to increase the clickable area of buttons
C. id attribute is used with <label> to increase the clickable area of form elements
D. None of the above
A. radio button allows to choose only one option from the given options.
B. default option can be chosen using attribute "selected" in radio button
C. default option can be chosen using attribute "checked" in radio button
D. checkbox allows to choose one or more than one options from the given options.
5. Which one of the following does not hold true regarding GET method in HTML?
Exercise
1)What do you mean by forms in html
2) Create a Sign-In Form.
3) Create a registration form
4) Explain about radio button
5) What do you mean by properties and values
6)Why forms are used in webpages?
7)Explain all the attributes of Form tag
8)Differentiate between Get & Post methods of Form tag
9)How text field and text area controls are different from each other?
10)Explain the use of Radio buttons in HTML forms with the help of an suitable
example.
11)Mention all the attributes of Check box. Justify how it is different from Radio
12)State the purpose of Submit and Reset button.
13)Which attributes are necessary to insert drop down list in a HTML page?
14)Sometimes it is better to use the text area element instead of an input
element of type text. Write a short note to explain when and why?
Keyword
Form, attributes, get, post, container method, generally, processing
5)d
Chapter 7: Table
A table is a Collection of organized columns and rows,
An example table is shown below.
1 2 3
4 5 6
7 8 9
Code
Output
Code
Output
Now there one more tag we can use called <th></th> tag in the <table> tag
<th> tag is mainly used to give the column header (main names)
Code
Output
Spanning columns or rows
Table cells can span multiple columns or rows using the Col span and row span
attributes. These attributes can be applied to and elements.
Code
Output
We should not design a table where both rows and columns overlap as this is invalid
HTML and the result is handled differently by different web browsers.
row span = A non-negative integer that specifies the number of rows spanned by a cell.
The default value of this
attribute is one (1). A value of zero (0) means that the cell will extend from the current
row until the last row of the table (<thread>, <tbody>, or <tfoot>).
colspan = A non-negative integer that specifies the number of columns spanned by the
current cell.
The default value of this attribute is one (1). A value of zero (0) means that the cell will
extend from the current to the last
column of the column group <colgroup> in which the cell is defined.
HTML also provides the tables with the <thread>, <tbody>, <tfoot>, and <caption>
elements. These additional
elements are useful for adding semantic value to your tables and for providing a place for
separate CSS styling.
When printing out a table that doesn't fit onto one (paper) page, most browsers repeat the
contents of <thread> on
every page.
There's a specific order that must be adhered to, and we should be aware that not every
element falls into place as
one would expect. The following example demonstrates how our 4 elements should be
placed.
Code
Output
Multiple Choice Questions
1) In HTML tables table row is defined by
a) <th> tag
b) <tr> tag
c) <td> tag
d) <row> tag
a) Cell parsing
b) Cell difference
c) Cell padding
d) All of above
a) <th> tag
b) <tr> tag
c) <td> tag
d) <t head> tag
a) footer>
b) <sepfooter>
c) <tfoot>
d) None of them
Exercise
1) Create a table which contains 4 rows and 3 columns
2) Which tag is used to create a row and explain the tag
3) How to merge two columns
4) How to create a table footer
5) What do you mean by a table
6)What attribute will be used on the CAPTION tag to put the table description at the bottom of
the
Table?
7)Name the tag that define show to divide the window into frames.
8)Differentiate between <TH> and <Caption> tags.
9)How <TD> and <TR> are different from each other?
Keywords
Row span, row merge, table rows, columns, cell parsing
Padding
Canvas
If we want to draw graphics on a web page, we can use <canvas>…</canvas> tag
<canvas>…</canvas> only defines a canvas where we can draw but to actually draw, we
need to use java script
Syntax used for <canvas>…</canvas> tag is
<canvas id="my Canvas" width="200" height="100"></canvas>
We can also specify height and weight attribute to specify the canvas height and weight
In the below example just used style to add border to the canvas
Code
Output
To draw in the above canvas, we have to
use JavaScript
Code
Output
2) Add a text in the canvas
Code
Output
SVG Graphics
SVG stands for Scalable vector graphics
It is used to define graphics (vector -based) directly without using java script
SVG graphics can be created by <sag>…</svg> tag
1) Circle
To create a circle using svg tag
Code
Output
2) Rectangle
To create a circle using svg tag
Code
Output
Advantages of SVG
2. Scalable
Raster formats like PNG and JPG become pixilated when resized.
Since SVG images are vector images, they do not suffer from loss of quality when
resized or zoomed in the browser.
This makes them suitable in case where an image has to be scaled to fit different screen
sizes.
3. Flexible
SVG is a W3C standard file format. Because of this, it works well with other open
standard technologies, including CSS, JavaScript, and HTML.
4. Can be animated
SVG graphics can be animated using JavaScript and CSS, making it a powerful image
format building interactive animations on the web.
5. Lightweight
Compared to other formats, SVG images are very small in size
Disadvantages of SVG
1. Not detailed
The SVG image format is great for 2D graphics like logos and icons but is not
ideal for detailed pictures.
SVG-based graphics can’t display as many details as standard image formats
since they are rendered using points and paths instead of pixels
Even though SVG has been around since 1999 and is supported by most modern
browsers (both on desktop and mobile), it does not work on legacy browsers like IE8 and
below.
4) SVG is used to
a) Define graphic based
b) Define normal graphics
c) Define direct graphics
d) Not used for graphics based
Keyword
SVG, graphics, vector, script, canvas, JavaScript, Circle, Square, screen, platform, scalable
5)a
Chapter 9: Multimedia in html
Multimedia can be sound, image, video etc.
It can be in many forms
And all these things can be inserted in the web page
1) Video
To insert a video inside an html page we can use <video> …. </video>
Source element is used to give the location of the video
<source> tag is used to set the location of the video
Code
2) Audio
To insert an audio in a html page we can use <audio>. </audio> tag
It also has controls attribute and <source> tag
<source> tag is used to specify the location of the audio
Controls attribute is used to specify the controls for audio
Code
Output
1) Which of the following attribute adds audio controls, like play, pause, and volume?
a) Audio
b) Controls
c) Source
d) Src
2) Which of the following HTML Video “Media Type is not supported in IE?
a) Webm
b) Mp4
c) Ogg
d) Mp3
iframes
iframes are used to display another web page within a web page
Here I in iframes denotes inline (inline frame)
To use an iframes we have to use <iframe> …</iframe>
Syntax used
<iframe src="URL" title="description"></iframe>
src is used to specify the URL of the web page to be inserted
title is used to specify the description of the frame inserted
Code
Output
Frames
HTML frames are used to divide your web page window into multiple areas where each
area can load a separate HTML document.
A collection of frames in the web page window is known as a frameset.
The window is divided into frames similar to table and rows
We can create frames by using <frame>…. </frame> tags
The <frame>…. </frame> tag defines how to divide the window into frames.
The rows attribute of tag defines horizontal frames and cols attribute defines vertical
frames.
Each frame is indicated by tag and it defines which HTML document shall open into the
frame.
Code
Output
Border: -This attribute specifies the width of the border of each frame in pixels.
For example, border="5". A value of zero means no border
src: -This attribute is used to give the file name that should be loaded in the frame. Its
value can be any URL. For example, src="/html/top_frame.htm" will load an HTML file
available in html directory
frameborder: -This attribute specifies whether or not the borders of that frame are shown;
it overrides the value given in the frameborder attribute on the tag if one is given, and this
can take values either 1 yes or 0 no
Code
horizontal forms
Output
Code
vertical forms
Output
3)a
4)a
5)b
Image Maps
An image maps is an image with clickable areas that usually act as hyperlinks
The image is defined by the<img>tag, and the map is defined by a <map>tag with <area>
tags to denote each clickable area.
We Use the use map and name attributes to bind the image and the map
Code
Output
Exercise
1) What do you mean by multimedia
2) What do you mean by iframes
3) How to create a horizontal frame
4) How to insert a video in an html page
5)What do you mean by image maps
6)How to embed audio in a HTML document
7)How to use image tag in html
8)How to author an abbreviation or an acronym
9)How to define a section that is quoted from another source in HTML
10)How to embed multiple videos in html
Keyword
Multimedia, music, images, controls, audio, source , Iframe, horizontal, vertical, frames, div,
Chapter 10: Geolocation
Geolocation is the art of figuring out where we are in the world and optionally sharing
that information with people we trust. There are many ways to figure out where we are -
our IP address, our wireless network connection, which cell tower our phone is talking to,
or dedicated GPS hardware that receives latitude and longitude information from
satellites in the sky.
Geolocation is one of the HTML5 API which is provided to identify the user’s
geographic location for the web application.
This new feature of HTML5 allows you to navigate the latitude and longitude coordinates
of the current website’s visitor(user). These coordinates can be captured by JavaScript
and send to the server-side which can show the user current location on the website.
GPS
The most accurate of the three, and it reads microwave signals from multiple satellites to
determine the current location.
geo=navigator. geolocation;
Geolocation Methods:
getCurrentPosition () – The visitor’s current location and returns a position object with
data.
Code
Input
Handling Errors and Rejections:
Code
Input
Multiple Choice Question
4. Which button let us move the map to the current position of the device?
a) currentPositionBtn
b) enableHighAccuracy
c) timeout
d) maximumAge
Exercise
1)what do you mean by geolocation
2)What do you mean by api
3)How to handle error when we set geolocations
4) what is watchPosition () method
5) Explain clearWatch ()
Keywords
Geolocation, navigator, random, error, location, latitude, longitude
MULTIPLE CHOICE QUESTIONS
ANSWERS
1)a
2)a
3)d
4)a
5)a
Chapter 11: Introduction to CSS
<span
Consider can you make all the text in the app slightly
bigger? Or purple is our new company color.
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, bicolor etc. 3. Value: Values are assigned to properties.
For example, color property can have the value either red or #F1F1F1 etc.
Format of CSS:
Selector {property: values)
Here h1 is a selector, color and font-size are properties and the given value red, and 15px
are the value of that property.
The selector is normally the HTML element you want to style.
Each declaration consists of a property and a value.
The property is the style attribute you want to change. Each property has a value.
responsive web design is a TECHNIQUE that ensures all the pages of the website look,
work and feel perfectly on any device.
Whether it is a tiny old cell phone with a screen width of 320px, a modern phablet with 7
inches screen, a big iPad, or a TV with a massive diagonal line, all the main aspects such
as content, design, and especially functionality should perform consistently to provide
users with an excellent user experience.
The concept of a responsive website appeared due to non-effective and ill-suited ways of
handling screen sizes. Originally, pages were built to target a particular device. This
approach implied creating a range of designs for each responsive tier resulting in
different versions of the same page. However, with the mobile web becoming a reality
and more and more devices with non-standard resolutions appeared, this approach has
quickly become irrelevant since it could not handle this variety efficiently.
The modern-day user expects to be able to access any website with a vast range of
devices. Your website should be ready to handle any scenario. You cannot ignore these
demands because numbers do not lie: according to recent studies,
more than 80% of users surf through the internet using mobile devices in 2019;
more than 60% of Google’s visits are done via a mobile device;
mobile devices accounted for more than 50% of website traffic worldwide.
Your brand cannot neglect this tendency. If you cannot meet these expectations and
growing demands by quickly adapting to the new reality, then you are doomed to failure,
and your brand is doomed to extinction.
They are:
1. Flexible layout;
2. Flexible images;
3. Media Queries.
Flexible Layout
A flexible layout is the heart and soul of the design. As a rule, it is a flexible grid built
with the relative units of measurement
Flexible Images
images have been an obstacle to implementing truly adaptable responsive pages since the
dawn.
The deal is, use of a flexible grid in the project made us abandon our beloved pixels and
replace them with relative units of measurement.
This means that all elements inside the grid should follow this lead. Images are no
exception.
More so, by playing a crucial role in visual communication and user experience, they
should first obey this principle.
Media Queries
The third key ingredient of a responsive website is media queries.
Media queries allow building different layouts within one project by tweaking your
whole design or parts to best suit the screen size.
With them, you can re-arrange and reorder existing elements like columns, rows, and
containers using basic CSS
CSS Modules
CSS modules let you import your .CSS file into a JavaScript file with the CSS definitions
as properties.
It also lets you use the compose property to extend and modularize style definitions.
CSS was defined to style documents, not UI components.
The lack of modularity in CSS language makes it hard to maintain complex or legacy
code.
Developers are afraid to make code changes since it's easy to break something when CSS
definitions are global.
CSS Modules solves these problems by limiting the scope to components. CSS Modules
is not an official standard.
It's a community-led effort popularized by the ReactJS ecosystem.
The problem of global scope is solved by CSS Modules since class names are local to the
component.
The same class name can be used in another component with different styling.
CSS Modules leverages on tooling. Tools convert local names to globally unique names.
A selector can extend styles from another, thus promoting reuse of styles within local
scope.
Composition can't be used for global scope. A selector can be composed from a selector
in global scope or selectors in other files.
Naming
CSS Modules should have tooling support to compile CSS to a low-level format called
Interoperable CSS (ICSS).
It should also work nicely with CSS processors (Less, Sass, Post CSS), bundlers (Webpack) and
JS frameworks (Angular, React).
Exercise
1) What do you mean by CSS?
2) Explain the properties of CSS
3) Why we are using CSS
4) What do you mean by modules in CSS?
5) Explain the features of CSS Modules
Keywords: -
Property, values, declaration, CSS, tag, sheet, style, modules, centered
The Element selectors A CSS declaration always ends with a semicolon, and declaration
groups are surrounded by curly brackets: example –
The ID selectors the id selector is used to specify a style for a single, unique element.
The id selector uses the id attribute of the HTML element, and is defined with a "#".
Example – Imagine within the body element of our html page, we have the following
paragraph element
We can then create a CSS rule with the id selector:
{color: red; text-align: center;}
we can also specify that only specific HTML elements should be affected by a class.
In the example below, all p elements with class="center" will be center-aligned: example
p. center {text-align: center;}
Attribute Selector
We 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;}
Code
Output
Make sure you include the correct path to your CSS file in the href. If the CSS file is in
the same folder as your HTML
file then no path is required (like the example above) but if it's saved in a folder, then
specify it like this
href="folder name/style.css".
<link rel="stylesheet" type="text/CSS" href="folder name/style.css">
External stylesheets are considered the best way to handle your CSS. There's a very
simple reason for this: when
you're managing a site of, say, 100 pages, all controlled by a single stylesheet, and you
want to change your link colors from blue to green, it's a lot easier to make the change in
your CSS file and let the changes "cascade"
Again, if you want to completely change the look of your website, you only need to
update this one file.
You can load as many CSS files in your HTML page as needed.
<link rel="stylesheet" type="text/CSS" href="main.css">
<link rel="stylesheet" type="text/CSS" href="override.css">
CSS rules are applied with some basic rules, and order does matter. For example, if you
have a main.css file with
some code in it:
p. green {color: #00FF00;}
All your paragraphs with the 'green' class will be written in light green, but you can
override this with another .CSS
file just by including it after main.css. You can have override.css with the following code
follow main.css, for
example:
p. green {color: #006600;}
Now all your paragraphs with the 'green' class will be written in darker green rather than
light green.
Other principles apply, such as the ‘! important' rule, specificity, and inheritance.
When someone first visits your website, their browser downloads the HTML of the
current page plus the linked CSS
file.
Then when they navigate to another page, their browser only needs to download the
HTML of that page; the
CSS file is cached, so it does not need to be downloaded again. Since browsers cache the
external stylesheet, your pages load faster.
Code
Output
CSS enclosed in <style></style> tags within an HTML document functions like an
external stylesheet, except that
it lives in the HTML document it styles instead of in a separate file, and therefore can
only be applied to the
document in which it lives. Note that this element must be inside the <head> element for
HTML validation (though it
will work in all current browsers if placed in body).
Code
Output
The padding-top property sets the top padding (space) of an element. This can take a
value in terms of length of %
Code
Output
Setting Display Using CSS
The display property is the most important CSS property for controlling layout.
The display property specifies if/how an element is displayed. Every HTML
element has a default display value depending on what type of element it is. The
default display value for most elements is block or inline. A block element is
often called a block-level element. An inline element is always just called an inline
element.
Block-level Elements
A block-level element always starts on a new line and takes up the full width
available (stretches out to the left and right as far as it can).
The <div> element is a block-level element.
Examples of block-level elements:
<div>
<h1> - <h6>
<p>
<form>
<header>
<footer>
<section>
<div>
div is the standard block-level element. A block-level element
starts on a new line and stretches out to the left and right as far as it can.
Other common block-level elements are p and form, and new
in HTML5 are header, footer, section, and more.
Inline Elements
An inline element does not start on a new line and only takes
up as much width as necessary. This is an inline <span>
element inside a paragraph.
Span is the standard inline element. An inline element can wrap
some text inside a paragraph <span> like this </span> without
disrupting the flow of that paragraph. An element is the most
common inline element, since you use them for links.
Examples of inline elements:
<span>
<a>
<imp>
CSS Syntax
Display: value;
The values of display property have the following meanings:
Block -This value causes an element to generate a block box.
Inline-block - This value causes an element to generate an inline-level
block container. The inside of an inline-block is formatted as a block box,
and the element itself is formatted as an atomic inline-level box.
Inline - This value causes an element to generate one or more
inline boxes.
list-item - This value causes an element (e.g., LI in HTML) to
generate a principal block box and a marker box.
None - This value causes an element to not appear in the
formatting structure
Here are some examples of the display property:
p {display: block}
em {display: inline}
li {display: list-item}
. blue. Red All elements with class blue and red (a type of Compound selector)
: lang(en) Element that matches: lang declaration, for example <span lang="en">
div > p child selector
Attribute Selectors
Code
Output
CSS Borders
CSS borders allows us to specify the different style, width, and color of an element's border.
The border property is a shorthand syntax in CSS that accepts multiple values for drawing a line
around the element it is applied to.
Values
The border property accepts one or more of the following values in combination:
The border-style property specifies what kind of border to display
1) dotted
2) dashed
3) none
Sets no border
4) groove
5)double
Code
Output
Border width and color
We can also add the width and color for the border by using border-width and border-
color properties
Code
Output
You can also combine class names to target elements more specifically. Let's build on the
example above to
showcase a more complicated class selection.
In this example, all elements with the. warning class will have a blue text color, elements
with the. important class
with have an orange text color, and all elements that have both the. important and.
warning class name will have a
red text color.
Notice that within the CSS, the. warning. Important declaration did not have any spaces
between the two class
names. This means it will only find elements which contain both class names warning
and important in their class
attribute. Those class names could be in any order on the element.
If a space was included between the two classes in the CSS declaration, it would only
select elements that have
parent elements with a. warning class names and child elements with. important class
names.
Code
Output
6)Which of the following CSS property defines the different properties of all four sides of an
element’s border in a single declaration?
a) border
b) padding
c) border-collapse
d) border-width
7) Identify the CSS property defining bottom-left corner shape of the border?
a) border-radius
b) border-corner-radius
c) border-bottom-left-radius
d) border-left-radius
8) Select the CSS property that sets the width of an element’s bottom border?
a) border-width
b) border-bottom
c) border-width-down
d) border-bottom-width
9) Which of the following CSS property border-color property sets the color of an element’s
four borders?
a) border-background
b) border-background-color
c) border-color
d) all of the mentioned
10) Choose the CSS property that can be used for collapsing the borders between table cells?
a) border
b) collapse-border
c) border-collapse
d) border-cell
Exercise
1) What is the different style sheet in CSS?
2) Explain internal style sheet
3) Explain the difference between internal and external style sheet
4) Explain the syntax for CSS selectors
5) Explain class name selectors
Keywords
collapsing, internal, inline, element, property, external, background
Text Effect
CSS is a language that describes the style of an HTML document. You can set the
following text properties of an element:
The color property is used to set the color of a text.
The direction property is used to set the text direction.
The letter-spacing property is used to add or subtract space between the
letters that make up a word.
The word-spacing property is used to add or subtract space between the
words of a sentence.
The text-indent property is used to indent the text of a paragraph.
The text-align property is used to align the text of a document.
The text-decoration property is used to underline, overline, and
strikethrough text.
The text-transform property is used to capitalize text or convert text to
uppercase or lowercase letters.
The white-space property is used to control the flow and formatting of
text.
The text-shadow property is used to set the text shadow around a text.
Set the Text Color
The following example demonstrates how to set the text color. Possible
value could be any color name in any valid format.
<p style="color: red;">This text will be written in red. </p>
Set the Text Direction
The following example demonstrates how to set the direction of a text.
Possible values are ltr or rtl.
<p style="direction;">This text will be rendered from right to left </p>
The following example demonstrates how to set the space between words.
Possible values are normal or a number specifying space.
<p style="letter-spacing:5px;">This paragraph is having spaces between the letters.
</p>
Code
Output
Set the Text Indent
The following example demonstrates how to indent the first line of a
paragraph. Possible values are % or a number specifying indent space.
<p style="text-indent:1cm;">
This text will have first line indented by 1cm and this line will
Code
Output
Code
Output
Decorating the Text
The following example demonstrates how to decorate a text. Possible
values are none, underline, overline, line-through, blink.
<p style="text-decoration: underline;"> This text will be underlined </p>
<p style="text-decoration: line-through;"> This text will be strike through.
</p>
<p style="text-decoration: overline;"> This text will have an over line. </p>
<p style="text-decoration: blink;">This text will have blinking effect </p>
Code
Output
Set the Text Cases
The following example demonstrates how to set the cases for a text.
Possible values are none, capitalize, uppercase, lowercase.
<p style="text-transform: capitalize;"> This text will be capitalized </p>
<p style="text-transform: uppercase;"> This text will be in uppercase </p>
<p style="text-transform: lowercase;"> This text will be in lowercase </p>
Code
Output
CSS Fonts
A font is the combination of typeface and other qualities, such as size, pitch,
and spacing. For example, Times Roman is a typeface that defines the shape
of each character. Within Times Roman, however, there are many fonts to
choose from -- different sizes, italic, bold, and so on. You can set the following
font properties of an element:
The font-family property is used to change the face of a font.
The font-style property is used to make a font italic or oblique.
The font-variant property is used to create a small-caps effect.
The font-weight property is used to increase or decrease how bold or light
a font appears.
The font-size property is used to increase or decrease the size of a font.
The font property is used as shorthand to specify a number of other fonts
properties.
style </p>
Code
Input
Input
Code
Input
Input
Code
Input
1. Which of the following CSS property is used to set the text formatting?
a) font
b) font-style
c) text-decoration
2. Which of the following sets the color of any text decoration, such as underlines, overlines,
and strike throughs?
a) text-font
b) text-format
c) text-color
d) text-decoration-color
3. Which of the following sets what kind of line decorations are added to an element, such as
underlines, overlines, etc.?
a) text-style
b) text-decoration
c) text-line
d) text-decoration-line
4. Which of the following text-decoration value specifies each line of text has a line above it?
a) line
b) underline
c) overline
d) blink
b) text-overline-decoration
c) text-overline-width
d) text-decoration-overline-width
6) Which of the following value is supposed to be a slightly bolder weight that standard bold in
font attribute?
a) emphasize
b) light
c) lighter
d) dark
7)Which of the following property allows contextual adjustment of inter-glyph spacing, i.e., the
spaces between the characters in text?
a) font-style
b) font-family
c) font-kerning
d) font-variant
9)Which of the following selects a normal, or small-caps face from a font family?
a) font-weight
b) font-synthesis
c) font-kerning
d) font-variant
10)Which of the following value specifies whether the user agent is allowed to synthesize bold
or oblique font faces when a font family lacks bold or italic faces?
a) font-weight
b) font-synthesis
c) font-kerning
d) font-variant
Exercise
1) Explain fonts in CSS
2) Explain three different types of fonts
3) How to set the space between the text
4) What do you mean by text-indent?
5) How to set the font style
Keywords
italic, oblique, font-variant-font-size, emphasizes, family, kerning,Text-transform, letter-fonts,
lowercase, uppercase, capitalize
To use float, you start with the normal layout of boxes stacked vertically on the page,
but you can allow certain elements to move to the side and have other material flow
around them. To do that, HTML elements have a property float, which will make the
element float to either the left or the right side of the page (your choice). Of course,
other material can't flow around it unless it is narrow enough, so we also have to
consider the width of the element. We'll look at that, too.
This technique doesn't go well with the fluid design, but is good for positioning things
like logos, etc. that need always be in a certain place. Absolute positioning is sometimes
used in a limited way as part of an overall layout that mostly uses float.
LAYOUT STRATEGIES
Web page layout with CSS is more of an art than science; there is no formula for
marking up your HTML page or creating the CSS. CSS layout is something that you will
learn through experience, learning the different CSS properties, following tutorials, and
practicing a lot. What follows in this section is a set of guidelines that can be useful as
you start learning about this topic.
Start with your content. Design starts with your content (headlines, text, links,
photographs, etc.), not with colors, fonts, or icons. It is the page message that should
dictate the design. For example, if the goal of a student organization page is to get more
students to join, you can put a large photo of the members doing something fun or
interesting, together with quotes from them. Then you use style to make them
compelling.
Mock up your design. Don't start your design with code, start with a drawing. Using a
drawing program (Paint, Photoshop, Illustrator, etc.) gives you freedom to explore
different colors, fonts, images, and positioning, without having to write code. This way
you can experiment faster with many choices. If your page needs user interface
elements such as buttons, tabs, etc. you can use the free stencil kit from Yahoo,
together with Photoshop.
Identify the boxes. Once you are satisfied with your mockup, you can start thinking
about the HTML structure. Basically, you need to identify which elements look like
individual boxes, because they will have to be in container tags in your HTML.
Remember background images. Very often, you can more easily place an image with the
background-image property than the <img> tag. This is because you can put other
information on top of this image. However, you should know that background images
are not printed, thus, don't put important information (such as maps) as background.
Grid
CSS Grid Layout is a two-dimensional grid-based layout system that,
compared to any web layout system of the past, completely changes the way we design
user interfaces. CSS has always been used to layout our web pages,
but it’s never done a very good job of it
Grid is the very first CSS module created specifically to solve the layout problems we’ve
all been hacking our way around for as long as we’ve been making websites.
Grid Container
The element on which display: grid is applied. It’s the direct parent of all the grid items.
In this example container is the grid container.
<div class="container">
<div class="item item-1"> </div>
<div class="item item-2"> </div>
<div class="item item-3"> </div>
</div>
Grid Line
The dividing lines that make up the structure of the grid.
They can be either vertical (“column grid lines”) or horizontal (“row grid lines”) and
reside on either side of a row or column. Here the yellow line is an example of a column
grid line.
Grid Track
The space between two adjacent grid lines.
You can think of them as the columns or rows of the grid. Here’s the grid track between
the second and third-row grid lines.
Grid Area
The total space surrounded by four grid lines.
A grid area may be composed of any number of grid cells. Here’s the grid area between
row grid lines 1 and 3, and column grid lines 1 and 3.
Grid Item
The children (i.e., direct descendants) of the grid container. Here the item elements are
grid items, but sub-item isn’t.
<div class="container">
</div>
Grid Cell
The space between two adjacent row and two adjacent column grid lines.
It’s a single “unit” of the grid. Here’s the grid cell between row grid lines 1 and 2, and
column grid lines 2 and 3.
Code
Output
Multiple Choice Questions
1) Which of the following is most suitable for a grid layout?
a) toolbar
b) form
c)menu
d) CSS float
4)You are creating a grid layout. What does 1fr mean in the following code?
a) The first two columns will be two fraction units of the stated width.
b) The third and fourth columns is 1 fraction unit of the remaining space in the grid.
d) The second column will be half of the remaining space in the grid.
5)How many columns and rows are defined in the following code?
section {
display: grid;
section header {
grid-column: 1 / 4;
grid-row: 1;
section nav {
grid-column: 1;
grid-row: 2 / 3;
section article {
grid-column: 2;
grid-row: 2;
}
section aside {
grid-column: 3;
grid-row: 2;
section footer {
grid-column: 1 / 4;
grid-row: 3;
Exercise
1) What do you mean by grid
2) What do you mean by layouts?
3) What do you mean by grid layouts?
4) What do you mean by grid are?
5) Explain the two techniques in CSS layouts
Keywords
Techniques, layouts, grids, narrow, positioning, guidelines
Chapter 15: Box Model
You have seen the border that surrounds every box i.e., element, the padding that
can appear inside each box, and the margin that can go around them. In this
chapter, we will learn how to change the dimensions of boxes. We have the
following properties that allow you to control the dimensions of a box.
The height property is used to set the height of a box. The width property is used to set
the width of a box.
The line-height property is used to set the height of a line of text.
The max-height property is used to set a maximum height that a box can
The min-height property is used to set the minimum height that a box can
The max-width property is used to set the maximum width that a box can
The min-width property is used to set the minimum width that a box can
Code
Input
Multiple Choice Question
a) height
b) padding-height
c) top
d) padding-top
2)Which of the following display property value is described by treats the element as inline?
a) inline-block
b) list-item
c) block
d) inline
3)Which of the following property defines the style for the bottom border of an element?
a) border-bottom-style
b) border-collapse
c) border-style-bottom
d) none of the mentioned
4)Which of the following visibility property value is described by the element is not visible, but
the layout of surrounding elements is not affected?
a) visible
b) hidden
c) collapse
d) none of the mentioned
5)Which of the following property defines the style for the left border of an element?
a) border-style
b) border-left-style
c) border-left-width
d) border-right
Exercise
1) what do you mean by box-model?
2) Explain the features of box-model
3) Explain max-height and max-width property
4) Draw a simple box -model layout
5) Explain some border properties
Keywords
Border, bottom, collapse, inline-block, hidden, top, padding, Hight
1)d
2)d
3)a
4)b
5)b
Chapter 16: CSS Pagination
Code
Output
When you click on pagination 1number you will be
redirected into page1
Exercise
1)Explain about pagination
2) Different type of pagination
3) what do you mean by breadcrumbs
Keywords
Pagination, breadcrumbs, redirect, homepage
Chapter 17: Buttons
With the help of CSS, we can do modification on buttons like adding color, changing
borders etc.
Buttons are for triggering actions. When do you use the <button> element? A good rule
is to use a button when there is “no meaningful href.”
Here’s another way to think of that: if clicking it doesn’t do anything without JavaScript,
it should be a <button>.
A <button> that is within a <form>, by default, will submit that form. But aside from
that, button elements don’t have any default behavior, and you’ll be wiring up that
interactivity with JavaScript.
Code
Output
In CSS we can use. buttons {} to give the properties of buttons inside the style tag and to
create a button we have to use <button>…</button> tag in html
Code
Output
Code
Output
2) Button color
We can change the button color by using background-color property
Code
Output
3) Rounded Button
We can change the button to rounded button by using border-radius property
Code
Output
4) Button Width
We can change the button width to by using width property
Code
Output
a. Background-color
b. Button-color
c. Font-size
d. Width
Exercise
1) How to create a button
2) How to use CSS for styling the buttons
3) How to create different button size
Keywords
4)c