HTML & CSS Front-End Development Guide
HTML & CSS Front-End Development Guide
HTML
CSS
Note: This document not having more examples, Should refer recording sessions or your running notes.
Website:
2
A website is a collection of multiple webpages that are linked together under a single domain name.
Webpage:
A webpage is a single document or page that is part of a website, contain text, images, links, and multimedia.
Front-End:
The front end of a website is the part that users see and interact with, including the design, layout, and user experience
CSS (Cascading Style Sheets) → Styles the webpage (colors, fonts, layout).
Front-End Frameworks/Libraries:
[Link]
Introduction To Html
→HTML stands for HyperText Markup Language. It is the standard language used to create and structure
content on the web.
→It is markup language , Not a programming language because HTML only structures content; it does not handle
logic like JavaScript.
→It is Platform-Independent → Works on all browsers (Chrome, Firefox, Edge, etc.).
→We can combine with CSS & JavaScript → Used with CSS for styling and JavaScript for interactivity.
→In short, HTML is the skeleton of every website!
Elements and Tags:
→HTML documents are made up of elements, which are represented by tags.
→Tags are enclosed in angle brackets (< >). Most tags come in pairs: an opening tag (<tag>) and a closing tag
(</tag>).
Example: <p>This is a paragraph.</p>
Document Structure:
An HTML document has a specific structure:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
3
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
• <!DOCTYPE html> declares the document type and version of HTML (HTML5 in this case).
• <html> is the root element of the document.
• <head> contains meta-information about the document, such as the title and links to stylesheets.
• <body> contains the visible content of the webpage.
Horizontal Rule
→<hr> tag is Used to create a horizontal line to separate sections of content.
→It is a self-closing tag (no closing tag needed).
→By default, it takes the full width of the page.
<p>Section 1</p>
<hr>
<p>Section 2</p>
Line Break
→<br> is Used to insert a line break inside a paragraph or text.
→It is also a self-closing tag.
<p>This is<br>a paragraph<br>with line breaks.</p>
Preformatted Text
→<pre> is used to Displays text exactly as written in the HTML file, preserving spaces, line breaks.
→Useful for showing code snippets, poetry, where formatting matters
Text Formatting:
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Smaller text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript text
<b>:
→The HTML <b> element defines bold text, without any extra importance.
<b>This text is bold</b>
<strong>:
→The HTML <strong> element defines text with strong importance. The content inside is typically displayed in bold.
<strong>This text is important!</strong>
<i>:
→The <i> Html element is used for styling purposes to display text in an italic font.
→It does not carry any additional meaning or emphasis.
→Commonly used for foreign words, technical terms, or citations.
5
Relative Path
→A relative path provides the file location relative to the current document.
→It is shorter and flexible, making it useful when moving files within the project.
→An HTML table is defined using the <table> tag. It consists of rows (<tr>) and columns (<td> for data cells and
<th> for header cells).
a) <table>
Defines the table.
b) <tr> (Table Row)
Defines a row inside a table.
c) <td> (Table Data)
Defines a data cell.
d) <th> (Table Header)
Defines a header cell, which is bold and center-aligned by default.
Example:
<table border="1">
<tr>
<th>Student Name</th>
<th>Subject</th>
<th>Marks</th>
</tr>
<tr>
<td>Alice</td>
<td>Math</td>
<td>85</td>
</tr>
<tr>
<td>Bob</td>
<td>Science</td>
<td>90</td>
</tr>
</table>
<table> Tag Attributes
a) border
Specifies the thickness of the table border.
Example: <table border="2">
b) cellspacing and cellpadding
cellspacing: Controls the space between table cells.
cellpadding: Controls the space inside each cell.
10
action
Defines the URL where form data is sent (e.g., a server-side script).
method
Specifies how data is sent: "GET" (data in URL) or "POST" (data in request body).
id
Unique identifier for JavaScript or CSS targeting.
→HTML forms support various input types to collect different kinds of data.
→Each input type is designed for a specific kind of user input. We are using <input> tag.
<label for="username">Username:</label>
<label for="password">Password:</label>
<label for="email">Email:</label>
<label for="age">Age:</label>
<label>Gender:</label>
Checkboxes (type="checkbox")
<label>Hobbies:</label>
<form>
<fieldset>
<legend>Personal Details</legend>
13
<label for="name">Name:</label>
<label for="email">Email:</label>
</fieldset>
</form>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="javascript">JavaScript</option>
</select>
• HTML Lists
• HTML Links
• Images and Audio
HTML LISTS
HTML lists are used to group related items together in an organized way. There are three main types of lists in HTML:
An ordered list is used when the order of items matters. Each item in an ordered list is marked with numbers, letters,
or roman numerals.
<ol>
<li>First item</li>
14
<li>Second item</li>
<li>Third item</li>
</ol>
The <ol> tag supports the type attribute, which changes the numbering style:
<ol type="I">
<li>Introduction</li>
<li>Body</li>
<li>Conclusion</li>
</ol>
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
</ol>
An unordered list is used when the order of items does not matter. The items are marked with bullets (•).
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
15
<ul type="square">
<li>Math</li>
<li>Science</li>
<li>History</li>
</ul>
A definition list is used for listing terms and their descriptions, similar to a dictionary.
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
</dl>
4. Nested Lists
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
<li>Vegetables
<ul>
16
<li>Carrot</li>
<li>Broccoli</li>
</ul>
</li>
</ul>
HTML Links
HTML links (also called hyperlinks) allow users to navigate between different web pages, sections of the same page.
They are created using the <a> (anchor) tag.
→The <a> tag is used to define a hyperlink, and the href attribute specifies the destination URL.
→By default, links open in the same tab. To open a link in a new tab, use the target="_blank" attribute.
→we can create a clickable link that opens an email client using the mailto: scheme.
→We can create a link that allows users to call a number on mobile devices using tel:
→Anchor links help users jump to specific sections of a page using the id attribute.
<a href="[Link]
</a>
→HTML provides built-in support for audio and video playback using the <audio> and <video> elements.
→The <audio> tag is used to embed audio files like MP3, WAV, OGG.
17
</audio>
→The <video> tag is used to embed video files like MP4, WebM, Ogg.
</video>
<div> tag:
The <div> (short for "division") tag is a block-level element that is primarily used to group other HTML elements
together for styling and layout purposes.
Example:
<div class="container">
18
<h2>Welcome to My Website</h2>
</div>
<span> tag:
The <span> tag is an inline element used to apply styling to a specific part of text within a larger Section.
Example:
<iframe> tag
The <iframe> (Inline Frame) element in HTML is used to embed another webpage or document within the current
webpage.
Note: Referrer data is information about the previous webpage that a user visited before reaching the current page.
origin Sends only the origin (e.g., [Link] not the full URL).
origin-when-cross-origin Sends full referrer only for same-origin requests; otherwise, sends only the origin.
strict-origin Sends only the origin, and only if the destination is HTTPS.
strict-origin-when-cross-originSends full referrer for same-origin and only origin for cross-origin, but only if the
destination is HTTPS.
Use-Cases:
Semantic elements
19
Semantic elements in HTML are elements that convey meaning about their content, making it easier for both
developers and search engines to understand the structure of a webpage.
• <article>
• <aside>
• <footer>
• <header>
• <nav>
• <section>
• <figcaption>
• <figure>
Example:
<header>
<h1>Welcome to My Website</h1>
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Contact</a>
</nav>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
20
</ul>
</nav>
<section>
<h2>Our Services</h2>
</section>
Example:
<footer>
<nav>
</nav>
</footer>
Example
<aside>
<h2>Related Posts</h2>
<ul>
</ul>
</aside>
Example: Think of <aside> as the side column in a newspaper, where ads or related news appear.
An article should make sense on its own, and it should be possible to distribute it independently from the rest of the
web site.
Note: we will find HTML pages with <section> elements containing <article> elements, and <article> elements
containing <section> elements.
• This happens when you have multiple independent articles grouped under a common theme.
<section>
<article>
</article>
<article>
</article>
</section>
• This happens when an article itself has multiple sections inside it.
<article>
<section>
<h3>Introduction</h3>
22
</section>
<section>
<h3>Frontend vs Backend</h3>
</section>
</article>
• Introduction to CSS
• Different Ways to apply CSS
• CSS Colors
What is CSS:
→CSS describes how HTML elements are to be displayed on screen, paper, or in other media
→CSS saves a lot of work. It can control the layout of multiple web pages all at once
1. Inline CSS:
23
→In this method, we CSS Properties applied directly within an HTML element using the style attribute.
2. Internal CSS
→In this method, CSS properties is written inside the <style> tag within the <head> section of an HTML document.
<head>
<style>
p{
color: green;
font-size: 18px;
</style>
</head>
3. External CSS
→In this method, CSS Properties are written in a separate .css file and linked to an HTML document using the <link>
tag.
[Link]
p{
color: red;
font-size: 22px;
<head>
</head>
COLORS in CSS:
→We can apply the colors in CSS by using following CSS Properties:
a) Named Colors:
→CSS Provides some pre-defined color names such as red, blue etc..
Ex: color:red;
→A HEX code is a six-digit code representing colors in the RGB (Red, Green, Blue) format.
Format: #RRGGBB
→Defines colors using Red, Green, and Blue values in the range of 0 to 255.
RGBA in CSS
→The Alpha channel controls the transparency (0 = fully transparent, 1 = fully visible).
Opacity
CSS gradients
→CSS gradients let you display smooth transitions between two or more specified colors.
→ To create a linear gradient we must define at least two color stops. Color stops are the colors you want to render
smooth transitions among
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
Direction:
Top to Bottom(this is default)
25
→CSS selectors define which HTML elements the CSS Properties apply to
Simple Selectors
*{
p{
26
#abc{
.abc{
h1,p,span{
Combinator Selectors
div p{
div > p{
h1+p{
General Sibling Selector (A ~ B): Selects all siblings after a specified element.
h1 ~ p{
Attribute Selectors
[disabled] {
background-color: gray;
input[type=”text”] {
background-color: gray;
→The CSS box model is essentially a box that wraps around every HTML element. It consists of: content, padding,
borders and margins.
→Th innermost box contains the content of element. Surrounding that is the padding then border and finally the
outermost layer the margin.
Note: In Developers tools of every browser we can see the box model for html element.
→CSS Provides properties that can be used to change the padding, border and margin for HTML Element.
Borders
Border Properties
border-width:2px;
border-style:solid;
border-color:red;
border-radius: 10px;
28
Padding:
→Padding is the space between the content of an element and its border. It provides inner spacing
Padding Properties:
padding:10px;
padding:10px 20px;
Margins :
→Margin is the space outside an element’s border that separates it from other elements. It controls the outer
spacing of an element.
Margin Properties:
margin:10px;
margin:10px 20px;
Note:
Margin collapsing is a behavior in CSS where vertical margins of adjacent elements are combined (collapsed) into a
single margin instead of adding up.
29
→When two block elements are placed next to each other, their vertical margins collapse, and the larger of the two
margins is used instead of adding them together.
.div1 {
margin-bottom: 20px;
.div2 {
margin-top: 30px;
→If a parent element has no padding or border, the top margin of its first child and the bottom margin of its last child
will collapse with the parent’s margin.
.parent {
margin: 20px;
.child {
margin-top: 30px;
Note:
→When you apply margin:auto to an element, it tells the browser to distribute the available space equally on both
sides.
float:
when an element is floated, it is taken out of the normal flow of the document (though still remaining part
of it). It is shifted to the left, or right, until it touches the edge of its containing box, or another floated
element.
inherit: The element inherits the float value from its parent.
Note:
→When an element is floated, it is taken out of the normal document flow. This means that other block-level
elements will behave as if the floated element does not exist, and they will occupy the space as if the floated
element were not there.
→Inline elements and text will wrap around the floated element. This is the primary use case for the float property,
such as wrapping text around an image.
Clearing Floats:
30
→The clear property is used to prevent elements from wrapping around floated elements. It is useful when you want
to ensure that an element starts below any floated elements.
Values of clear
CSS Units
→Many CSS properties take "length" values, such as width, margin, padding, font-size, etc.
Absolute
→The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.
→Absolute length units are not recommended for use on screen, because screen sizes vary so much. However, they
can be used if the output medium is known, such as for print layout.
Note: The viewport is the visible area of a webpage on a device (like a phone, tablet, or computer). It is the browser
window size where content is displayed.
Relative
→ Relative units depend on the parent element, viewport, or other factors. They make web pages more responsive
and adaptable.
em → Relative to the font size of the parent element. If parent font-size = 16px, then 1em = 16px.
rem (Root em) →Similar to em, but relative to the root (html) font size. By default, 1rem = 16px
b) Relative to Viewport
31
c) Percentage (%)
1. Font Properties
These properties control the appearance of text, including size, family, weight, and style.
Common values:
Common values:
Values:
Values:
Values:
background-image
To use an image as a background, we need to specify the path to the image file using the url() function.
background-image: url('path-to-image');
Note:By default, the background image repeats itself both horizontally and vertically to fill the entire element.
background-repeat
Values:
background-position
Values:
background-size
Values:
cover: The image scales to cover the entire element (may crop the image).
background-attachment
Controls whether the image scrolls with the content or stays fixed.
Values:
CSS Positioning
→CSS positioning is a way to control where an element is placed on a web page. By default, elements are positioned
in the normal document flow,
→However, CSS positioning allows you to override this behavior and place elements anywhere you want on the page.
→The position property in CSS is used to define how an element is positioned. It has five possible values:
Static (default)
Relative
Absolute
Fixed
Sticky
→Elements are placed in the normal document flow (i.e., they appear in the order they are written in the HTML).
→The top, right, bottom, left, and z-index properties do not work with static positioning.
2. position: relative;
→The element is positioned relative to its normal position in the document flow.
→we can use top, right, bottom, and left to move the element from its original position.
→Other elements on the page will not adjust to fill the gap left by the moved element.
3. position: absolute;
→The element is removed from the normal document flow. This means other elements on the page will ignore it and
act like it doesn’t exist.
34
→The element is positioned relative to its nearest positioned ancestor. If no positioned ancestor exists, it is
positioned relative to the viewport (the browser window).
Note:A positioned ancestor is any parent element with position set to relative, absolute, fixed, or sticky.
→we can use top, right, bottom, and left to precisely place the element.
position: fixed;
→It stays in the same place even when the page is scrolled.
→we can use top, right, bottom, and left to place the element.
position:sticky; relative+fixed
z-index is a CSS property that controls the stacking order of elements on a webpage. It determines which elements
appear in front or behind others when they overlap.
z-index only works on elements with a positioned property (position: relative;, absolute;, fixed;, or sticky;).
The higher the z-index value, the closer the element is to the user (it appears on top).
If two elements have the same z-index, the one that appears later in the HTML code is stacked on top.
→The CSS Flexbox (Flexible Box Layout) is a modern CSS layout system that provides an efficient way to align and
distribute space among elements in a container.
→To use all of Flexbox's properties, we need to set the display property for an element to flex or inline-flex.
→ This turns the element into a flex container, and the children of that element become flex items.
→This turns the element into a flex container, and the children of that element become flex items.
we can use both flex and inline-flex to make an element a flex container. The difference is in how they interact with
surrounding elements.
display: flex
This makes the flex container behave like a block-level element. The flex-container takes up the entire available width
of its parent element. It starts on a new line, and the element that comes after it also starts on a new line.
display: inline-flex
This makes the flex-container behave like an inline-level element. This allows other inline elements (like buttons) to
flow alongside it. Using the previous example, this is how the elements will be arranged when you change display
from flex to inline-flex.
The flex container properties allow you to control the layout and alignment of the flex items within a flex container.
We can apply these properties on the flex container, and not on its items.
flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content
The flex-direction property defines the direction for displaying the flex items. It is what sets the flex container's main
axis. This property can take any of these four values:
column
row-reverse
column-reverse
Sometimes, the space within the flex container will not be enough for the flex items.
In such cases, you use the flex-wrap property to choose whether to let the flex-items overflow or begin on a new line.
wrap
wrap-reverse
The flex-flow property is a shorthand for the flex-direction and flex-wrap properties. This means that when you use
flex-flow, you can apply both properties with only a single line of code.
This justify-content property handles the alignment of flex items on the main axis of the flex container.
You can use it to take care of how space is distributed on the main axis. This property takes any of the following
values:
flex-end
center
36
space-between
space-around
space-evenly
The align-items property handles the alignment of flex items on the cross-axis of the flex container. It can take any of
the following values:
flex-start
flex-end
center
When you have a flex container with wrap (or more than one flex line), you may need to align the lines to distribute
the space as you want. That is when you use align-content. This property can take any of the following values:
flex-start
flex-end
center
space-between
space-evenly
space-around
Every direct child of a flex container is a flex item. Flexbox also has properties that you can apply to individual flex
items. They include the following:
order
align-self
flex-grow
flex-shrink
flex-basis
flex
The order property determines the order of appearance for the flex items.
The value you give to this property must be a number. A flex item with a lower number will appear before one with a
higher number.
37
we can use the align-self property to give a flex item a different alignment from the other items.
It works the same way as the align-items property. The difference is that whereas align-items applies to all flex items,
the align-self property is applied to only specific items.
When we set a container's display to flex, often there will be some extra space after the items are arranged.
This property control how much a flex item should expand to fill the available space within the flex container.
The extra space is shared proportionately if we apply for multiple flex items within container
You use flex-grow when you want to increase the flex item's size if there's extra space. But, you use flex-shrink when
you want to decrease the flex-item's size if there's not enough space in the flex container.
A higher value makes the item shrink more relative to other items.
You can use the flex-basis property to set the default length of a specific flex item. This is either the width or height of
the item depending on the flex-direction.
If the flex-direction is row or row-reverse, the value for flex-basis becomes the initial width of the item.
And if flex-direction is column or column-reverse, then the value for flex-basis becomes the initial height of the item.
we can use flex as a shorthand for the flex-grow, flex-shrink, and flex-basis properties.
flex: 2 0 50px;
Flexbox Gaps
we can use the gap property to adjust the space between flex items.
gap can take two values: the first value for gaps between the rows and the second value for gaps between the
columns.
If the gap you want between the rows and the columns is the same, you can use a single value. The browser will
apply the same value to both rows and columns.
You can also use the properties row-gap if you need to apply a specific gap value between only the rows. and column-
gap if you need to add gaps between only the columns.
1. max-width
38
→Useful for ensuring that an element does not exceed a certain width, even if its content or container is larger.
Values:
Example:
.container {
max-width: 1200px;
This ensures the .container will not grow wider than 1200px, even if the viewport is larger.
2. min-width
→Ensures that an element does not shrink below a specified width, even if its content or container is smaller.
Values:
Example:
.sidebar {
min-width: 250px;
3. max-height
→Prevents an element from exceeding a specified height, even if its content is taller.
Values:
Example:
.modal {
max-height: 80vh;
This ensures the .modal will not grow taller than 80% of the viewport height.
4. min-height
39
→Ensures that an element does not shrink below a specified height, even if its content is smaller.
Values:
Example:
.header {
min-height: 100px;
5. overflow
Values:
visible (default): Content is not clipped and may overflow outside the element’s box.
scroll: Adds scrollbars to the element, allowing users to scroll to see the overflowed content.
.scrollable {
overflow: auto;
max-height: 200px;
This ensures the .scrollable element will show scrollbars if its content exceeds 200px in height.
• setting an element's display property's value to grid turns the box model into a block-level grid layout
module.
40
• setting an element's display property's value to inline-grid turns the box model into an inline-level grid layout
module.
grid-template-columns
grid-template-rows
justify-content
align-content
grid-template-columns
grid-template-columns specifies the number and widths of columns browsers should display in the selected grid
container.
Note:The auto value in grid-template-columns or grid-template-rows allows the size of a column or row to adjust
based on the size of the content inside it.
Note:Instead of manually defining each column or row, you can use the repeat() function to simplify the definition.
grid-template-rows
grid-template-rows specifies the number and heights of rows browsers should display in the selected grid container.
justify-content
justify-content specifies how browsers should position a grid container's columns along its row axis.
The justify-content property works if the total column widths are less than the grid container's width
start
center
end
stretch
space-between
space-around
space-evenly
align-content
align-content specifies how browsers should align a grid container's rows along the container's column axis.
The align-content property works if the total row heights are less than the grid container's height
start
center
41
end
stretch
space-between
space-around
space-evenly
Gaps in Grid
row-gap:Defines the space between rows.
gap (Shorthand):A shorthand for setting both row and column gaps at once. If only one value is given, it sets both
row and column gaps to the same value.
grid-column-start
grid-column-end
grid-column
grid-row-start
grid-row-end
grid-row
grid-area
grid-template-areas
grid-column-start
grid-column-start specifies where the selected grid item should start (or span) along the grid container's row
axis(inline)(Column lines).
grid-column-end
grid-column-end specifies where the selected grid item should end (or span) along the grid container's row (inline)
axis.
grid-column
grid-column is a shorthand for the grid-column-start and grid-column-end properties.
grid-column:1 / 5;
grid-row-start
grid-row-start specifies where the selected grid item should start (or span) along the grid container's column (block)
axis (Row Lines).
grid-row-end
grid-row-end specifies where the selected grid item should end (or span) along the grid container's column (block)
axis.
42
grid-row
grid-row is a shorthand for the grid-row-start and grid-row-end properties
grid-row: 1 / 5;
grid-area
As a shorthand for the grid-column-start, grid-column-end, grid-row-start, and grid-row-end properties. we can use
grid-area
grid-template-areas
grid-template-areas specifies the area where you want to place named grid items within a grid container.
CSS Pseudo-classes
A pseudo-class is a keyword added to a CSS selector, prefixed by a colon (:), to define a specific state or condition of
an element
selector:pseudo-class {
/* styles */
1. :hover
2. :focus
3. :active
4. :visited
5. :link
1. :first-child
2. :last-child
3. :nth-child(n)
Form Pseudo-Classes
1. :checked
2. :disabled
4. :required
A pseudo-element is a keyword added to a selector that lets you style specific parts of an element
selector::pseudo-element{
property: value
1. ::before
The ::before pseudo-element allows you to insert content before the actual content of an element.
p::before {
color: gold;
2. ::after
Similar to ::before, the ::after pseudo-element inserts content after the element’s content
etc....
text-shadow
box-shadow
x-offset
y-offset
blur-radius (optional)
Amount of blur
color
Shadow color
box-shadow
The box-shadow property in CSS is used to add shadow effects around the edges of an HTML element
x-offset
y-offset
blur-radius (optional)
Amount of blur
spread-radius (optional)
2px, -2px
color
Shadow color
inset (optional)
transform property
The transform property in CSS allows you to manipulate the appearance of an element by applying various transform
functions.
1. translate(x-axis, y-axis)
45
Values:
x-axis: Horizontal movement (positive values move right, negative values move left).
y-axis: Vertical movement (positive values move down, negative values move up).
Example:
.box {
2. translateX()
Values:
Example:
.box {
transform: translateX(30px);
3. translateY()
Values:
Example:
.box {
transform: translateY(-20px);
4. rotate()
Values:
Angle: deg,
Example:
46
.box {
transform: rotate(45deg);
5. skew()
Values:
Example:
.box {
Skews the element 20 degrees along the X-axis and 10 degrees along the Y-axis.
6. scale()
Values:
Example:
.box {
Scales the element to 1.5 times its original width and 0.8 times its original height.
7. matrix()
Values:
matrix(a, b, c, d, e, f):
.box {
47
CSS Transitions
→Allow you to create smooth animations between different states of an element.
→Instead of the change happening instantly, transitions let you control the timing and speed of the change, making
it more visually appealing.
transition-property
.my-element {
transition-property: background-color;
The transition-property accepts one or more CSS property names in a comma-separated list.
transition-duration
The transition-duration property is used to define the length of time that a transition will take to complete.
transition-duration accepts time units, either in seconds (s) or milliseconds (ms) and defaults to 0s.
transition-duration: 0s;
transition-duration: 200ms;
The transition-timing-function
When you define a transition, the transition-timing-function controls how quickly or slowly the transition happens at
different points during the duration.
1. ease (Default)
Starts slow, speeds up in the middle, and slows down at the end.
2. linear
3. ease-in
4. ease-out
5. ease-in-out
Starts slowly, accelerates in the middle, and slows down at the end.
48
transition-delay
Use the transition-delay property to specify the time at which a transition will start. If transition-delay is not
specified, transitions will start instantly because the default value is 0s. This property accepts a time unit, for example
seconds (s) or milliseconds (ms).
shorthand: transition
Like most CSS properties, there is a shorthand version. transition combines transition-property, transition-duration,
transition-timing-function, and transition-delay.
CSS Animations
When you specify CSS styles inside the @keyframes rule, the animation will gradually change from the current style
to the new style at certain times.
@keyframes example {
to {background-color: yellow;}
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
49
The animation-duration property defines how long an animation should take to complete. If the animation-duration
property is not specified, no animation will occur, because the default value is 0s (0 seconds).
In the example above we have specified when the style will change by using the keywords "from" and "to" (which
represents 0% (start) and 100% (complete)).
It is also possible to use percent. By using percent, you can add as many style changes as you like.
@keyframes example {
0% {background-color: red;}
The following example has a 2 seconds delay before starting the animation
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-delay: 2s;
Note:Negative values are also allowed. If using negative values, the animation will start as if it had already been
playing for N seconds
The animation-iteration-count property specifies the number of times an animation should run.
The following example will run the animation 3 times before it stops:
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
50
animation-iteration-count: 3;
The animation-direction property specifies whether an animation should be played forwards, backwards or in
alternate cycles.
ease - Specifies an animation with a slow start, then fast, then end slowly (this is default)
linear - Specifies an animation with the same speed from start to end
The animation-fill-mode property specifies a style for the target element when the animation is not playing (before it
starts, after it ends, or both).
none - Default value. Animation will not apply any styles to the element before or after it is executing
forwards - The element will retain the style values that is set by the last keyframe
backwards - The element will get the style values that is set by the first keyframe , and retain this during the
animation-delay period
both - The animation will follow the rules for both forwards and backwards, extending the animation properties in
both directions
Media queries are a powerful feature in CSS that allow you to apply styles based on specific conditions, such as the
viewport size, device orientation, screen resolution. enabling you to create layouts that adapt to different devices
and screen sizes.
/* CSS rules */
Media Types
Common Conditions
Media queries use conditions to apply styles based on specific criteria. Here are the most commonly used ones:
1. Viewport Width
Example:
2. Viewport Height
Example:
3. Device Orientation
Combining Conditions
Example: